Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I have been wrestling with something I don't understand with what I thought is a simple rsync command line.
rsync -u -v -r -n "~/usb/.notes/_tech" "~/.notes/_tech"
Where the: usb node is a mount point for a (known) usb. The question is that the following two variations give radically different results.
Example 1.
$ rsync -u -v -r -n "~/usb/.notes/_tech" "~/.notes/_tech" | tee | wc -l
:
sent 94,378 bytes received 6,340 bytes 201,436.00 bytes/sec
total size is 13,222,770,177 speedup is 131,285.07 (DRY RUN)
2,024 lines (about ~ 2,020 x files)
Example 2.
$ rsync -u -v -r -n "~/usb/.notes/_tech/" "~/.notes/_tech/" | tee | wc -l
:
sent 88,352 bytes received 334 bytes 177,372.00 bytes/sec
total size is 13,222,770,177 speedup is 149,096.48 (DRY RUN)
23 lines (around 19 x files)
Therefore ... I figure example #1 is giving me All files on that tree. While, example #2 is more-as I expected (doesn't mean it was 'correct' though).
Questions:
Why is there a difference at all?!
Which syntax choice provides this simple, recursive, update of a folder sub-tree?
What is the underlying reason(s) behind such a vast difference?
For example; over the weekend, I figured-out that I need to use ls -lt**c** when considering rsync commands. (Obvious once you realise that).
Also that "size does matter" when talking about rsync.
I can accept a difference in semantics for the "dir/" versus the "dir" (no slash). I can't see how with a recurse switch (-r) there be much / if any difference.
I don't see a structural issue in the example; so I'm seeking wisdom from the stackoverflow?!! Insights?
Wisdom sought.
The answer to all your questions is in the manual page:
A trailing slash on the source changes this behavior to avoid
creating an additional directory level at the destination.
You can think of a trailing / on a source as meaning "copy the
contents of this directory" as opposed to "copy the directory
by name", but in both cases the attributes of the containing
directory are transferred to the containing directory on the
destination.
So rsync -r /foo/ /tmp will put everything in /foo into /tmp whereas rsync -r /foo /tmp will put everything in /foo into /tmp/foo.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
In linux server, is there a way to get the list of files in a directory
without using commands such as ls-la?
Our log directory size is too huge (almost 90GB) that
when we use ls -la command to get the list of files in that directory,
the command prompt does not come back...
echo *
... will show files in the current folder through file globbing on Bourne compatible shells.
This lists all files down one level:
echo /
In Bash, if globstar is set (set with shopt -s globstar, unset with shopt -u globstar), this will list all files recursively:
echo **
For More info, you may visit This Link
and your following problem why not you use a limit to list file?
this command may help you
ls -U | head -4
Don't know if there are other commands, but you could combine ls with other command like:
ls -la | less
which still lists your files but you can move up and down (and search) easily. less does not load all the content (your 90GB) at once but it loads lines when you move around.
Or you can save output of ls to a file to open it later
ls -la > my_files.txt
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
As far as you know, - has different usages for in combination with different commands in Linux. For example in combination with cd command, it means "Change directory to the previous location" and in combination mv or cat command it means stdin or stdout.
Unfortunately I wrongly used this character with mv command. I wanted to move my file to the previous location which I have been before the change directory but I moved it to stdin instead.
Is there any way to recover my file?
I run this command:
# mv myfile -
I moved it to stdin instead.
No, you moved to a file literally named by a dash (you'll use /dev/stdin or /proc/self/fd/0 to refer to the stdin, i.e. the file descriptor 0).
You want to
mv -i ./- myfile
this is usual practice (to prefix by ./ a strange path). The -i interactively asks for confirmation.
Sometimes it is not even easy to type a path for a weird file (e.g. for a file name containing a single newline character). You could use globbing (read about shell expansion), e.g. mv -i ./? file.
See mv(1) and path_resolution(7) and glob(7) and proc(5)
The good habit is to avoid strange characters in file paths.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I'm trying to wrap my head around the 'ls -d' command.
I run the command 'ls -d' in any given directory and all I get is a '.'
I run the command 'ls -d */ and I get only the directories
I run the command -ls -d * and I get all files, including those that aren't directories.
The man page just states this:
list directories themselves, not their contents
Can someone please help explain how this switch is supposed to work?
The things to understand are:
ls lists the current directory, otherwise known as ., by default.
ls -d makes ls show the directory it's listing, not that contents of that directory.
The behaviors you describe all follow from that:
ls -d showing . is showing the directory you're in -- the default target of ls with no arguments given.
ls -d */ tells your shell to run ls with each directory under the current one passed as an argument; ls -d then shows the entries for each of its arguments, behaving as you report.
ls -d * tells your shell to run ls with each entry in the current directory passed as an argument. ls then lists one entry for each such argument, not showing the contents of each argument which is a directory name as it otherwise would.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I'm trying to convert a bunch of CBR 320 Kbps Mp3 to VBR 0 (max quality), using lame command in bash. However, it seems like lame can't overwrite existing files. It would be much faster that way, as I could use wildcards to do it on an unique, short terminal command, plus I wouldn't have to delete the old files and rename the new.
What I'm trying is:
lame -h -V 0 *.mp3
But I get the following error message:
lame: excess arg %filename%.mp3
Also, if I try on a single file
lame -h -V 0 %filename%.mp3 %filename%.mp3
I get:
Input file and Output file are the same. Abort.
In the command help there's no option mentioned for forced, overwrite or whatever. I searched in the internet and on Stack Overflow and found nothing too. Can anybody help me?
lame just doesn't support this. Few commands do.
Instead, the Unix philosophy is to not require every program to support every possible mode of invocation, and instead lets the user combine commands to do what they want:
for f in *.mp3; do lame -h -V 0 "$f" tmp && mv tmp "$f"; done
If this is something you do often (though I hope not, since transcoding is bad for quality), you can create your own shortcut for it in .bashrc:
superlame() { for f; do lame -h -V 0 "$f" tmp && mv tmp "$f"; done; }
From then on, you can simply superlame *.mp3
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
What is the command to do a incremental backup? Any source or any links would be much appreciated.
rsync is what you are looking for. Here is a nice tutorial.
Depending on what you need from your backups, rdiff-backup may be what you want. It's based on the same idea as rsync, but also keeps historical backups (in a space-efficient manner, by storing the differences).
Dirvish makes incremental snapshots (that look as full directories trees, thanks to the magic of hardlinks), using rysnc under the hood. It works well for me.
Here's the command I use for incremental backups of my virtual machine using rsync.
rsync -avh --delete --progress --link-dest="/Volumes/canteloup/vm_backups/`ls -1tr /Volumes/canteloup/vm_backups/ | tail -1`" "/Users/julian/Documents/Parallels" "/Volumes/canteloup/vm_backups/`date +%Y-%m-%d-%H-%M-%S`"
-avh means make an archive, with verbose output in a human readable form.
--delete will make sure each incremental backup does not contain files that have been deleted since the last backup. It means the backup taken on a particular date will be a snapshot of the directory as it was on that date.
--progress will display in the terminal the amount transferred, the percentage, and the time remaining for each file. Handy for virtual machine backups with 40Gb+ file sizes.
--link-dest specifies the directory to use for making links for the files that haven't changed. It uses ls -rt | tail -1 to get the last file. Seems to be fine if the file doesn't exist, as in the first time it is run.
The next arg is the directory to backup.
The last arg is the target directory. The name is a timestamp.
Try the following bash script. Please replace src and dest with the source and destination you want to use. If you are not backing up in a local storage then remove --inplace (This option is useful for transfer of large files with block-based changes or appended data, and also on systems that are disk bound, not network bound. you should also not use this option to update files that are being accessed by others).
#!/bin/bash
rsync -ab --dry-run --stats --human-readable --inplace --debug=NONE --log-file=rsync.log --backup-dir=rsync_bak.$(date +"%d-%m-%y_%I-%M-%S%P") --log-file-format='%t %f %o %M' --delete-after src dest | sed -e '1d;5,12d;14,17d'
echo -e "\nDo you want to continue?"
while true; do
case $yn in
[Yy]* ) rsync -ab --human-readable --inplace --info=PROGRESS2,BACKUP,DEL --debug=NONE --log-file=rsync.log --backup-dir=rsync_bak.$(date +"%d-%m-%y_%I-%M-%S%P") --log-file-format='%t %f %o %M' --delete-after src dest; break;;
[Nn]* ) exit;;
* ) read -p "Please answer yes or no: " yn;;
esac
done