livereference.org

Linux One Liners

Find top 10 largest files

du -sh /var/log/* | sort -r -n | head -10

Recursively delete (e.g. backup) files

find ./ -name '*~' | xargs rm

Process all files, one by one (e.g. xml files), in the directory

ls dir_path/*.xml | xargs -n 1 ProgramThatProcessFile

Find and count repeated word in a file

grep -w 'searchword' filename.txt | tr ' ' '\n' | wc -l

Script finds its own directory location

mydir=`dirname $(readlink -f $0)`