Linux

Counting files (list and word count, ls & wc)

How do you count the number of files in a directory? That becomes non-trivial if you have thousands of files in a directory. Your file manager chokes on counting them, especially if they are not local. On the Linux command line, this task is fast and easy:
ls | wc
ls lists your files one per row and wc returns three numbers: lines, words and bytes. In the file counting example, lines and words are the same and equal the number of files in the directory.

Copying with rsync

rsync --progress --recursive source target
To resume a previously interrupted copy:
rsync --progress --recursive --ignore-existing source target

 
Please note that rsync source/ target and rsync source target do produce different results!

The trailing slash at the end of the source directory causes rsync to copy the contents of the source directory into the target directory. Without the trailing slash, the target directory will contain one directory that is identical to the source directory.

Pages