Various miscellany that doesn't fit anywhere else # date Handy for getting the date, but you can also format it and include it the output when renaming things. ```bash DATE=$(date +%Y%m%d) ``` # diff You can compare two directories using... ```bash diff --brief -r dir1/ dir2/ ``` Diffing on two different systems # find I'm forever forgetting how to use `find` so have written down examples I found from [here](https://www.tecmint.com/35-practical-examples-of-linux-find-command/). ```bash # Find files of name blah in / (ignores case) find / -iname blah # Find files of name blah in / (case sensitive) find / -name blah # Find directories of name blah in /home find /home -type d -name blah # Find files using glob find /home -type f -name "*.txt" # Permissions 777 find / -type f -perm 0777 -print # Without Permissions 777 find / -type f ! -perm 0777 -print # File based on user find /home -user blah # File based on group find /home -group blah # Modified in the last 50 days find / -mtime 50 # Accessed in the last 50 days find / -atime 50 # Modified last 50-100 days find -mtime +50 -mtime -100 # Modified in last hour find / -mmin -60 # Files based on size find / -szie +50M -size -100M ``` # rename Will rename files using an [[bash:sed|sed]] like syntax. For example to lowercase all file names ```bash rename 'y/A-Z/a-z/' * ``` # md5 checksum Generate the md5 (or otherwise) checksum for all files under a given directory ```bash # md5 sum for all files in the current directory, following symbolic links (-L) find -L . -type f -exec md5sum '{}' \; > ~/checksum_of_files.md5 ``` # rsync ## Specifying port If you don't have you `~/.ssh/config` set up to define the port for the target then you sometimes have to specify this on the command line call to `rsync`. ```bash rsync -av -e 'ssh -p 2222' * target:~/tmp/. ``` ## Specific files Put a list of the files you want to copy in a file and [use](https://stackoverflow.com/questions/16647476/how-to-rsync-only-a-specific-list-of-files) `--from-file=FILE` ```bash rsync -av --from-file=some_files_to_copy.txt ~/ remote:~/tmp/. ``` # sort `sort` is a very useful utility, not only does it do what it says on the tin but it can also reduce a list of rows to unique observations with the `-u` flag. # tar You can look at the contents of a tar ball without extracting them using... ```bash tar -ztf some.tar.gz ``` # wc Counts characters, words and lines, very handy. ```bash # Count number of files in a directory ls -l | grep -v '^total' | wc -l ``` # wget Useful for downloading web-pages and files. ```bash # -nd prevents creation of directory hierarchy # -r recursive download # -A only get items with specified extension wget -nd -r -A jpg,jpeg,png,mp3 http://djriko.com/mixmases.htm ``` # Argument list too long This happens on occasions and there are some ways around it as explained [[https://www.linuxjournal.com/article/6060|here]].