Easily remember linux commands
I use an absolute ton of awesome tools my various linux distros. The problem is I tend to forget a lot of the time how to use the tools, so I got a list of frequently used command with and a few examples of how to use them from here. So here’s the file I use. — Create a new tar archive $ tar cvf archive_name.tar dirname/ — Extract from an existing tar archive. $ tar xvf archive_name.tar — Grep for a given string in a file (case in-sensitive search). $ grep -i “the” demo_file — Print the grep line, along with the 3 lines after it. $ grep -A 3 -i “example” demo_text — Grep for a given string in all files recursively $ grep -r “ramesh” * — Grep for a string that starts with $ char and contains what’s in $1 grep — color=auto -B 1 -E ‘^$.b’$1’b’ cmd_examples.txt — Find files using file-name ( case in-sensitve find) $ find -iname “MyCProgram.c” — Execute commands on files found by the find command $ find -iname “MyCProgram.c” -exec md5sum {} ; — Find all empty files in home directory $ find ~ -empty — Converts the DOS file format to Unix file format using sed command. $ sed ’s/.$//’ filename — Print file content in reverse order $ sed -n ‘1!G;h;$p’ thegeekstuff.txt — Add line number for all non-empty-lines in a file $ sed ‘/./=’ thegeekstuff.txt | sed ‘N; s/n/ /’ — Remove duplicate lines using awk $ awk ‘!($0 in array) { array[$0]; print }’ temp — Print all lines from /etc/passwd that has the same uid and gid $ awk -F ‘:’ ‘$3==$4’ passwd.txt — Print only specific field from a file. $ awk ‘{print $2,$5;}’ employee.txt — Diff ignore white space while comparing. $ diff -w name_list.txt name_list_new.txt — Sort a file in ascending order $ sort names.txt — Sort a file in descending order $ sort -r names.txt — Sort passwd file by 3rd field. — Xarg:Copy all images to external hard-drive $ ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory — Xarg:Search all jpg images in the system and archive it. $ find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz — XargLDownload all the URLs mentioned in the url-list.txt file $ cat url-list.txt | xargs wget –c — LS:Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr $ ls -ltr — LS:Visual Classification of Files With Special Characters Using ls -F $ ls -F — Gzip:Display compression ratio of the compressed file using gzip -l $ gzip -l *.gz $ bzip2 test.txt $ bzip2 -d test.txt.bz2 — UNZip:View the contents of *.zip file (Without unzipping it): $ unzip -l jasper.zip — Shutdown the system after 10 minutes. $ shutdown -h +10 — Force the filesystem check during reboot. ...