This link has been bookmarked by 284 people . It was first bookmarked on 29 Dec 2007, by TooManySecrets.
-
31 Dec 17
-
29 Mar 15
-
18 Nov 14
-
15 Nov 14
-
08 Nov 14
-
21 Sep 14
-
24 Dec 13
Juan Antonio Garcia10 good UNIX usage habits http://t.co/jtqDh2ZdYO definitely guilty of a few bad habits.
-
26 Oct 13
-
11 Oct 13
-
04 Oct 13
Robert Sutor"When you use a system often, you tend to fall into set usage patterns. Sometimes, you do not start the habit of doing things in the best possible way. Sometimes, you even pick up bad practices that lead to clutter and clumsiness. One of the best ways to correct such inadequacies is to conscientiously pick up good habits that counteract them. This article suggests 10 UNIX command-line habits worth picking up -- good habits that help you break many common usage foibles and make you more productive at the command line in the process. Each habit is described in more detail following the list of good habits."
-
26 Jun 13
-
10 Dec 12
-
12 Oct 12
-
02 Oct 12
Chris De Rouck"Adopt 10 good habits
Ten good habits to adopt are:
Make directory trees in a single swipe.
Change the path; do not move the archive.
Combine your commands with control operators.
Quote variables with caution.
Use escape sequences to manage long input.
Group your commands together in a list.
Use xargs outside of find .
Know when grep should do the counting -- and when it should step aside.
Match certain fields in output, not just lines.
Stop piping cats.
" -
11 Jun 12
-
15 Jul 11
-
06 Apr 11
-
07 Feb 11
-
25 Jan 11
-
17 Jan 11
-
18 Dec 10
-
16 Dec 10
-
15 Dec 10
-
11 Dec 10
-
06 Dec 10
-
12 Nov 10
-
11 Nov 10
-
23 Oct 10
-
10 Oct 10
-
30 Aug 10
Eric Miller10 good habits for using the unix command line, such as how to shorten redundant commands.
-
25 Aug 10
-
27 Jun 10
-
10 Jun 10
-
25 May 10
-
23 Mar 10
-
04 Mar 10
-
17 Feb 10
-
18 Nov 09
-
06 Oct 09
-
27 Aug 09
-
31 Jul 09
-
30 Jul 09
-
07 Jul 09
-
01 Jul 09
-
21 Jun 09
-
18 Jun 09
-
10 Jun 09
-
02 Apr 09
-
21 Mar 09
-
16 Mar 09
-
13 Jan 09
-
02 Jan 09
-
27 Dec 08
-
01 Dec 08
-
24 Nov 08
-
14 Oct 08
-
06 Oct 08
-
11 Sep 08
-
10 Sep 08
-
09 Sep 08
-
08 Sep 08
-
04 Sep 08
-
02 Sep 08
-
01 Sep 08
-
30 Aug 08
-
29 Aug 08
-
28 Aug 08
-
27 Aug 08
-
backslash (\)
-
long input
-
do not want those definitions to apply to your current shell.
-
the final command in your list ends with a semicolon,
-
any time you need to filter text into a single line
-
he
-eflag -
the number of lines
-
number of instances
-
26 Aug 08
-
25 Aug 08
-
Listing 2. Example of good habit #1: Defining directory trees with one command
~ $ mkdir -p tmp/a/b/c -
Listing 3. Another example of good habit #1: Defining complex directory trees with one command
~ $ mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a} -
~ $ tar xvf -C tmp/a/b/c newarc.tar.gz
-
Listing 5. Example of good habit #3: Combining commands with control operators
~ $ cd tmp/a/b/c && tar xvf ~/archive.tar
In this example, the contents of the archive are extracted into the ~/tmp/a/b/c directory unless that directory does not exist. If the directory does not exist, the
tarcommand does not run, so nothing is extracte -
You have probably seen code examples in which a backslash (\) continues a long line over to the next line, and you know that most shells treat what you type over successive lines joined by a backslash as one long line. However, you might not take advantage of this function on the command line as often as you can. The backslash is especially handy if your terminal does not handle multi-line wrapping properly or when your command line is smaller than usual (such as when you have a long path on the prompt). The backslash is also useful for making sense of long input lines as you type them, as in the following example
-
Run a list of commands in a subshell
Use parentheses to enclose a list of commands in a single group. Doing so runs the commands in a new subshell and allows you to redirect or otherwise collect the output of the whole, as in the following example:
Listing 11. Example of good habit #6: Running a list of commands in a subshell~ $ ( cd tmp/a/b/c/ || mkdir -p tmp/a/b/c && \ > VAR=$PWD; cd ~; tar xvf -C $VAR archive.tar ) \ > | mailx admin -S "Archive contents"
In this example, the content of the archive is extracted in the tmp/a/b/c/ directory while the output of the grouped commands, including a list of extracted files, is mailed to the
adminaddress. -
Use the
xargstool as a filter for making good use of output culled from thefindcommand. The general precept is that afindrun provides a list of files that match some criteria. This list is passed on toxargs, which then runs some other useful command with that list of files as arguments, as in the following example:
Listing 13. Example of the classic use of thexargstool~ $ find some-file-criteria some-file-path | \ > xargs some-great-command-that-needs-filename-arguments
-
Listing 15. Example of using of the
xargstool~/tmp $ ls -1 | xargs December_Report.pdf README a archive.tar mkdirhier.sh ~/tmp $ ls -1 | xargs file December_Report.pdf: PDF document, version 1.3 README: ASCII text a: directory archive.tar: POSIX tar archive mkdirhier.sh: Bourne shell script text executable ~/tmp $
-
~ $ time grep and tmp/a/longfile.txt | wc -l 2811 real 0m0.097s user 0m0.006s sys 0m0.032s ~ $ time grep -c and tmp/a/longfile.txt 2811 real 0m0.013s user 0m0.006s sys 0m0.005s ~ $
-
-
12 Aug 08
-
05 Aug 08
-
04 Aug 08
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.