Shell Common commands

Source: Internet
Author: User
Tags clear screen tar extract

1. CTRL + A returns the character at the front of the edge.

2. When Ctrl + R is used to query history, the command used is prompted.

3. In VI, move to the row header, press the number 0, and move to the end of the row and press $!

4. You can download wget httpd: // afdasfd.com or SVN Co httpd. // name.com or SVN export URL.

5. VI & Vim

Copy: 1, 6y à enter (Copy 1-6 rows) y = Yank

Delete: 1: 6d à enter (delete rows 1-6)

Paste: copy and paste it by P.

Number of lines displayed: Set nu

/Keyword for search. N is next.

6. Read the command more:

More + 20 file: display file content starting from line 1

More-20 file: Display 20 rows at a time

7. CP file1 file2 copy the file

CP-r file file2 copy directory

SCP file1 se1.asc.cnz.alimama.com :~ /Bok/copy to another machine

Rsync-r file se1.asc.cnz.alimama.com :~ /Bok/copy to another machine

RM file delete file

Rm-RF directory Delete directory

Rm-RF {a, B, c} Delete multiple directories

8. Less reading command

9. Cat reading command

Cat File

Cat file1 file2> file merged content

10.> clear File Content

11. Modify the file name in MV file file2

12. Modify the file path in MV file ../File

13. Find./-INAME 'file'
Find the path with the file name, case-insensitive

14. Find./-name 'file' find the file name path, case sensitive

15. Head-20 take the first 30 rows of file and browse

16. Tail-30 File
Last 30 rows

17. History commands

18. Modify the time when the file has been created touch-c-t 0906270730 File

19. Create a new file using mkdir File

20. WC-l file statistics on the number of rows

21. troubleshooting of Chinese garbled characters:

Exportlc_all = zh_cn.gbk

Exportlc_lang = zh_cn.gbk

22. crontab-l view the crontab command line

Crontab-e edit crontab command line

10 6 ***/home/a. Sh run a. Sh at 06:10 every day.

*/2 * A. Sh is executed every 2 minutes.

 

23. Redirection

Or | tee

Eg: CAT File> file2 or cat file | tee file2

 

24. PS-EAF | grep httpd search for HTTPd process

25. Kill-9 the PID forces the process to stop

26. rpm-ivh a. RPM installation RPM package

Rpm-q a. rpm check whether a. rpm is installed

Rpm-e a. RPM uninstall A. rpm

27. chmod 111 (executable)/222 (readable)/444 (writable) File Permission

28. modify the Linux color in vim. add exportps1 = "[\ [\ 033 [1; 32m \] \ U \ [\ 033 [1; 33m \] @ \ [\ 033 [1; 31m \] \ H \ [\ 033 [1; 35m \] \ W \ [\ 033 [0m \] \ $"

29. Syntax off can cancel the highlighted syntax Under VI. Syntax on can be displayed

30. Change Su-username to user account

31. Top displays the complete process path and name.

32. The hostname displays the current host name and domain name of the system.

33. Date system time

34. Cal calendar

35. pwd absolute path

36. Diff file1 file2
Compare two files

37. vimdiff file1 file2

38. Du file-K
Show File Size

39. Tail-F file dynamic viewing of File Content

40. grep 'title' file: Search the line with the title in the file.

41. grep 'title' file-10 search the row with the title in the file and print the content of the top 10 lines.

42. Sed-E's/a/B/G' File> file2 modify a in file to B and import

43. ls [A-Z] *. conf lists all files starting with A to Z and ending with Conf.

44. Yum search packagename search package

Yum install packagename install package

45. Tar-zxvf file.tar Extract

Tar-CVF file.tar file Packaging

46. PS-x Processes

PS aux owner Process

47. grep 'test' file | head-5

48. grep 'test' file-n shows the matched row number.

49. Du-H-max-depth =/home/liuyongb view space size

50. ln-S ~ /File ~ /Bin/file soft connection

51. Find./-name 'test' | Delete xargs Rm-RF after local search

52. df-Hl view the remaining space

53. Du-SH file: view the total directory size

54. ls | sort-N sort by number

55. ifconfig displays the machine IP Address

56. Change the file user group and use chown. For example, if the group and user of the file are admin users and you want to change it to Yahoo users, use sudo chown Yahoo: users file.

57. Find./| xargs grep 'eragon' find a file containing a word in the current directory and subdirectory?

The following is a machine connection method:

If two machines are connected. Step 1: Run CD on the machine 1. /ssh, then ssh-keygen-t rsa, press enter, and press enter to generate id_rsa.pub. Step 2: MV id_rsa.pub 1.pub; Part 3: CAT 1.pub>> authorized_keys.

Then go to machine 2 for the operation. In the same way, generate the pub file named 2.pubon Machine 2 and copy it to machine 1. ssh, and then Cat 2.pub》 authorized. keys ., finally, copy authorized. keys. to Machine 2. Now we can get through

If not, 1. chmod 644 authorized_keys

2. Add the IP address of the machine to be connected under/etc/hosts

50 RZ can directly upload things from a Windows machine

51 SZ file can copy Linux Files to Windows.

52. Rename the command: alias FID = 'Find./-name Test'

 

52. Mail-s "title" bin.liuyb@hotmail.com <file sends file content to the mailbox

(Uuencode file1 file1 & CAT file2) | mail-s "title"
The bin.liuyb@alibaba-inc.com sends file1 with attachments to the mailbox and file2 content to the mailbox.

52. CT Installation 

1. First, prepare the required two installation packages.

 

Tcl8.4.13-src.tar.gz

