I have accumulated some experience and skills in Linux over the past five years. 1. the code for copying $-related parameters in bash is as follows: $0-indicates the current file name $ *-separates all parameters with spaces to form a string $ @-separates all parameters with spaces to form
1. $ Related parameters in bash
The code is as follows:
$0-indicates the current file name
$ *-Separate all parameters with spaces to form a string
$ @-Separate all parameters with spaces to form a string combination. Different from $ *, when being referenced by "", "$ *" is a string, while "$ @" contains multiple strings.
$ #-Number of parameters passed to the process
$? -The execution result of the previous command. The value is 0 if no error occurs.
$-PID of this command
2. bash technique, which combines the content of a variable into the name of another variable
EXAMPLE:
The code is as follows:
A_ B _C_D = "something"
T1 = "B"
T2 = "_ D"
Eval echo \ $ A _ $ {t1} _ C ${t2 };
3. in Ubuntu (12.04, 12.10), set the sensitivity and speed of the ThinkPad X220.
The code is as follows:
Echo-n 225>/sys/devices/platform/i8042/serio1/serio2/sensiti.pdf
Echo-n 115>/sys/devices/platform/i8042/serio1/serio2/speed
4. back up the main boot sector (bootsector)
If the startup file is corrupted, you can restore the primary boot sector to repair the view:
Backup
The code is as follows:
Dd if =/dev/hda of = bootsector. img bs = 512 count = 1
Restore
The code is as follows:
Dd if = bootsector. img of =/dev/hda
The above two steps only restored the primary boot sector. it is likely that all the content in/boot must be restored before it can be started properly. Therefore, you can also back up the files under/boot.
5. bash command line input tips:
Use Ctrl + R to search for commands previously used
Use Ctrl + W to delete the current time
Use Ctrl + U to delete the current row
6. xargs is very powerful. you can use-l {} to specify the parameter location:
EXAMPLE
The code is as follows:
Cat hosts | xargs-I {} ssh root @ {} hostname
7. write a safe bash script:
Set-e. When an error occurs, the script exits.
Set-u. exit when bash finds there are no initialized variables
For more information, see: writing robust Bash scripts.
8. tar package the files listed in the specified list:
The code is as follows:
Cat yourlist. lst
/Etc/fstab
/Home/admin/bin/somefile. sh
/Home/mysql/somefile
...
Tar cvzf xxx.tar.gz-T yourlist. lst
9. specify a DNS server to query domain name records
The code is as follows:
Dig @ 8.8.8.8 www.google.com
10. the most important parameters of the sort command are-k and-s:
The code is as follows:
-S, -- stable
Stabilize sort by disabling last-resort comparison
Stable indicates that the final order depends on the original order.
EXAMPLE
The code is as follows:
$ Cat a.txt
A
A
B
$ Sort-f a.txt
A
A
B
$ Sort-f-s a.txt
A
A
B
In this example,-f indicates case-insensitive, and-s indicates that the order of the original files depends on the order of the original files.
The code is as follows:
-K, -- key = POS1 [, POS2]
Start a key at POS1 (origin 1), end it at POS2 (default end of line ).
Therefore, the data is sorted by the second column and should be written as follows:
The code is as follows:
Sort-k1, 1
Http://www.bkjia.com/PHPjc/327730.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327730.htmlTechArticle1. the $-related parameter code in bash is as follows: $0-indicates the current file name $ *-separates all parameters with spaces to form a string $ @-separates all parameters with spaces to form...