Tips on Linux Command Line

Source: Internet
Author: User
Tags ibm developerworks

Use a command to create a directory tree
~ $ Mkdir-P tmp/A/B/C

 

Use a command to define a complex directory tree
~ $ Mkdir-P project/{lib/EXT, bin, SRC, DOC/{HTML, info, PDF}, demo/STAT/}

 

Use Option-C to decompress the. tar archive file to the specified directory.
~ $ Tar xvf-C tmp/A/B/C newarc.tar.gz

 

Execute multiple commands in sequence
~ $ CD/; LS-l

 

Condition | control the execution of multiple commands
(If the tmp/A/B/C directory does not exist, the CD command returns a non-0 value and continues executing the mkdir command)
~ $ CD tmp/A/B/C | mkdir-P tmp/A/B/C

 

Condition & control execution of multiple commands
(When the tmp/A/B/C directory exists, the CD command returns 0 and continues to execute the tar command)
~ $ CD tmp/A/B/C & tar xvf ~ /Archive.tar

 

Use subshell to run the command list
(Use parentheses to include the command list in a single group. This will run the command in a new subshell and allow you to redirect or collect the output of the entire group of commands)
~ $ (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"

 

Execute commands using xargs Batch Processing
(The list of log files output by the previous command LS is run one by one as the input parameters of the next command file)
~ $ Ls/var/logs/*. log | xargs File

/Var/log/Anaconda. Log: UTF-8 Unicode English text
/Var/log/boot. Log: empty
/Var/log/prelink. Log: ASCII English text
/Var/log/scrollkeeper. Log: UTF-8 Unicode text
/Var/log/xorg.0.log: ASCII English text
/Var/log/yum. Log: empty

 

Use awk to separate text files
(The separator is used here)
~ $ Echo 2009/09/09> test.txt
~ $ Awk-F/'{print $1, $2, $3}' test.txt
2009 09

 

(Refer to some articles on IBM developerworks)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.