taken from
IBM Linux help site1. mkdir -p option allows multiple directory in different depth to be created all at once
e.g. mkdir -p good/{fun,happy/photos}
will create a directory good, which contains 2 directories fun and happy, and in happy a new directory photos
2. tar xvf -C unarchive without having to move the tar to the destination directory, giving the user an option to specify where the directory the tar will be unarchived
e.g. tar xvf /temp/a newarc.tar.gz
3. the && and || operator in command line are more advaned replacements for ;, which is the command separator in console. && checks if previous command have executed and returned 0, and only if it returned 0 the second command runs. || checks if the previous command returned non-zero, and only execute second command if non-zero return exit has been returned
e.g. cd /temp/a && mkdir b
e.g. cd /temp/a || mkdir -p /temp/a
4. It is generally a good idea to enclose variable calls in double quotation marks, unless you have a good reason not to. Similarly, if you are directly following a variable name with alphanumeric text, be sure also to enclose the variable name in curly braces ({}) to distinguish it from the surrounding text.
5. the escape sequence \ makes commands more clear
6. it's good habit to group commands using () in subshell or {} in current shell. this way all commands inside () or {} have their outputs grouped together for further use. make sure that there is a space between commands and {}
7. xargs is a powerful output format tool that can do many types of filtering
e.g. ls -l | xargs
combines all listed files into one line
e.g. ls | xargs file
lists all files and its file type
a caution that xargs can cause error when reading '_', which if placed in a single line cause xargs to ignore anything afterwards, xargs -e turns off the end of file string feature
8. grep -c does the same thing as grep | wc -l and is faster. but grep -c only count lines containing matching patterns. to count all matching patterns,even if a line contain more than 1, use grep -o | wc -l
grep -o cannot be used with -c at the same time
9. use awk instead of grep when possible. awk captures the line if word matches the key at the right index
e.g. ls -l | awk '$6 = "Dec"'
captures all lines with 6th word = Dec
10. grep doesn't have to work with cat because grep can take file names as arguments
e.g. time grep and tmp/a/longfile.txt
does the same as time cat tmp/a/longfile.txt | grep and