Linux Shell Script Raiders notes chapter II: Common Commands

Source: Internet
Author: User

Linux Shell Script Raiders notes Chapter II: Common Commands1. Cat cat-s//Multiple blank lines compressed into one cat *.txt | Tr-s ' \ n '//Remove blank line Cat-n//Gach No. 2, find goes down the file hierarchy, matches the qualifying file, and performs the appropriate action. Eg:find./! -name "*.txt"-print[[email protected] program_test]# find./-type f-name "*.SWP"-delete

3. Xargs converts standard input data into command line parameters. [email protected] program_test]# Cat OUT.txt | Xargs//Convert a single line to multiple lines
[email protected] program_test]# Cat OUT.txt | Xargs-n 3//Convert a single line to multiple lines, with a number of 3 per row.
Count the number of lines of code for. C and. cpp files. Xargs-0 the delimiter. [[email protected] program_test]# find. -type f-name "*.c*"-print0 | xargs-0 wc-l
119 Total
The command (abbreviated by translate) can replace, delete, and compress characters from standard input. That is, change a set of characters to another set of characters. 1) Replace echo "HELLO" | tr [A-z] [a-z]2] delete [[email protected] program_test]# echo "Hello 123 World 456" | tr-d ' 0-9 ' Hello World 3) compressed characters [[email protected] program_test]# echo "GNU is not UNIX" | Tr-s "
GNU is not unix//comprehensive example [[email protected] program_test]# cat Sum.txt
[email protected] program_test]# Cat Sum.txt | Echo $[$ (tr ' \ n ' + ') 0]
5. MD5 Check[Email protected] program_test]# md5sumOUT.txt > Out.txt.md5
[email protected] program_test]# cat OUT.TXT.MD5
Fd46d559bf0c90170fef3da3c3de4c67 OUT.txt

Eg:[[email protected] program_test]# find./-type f-name "*.txt"-print0 | xargs-0 md5sum >> curr_dir.md546e17910faf509df48dbfba9729ef018./banana.txt
[Email protected] program_test]# md5sum-c CURR_DIR.MD5
6. Sort sort//sort by 2nd column [[email protected] program_test]# sort-k 2 sort.txt
4 Bad 5000
3 Linux 50
1 Mac 2000
2 WinXP 100//sort Reverse order
[Email protected] program_test]# sort-r sort.txt
4 Bad 5000
3 Linux 50
2 WinXP 100
1 Mac 2000
General Example: Count the number of occurrences of each character in a string [email protected] program_test]#./
[email protected] program_test]# cat
input= "AHEBHAAA"
output=$ (echo $INPUT | sed ' s/[^. /&\n/g ' | Sed '/^$/d ' | Sort | uniq-c | Tr-d ' \ n ')
Echo $output

[Interpretation]: sed ' s/[^. /&\n/g '//any one character is followed by \ n Split as follows: [[email protected] program_test]# input= "AHEBHAAA"
[Email protected] program_test]# echo $input | Sed ' s/[^. /&\n/g '

Sed '/^$/d '//delete blank line uniq-c//Count the number of occurrences of each line of text. tr-d ' \ n '//Remove line breaks and space characters
7. Temporary file name [[email protected] program_test]# temp_file= "/tmp/var.$$"
[Email protected] program_test]# echo $temp _file
/tmp/ var.16565

Ming Yi World

Reprint please indicate source, original address:

If you feel this article is helpful, please click on the ' top ' support, your support is I insist on writing the most power, thank you!

Linux Shell Script Raiders notes chapter II: Common Commands

Related Article

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: 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.