Set operations on lines of a file

# Union of unsorted files, items in either file1 or file2
sort file1 file2 | uniq
# Intersection of unsorted files, items in both file1 and file2
sort file1 file2 | uniq -d
# Difference of unsorted files, items in file2 not in file1
sort file1 file1 file2 | uniq -u
# Symmetric Difference of unsorted files, items in file1 or file2 but not both
sort file1 file2 | uniq -u

Backup

# CAVEAT: apparently does not backup setuid bits?
tar cvpf backup.tar \
--exclude=/proc \
--exclude=/lost+found \
--exclude=/backup.tar \
--exclude=/mnt \
--exclude=/sys \
--exclude=/dev/pts \
/

Unit conversion

units -t '100m/9.58s' 'miles/hour'
units -t '500GB' 'GiB'
units -t '1 googol'

Dates

What time is it elsewhere?

TZ='America/Los_Angeles' date
TZ='America/Denver' date
TZ='America/New_York' date
TZ='UTC' date

Check /usr/share/zoneinfo/ to find values for $TZ.

Convert UNIX epoch seconds to date

date --date='@2147483647'

Exit a script unless it's the last day of the month

[ $(date -d "tomorrow" +%d) = "01" ] || exit

Calendar for particular month and year

cal 9 1752


CategoryCheatSheet

SamatsWiki: CheatSheet/GNUCoreUtils (last edited 2015-01-15 21:58:34 by SamatJain)