1. $ related parameters in bash
Copy codeThe 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:
Copy codeThe 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.
Copy codeThe 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
Copy codeThe Code is as follows:
Dd if =/dev/hda of = bootsector. img bs = 512 count = 1
Restore
Copy codeThe 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
Copy codeThe 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:
Copy codeThe 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
Copy codeThe 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:
Copy codeThe 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
Copy codeThe 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.
Copy codeThe 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:
Copy codeThe Code is as follows:
Sort-k1, 1