UNIX tips: Learn 10 good UNIX usage habits
1.Make directory trees in a single swipe
Listing 1 illustrates one of the most common bad UNIX habits around: defining directory trees one at a time.
Listing 1. Example of bad habit #1: Defining directory trees individually
|
It is so much quicker to use the -p
option to mkdir
and make all parent directories along with theirchildren in a single command. But even administrators who know about this option are still caught stepping through the subdirectories as they make them on thecommand line. It is worth your time to conscientiously pick up the good habit:
Listing 2. Example of good habit #1: Defining directory trees with one command
|
You can use this option to make entire complex directory trees, which are great to use inside scripts; not just simple hierarchies. For example:
Listing 3. Another example of good habit #1: Defining complex directory trees with one command
|
In the past, the only excuse to define directories individually was that your mkdir
implementation did not support this option, but this is no longer true on most systems. IBM AIX® mkdir
, GNU mkdir
, and others that conform to the Single UNIX Specification now have this option.
For the few systems that still lack the capability, use the mkdirhier
script (see Resources), which is a wrapper for mkdir
that does the same function:
~ $ mkdirhier project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a} |
2.Change the path; do not move the archive
3.Combine your commands with control operators
4.Quote variables with caution
5.Use escape sequences to manage long input
6.Group your commands together in a list
8.Know when grep should do the counting -- and when it should step aside
9.Match certain fields in output, not just lines
more specifically information please link there: http://www.ibm.com/developerworks/aix/library/au-badunixhabits.html#six
Conclusion: Embrace good habits
It is good to examine your command-line habits for any bad usage patterns. Bad habits slow you down and often lead to unexpected errors. This article presents 10 new habits that can help you break away from many of the most common usage errors. Picking up these good habits is a positive step toward sharpening your UNIX command-line skills.