Various miscellany that doesn't fit anywhere else
Handy for getting the date, but you can also format it and include it the output when renaming things.
DATE=$(date +%Y%m%d)
You can compare two directories using…
diff --brief -r dir1/ dir2/
Diffing on two different systems
I'm forever forgetting how to use find
so have written down examples I found from here.
# 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
Will rename files using an sed like syntax. For example to lowercase all file names
rename 'y/A-Z/a-z/' *
Generate the md5 (or otherwise) checksum for all files under a given directory
# md5 sum for all files in the current directory, following symbolic links (-L) find -L . -type f -exec md5sum '{}' \; > ~/checksum_of_files.md5
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
.
rsync -av -e 'ssh -p 2222' * target:~/tmp/.
Put a list of the files you want to copy in a file and use --from-file=FILE
rsync -av --from-file=some_files_to_copy.txt ~/ remote:~/tmp/.
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.
You can look at the contents of a tar ball without extracting them using…
tar -ztf some.tar.gz
Counts characters, words and lines, very handy.
# Count number of files in a directory ls -l | grep -v '^total' | wc -l
Useful for downloading web-pages and files.
# -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
This happens on occasions and there are some ways around it as explained here.