Expect-5.43.0.tar.gz

 

2. Install tcl8.4.13

 

The configure script of TCL has a syntax error. The following command can correct it:

Sed-I "s/relid '/relid/" Configure (8.4.13 no longer has this error)

Compile TCL

CD Unix

./Configure -- prefix =/verify CT

Make

Make install

Mkdir-P/tools/lib

Copy all required content to the/tools/lib directory.

CP tclconfig. sh/tools/lib/

 

Do not delete the source code after installation, so that you will need to use the unzip CT installation.

 

Export the/tools/bin directory to the environment variable, Vim. bashrc, and then enter export Path = "$ path:/opt/au1200_rm/build_tools/bin"

 

3. Install keep CT

 

./Configure -- prefix =/tools -- With-tcl =/tools/lib -- With-x = No

 

If

Checking for tclprivate headers... checking for tclint. H... no

Configure: Error: Can't Find TCL private Headers

 

Add another header file DIRECTORY parameter.

-- With-tclinclude = ../tcl8.4.13/generic, that is:

./Configure -- prefix =/tools -- With-tcl =/tools/lib -- With-x = No -- With-tclinclude = ../tcl8.4.13/generic

 

 

The script runs normally and runs make for compilation.

Make

If no error occurs during compilation, run the following command:

Make install

 

Sudo CP/tool/bin/ct/usr/bin/

53. Replace the number 0-9 in the file with a-J.

# Cat file | tr [0-9] [A-J]

54. Delete the "Snail Il" character in the file.

# Cat file | tr-d "Snail Il"> new_file

Note: All the 's', 'n', 'A', 'I', and 'l' characters in the file are deleted! Instead of deleting the "Snail Il" string.

55. Delete the newline '\ n' and tabulation' \ t' characters in the file.

# Cat file | tr-d "\ n \ t"> new_file

Invisible characters must be expressed by escape characters, which are unified.

56. Delete consecutive letters and retain only the first one

# Cat file | tr-s [A-Za-Z]> new_file

57. The NL file is the same as the cat file, but the row number is added.

58. Change the color of ECHO output in Shell

Format: Echo "\ 033 [background color; font color M string \ 033 [0 m"

For example:
Echo-en "\ 033 [41; 36 msomething here \ 033 [0 m"

The position 41 represents the background color, and the position 36 represents the color of the word.

Color Range: 40----49
40: Black
41: dark red
42: Green
43: Yellow
44: Blue
45: Purple
46: dark green
47: white

Color: 30-----------39
30: Black
31: red
32: Green
33: Yellow
34: Blue
35: Purple
36: dark green
37: white

========================================================== ======= ANSI Control Code Description
\ 33 [0 m close all properties
\ 33 [1 m set high brightness
\ 33 [4 m underline
\ 33 [5 m flashing
\ 33 [7 m reverse display
\ 33 [8 m blanking
\ 33 [30 m -- \ 33 [37 m sets the foreground color
\ 33 [40 m -- \ 33 [47 m set the background color
\ 33 [move the NA cursor up n rows
\ 33 [move the Nb cursor down n rows
\ 33 [move the NC cursor right n rows
\ 33 [Nd cursor shifts n rows left
\ 33 [Y; XH: Set the cursor position
\ 33 [2j clear screen
\ 33 [k clear content from cursor to end of line
\ 33 [s Save the cursor position
\ 33 [U restore cursor position
\ 33 [? 25l hide the cursor
\ 33 [? 25 h show cursor

 

 

 

60. If an error Bash:./1.sh: Bad Interpreter: nosuch file or directory is reported during script execution

 

Error analysis:

Because the operating system is windows and the script is edited in windows, invisible characters may exist.

From the perspective of your script and reported errors, it is likely that your script file is in DOS format, that is, the end of each line is identified by \ r \ n, the ASCII codes are 0x0d and 0x0a.
There are many ways to check whether the file is in DOS or Unix or Mac format.

(1). VI filename
Run the following command:
: Set ff?
You can see the DoS or Unix words. if it is in DOS format, you can use set FF = UNIX to force it to Unix format, and then save the disk and exit. run it again.

 

 

The V screen command can switch the screen to log on to a common server (this machine is recommended to be open all the year round and rarely restart) and run the screen command

V next demonstration of Screen

§ Ctrl + a c create a new window

§ Ctrl + A two windows switch back and forth

§ Ctrl + a n next window

§ Ctrl + a p previous window

§ Ctrl + A <num> (Num is 1, 2,...) to a window

§ Ctrl + a' input window ID

§ Ctrl + A "up/down key selection window

§ Ctrl + A Shift + A change the window name

§ Ctrl + a w show all windows

V is going home from work in the evening and the work is not finished yet. What should I do?

Enter Ctrl + a d to suspend Screen

§ Working the next day, run the screen-rd recovery window to continue working

§ After the screen is suspended, all the commands running in the screen will continue to be executed. Therefore, it is best to put some long-running tasks in the screen without using nohup.

 

VI editing

After entering the editing interface, run the VSP command to display the following on the split screen: VSP ~ /File to open file on another screen.

Grep-r 'admin' * recursively searches for matching items in the folder.

Grep-V 'admin' file matches the rows in the file that are not Admin

View the file encoding format in VI

: Set Encoding

Modify the encoding format under VI

: Set encoding = UTF-8

View Group

Create a user group groupadd Test

Modify the user group groupmod Test2 test to change test to tese1.

Create user useradd Test

Change passwd Password

CTRL + Z can terminate the text being edited, but it is not saved. FG recoverable

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