Common linux commands are useful.

Source: Internet
Author: User
Tags clear screen tar extract

Common linux commands are useful.

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: Get the 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. Add exportPS1 = "[

\ 033 [1; 32 m \ U \ 033 [1; 33 m @ \ 033 [1; 31 m \ H \ 033 [1; 35 m \ W \ 033 [0 m ] \ $"

 

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 compares two files

37. vimdiff file1 file2

38. du file-k shows the 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

(Uuencode file1 file1 & cat file2) | mail-s "title" bin.liuyb@alibaba-inc.com sends file1 with attachments to the mailbox, while sending 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 + (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

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.