Experience and skills accumulated over the past five years using Linux

Source: Internet
Author: User
This article is a small series of experience and skills accumulated over the past five years using Linux. For more information, see 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

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.