1. Create a hierarchy directory: Use the-P option for mkdir, such as Mkdir-p tmp/a/b/c.
2. Unpack to the specified directory: Use the-c option of tar, such as tar xvf newarc.tar.gz-c tmp/a/b/c.
3. Joint command: Use;, &&, | | such as control operators, such as CD tmp/a/b/c && tar xvf ~/archive.tar.
4. Use the variable carefully: Place the variable in the "", as
~ $ ls tmp/
A b
~ $ var= "tmp/*"
~ $ echo $VAR
tmp/a tmp/b
~ $ echo "$VAR"
tmp/*
~ $ echo $VARa
~ $ echo "$VARa"
~ $ echo "${var}a"
Tmp/*a
~ $ echo ${var}a
tmp/a
~ $
5. Input of long command: use \ Branch break, as
~ $ cd TMP/A/B/C | | \
> mkdir-p tmp/a/b/c && \
> Tar xvf-c tmp/a/b/c ~/archive.tar
6. Group command: Use (), {} to group commands, such as
~ $ (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"
7. Use Xargs: Can filter the output, such as
~/tmp $ ls-l | Xargs
-rw-r--r--7 Joe Joe 12043 Jan 20:36 december_report.pdf-rw-r--r--1 \
Root root 238 Dec 08:19 README Drwxr-xr-x, Joe Joe 354082 Nov 02 \
16:07 a-rw-r--r--3 Joe Joe 5096 Dec 14:26 archive.tar-rwxr-xr-x 1 \
Joe Joe 3239 Sep 12:40 mkdirhier.sh
~/tmp $
8. Use the-c option of grep to calculate the number of rows in the output, which is faster than using the wc-l of the pipe, as
~ $ 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
~ $
9. Match output fields: Using awk, such as
~/tmp $ ls-l | awk ' $6 = = ' Dec '
-rw-r--r--3 Joe Joe 5096 Dec 14:26 Archive.tar
-rw-r--r--1 root root 238 Dec 08:19 README
~/tmp $
10. Disable cat's pipe output: use grep instead, as
~ $ time Cat Tmp/a/longfile.txt | grep and
2811
Real 0m0.015s
User 0m0.003s
SYS 0m0.013s
~ $ time grep and Tmp/a/longfile.txt
2811
Real 0m0.010s
User 0m0.006s
SYS 0m0.004s
~ $