1. Basic commands

1.1 Shutdown and Restart

  • Shut down immediately:poweroff
  • Restart immediately:reboot

1.2 Remote Login

  • Using SSH to log in (to another system) :SSH [email protected]
  • Log out of the current login:exit

1.3 Help Commands

  • Use the help command:--help

2. File operation commands

2.1 Viewing Files and Directory Information in a Directory:lsandll

  • lsLists the contents of the current directory
  • ls /rootSpecify a directory to view
  • ls -aView all files and directories, including hidden files and directories
  • ls -lList view to display more information. With ll command

2.2 Directory Switchover Command:cd

  • cd appSwitch to the App directory
  • cd..Switch to the upper directory
  • cd /Switch to the system root directory
  • cdSwitch to the user home directory
  • cd -Switch to the previous directory

2.3 Creating and Deleting a Directory:mkdirandrmdir

  • mkdir  appCreate the app directory in the current directory
  • mkdir -p app2/testCascade the app2 and test directories
  • rmdir appDelete app directory

2.4 Browse files:cat,moreandless

  • cat: Used to display the contents of a file: Format:Cat [parameter]< file name >
  • more: Usually used when the content to be displayed exceeds one screen length. Press space to display the next screen and press Enter to display the next line. Q exit
  • less: is similar to more. It is controlled by the pgUp and pgDn keys

2.5 Display the following lines of the file:tail

  • tail -n 100 test.logLook at the last 100 lines
  • tail  -f  test.logDynamically Viewing Logs
  • ctrl + c: End View

2.6 Deleting Commands:rm

  • rm a.txtThe a. TB file is deleted. The deletion requires user confirmation
  • rm -f a.txtDelete without asking
  • rm -r aRecursive delete

2.7 Copy and Move commands:mv,cp

  • cp a.txt b.txtCopy A.tb to B.TB
  • cp a.txt .. /Copy a.tb to the directory at the previous level
  • mv a.txt .. /Move a.tb to a directory on the previous level
  • mv a.txt b.txtRename a.tb to B.TB

2.8 Compression Commands:tar

  • Tar -cvf xxx.tar./* Package command
  • Tar -czvf xxx.tar.gz./* Package and compress
  • Tar /xxx.tar.gz Command to decompress the package

2.9 Querying a Matching Character string:grep

  • grep lang xxx.logLook for lang in the file
  • grep lang xxx.log -colorHighlight, such as grep root warnquot. conf — color-a5-b5

2.10 Other Common Commands

  • pwdDisplays the current directory
  • touch a.txtCreate an empty file
  • ll -hFriendly display file size
  • wgetDownload resources
  • chomd 777 fileChange the permission on file to read, write, and execute

3. Combine commands

3.1 Output redirection:>>>

  • cat /etc/password > a.txtDirect the output to a.txt
  • cat /etc/password >> a.txtOutput and append

3.2 Pipes (taking the output of one command as input to another) :

  • ls  --help | morePaging query help information
  • ps -ef | grep javaQuery a process whose name contains Java

3.3 Command Execution Control:&&

4. Network communication commands

4.1 Displaying or Setting network Devices:ifconfig

  • ifconfigDisplay network equipment
  • ifconfig eth0 upEnabling eth0
  • ifconfig eth0 downDisabling eth0

4.2 Detecting whether the network is normal:ping

  • ping [www.baidu.com](http://www.baidu.com)

4.3 Viewing network Ports:netstat

  • netstat -an | grep 3306None Example Query the usage of port 3306

5. System management commands

5.1 System Management Command 1

  • dateDisplays the current system time
  • date -s "2018-01-01 10:10:10"Setting the System Time
  • df -hFriendly display disk information
  • free -mDisplays the memory status in MB
  • topDisplay and manage applications in execution

5.2 System Management Commands 2

  • clearClear the screen
  • ps -efViewing all processes
  • ps -ef | greep sshFind a process
  • kill 2868Kill process 2868
  • kill -9 2868Force kill process

5.3 System Management command 3

  • du -hDisplays the current directory size
  • whoThe current user information is displayed
  • hostnameView the current host name
  • uname -aDisplays local details

Vi. Vim Common commands

6.1 vim model

  • Edit mode (Command mode)
  • The input mode
  • At the end of the line mode

6.2 Mode Conversion

  • Edit –> Enter:
    • i: Convert to input mode before the character where the cursor is located;
    • a: After the character where the cursor is located, the input mode is changed;
    • o: Create a new line below the current line where the cursor is located and change it to the input mode.
    • I: Switches to the input mode at the beginning of the line where the cursor is located
    • A: Switches to the input mode at the end of the line where the cursor is located
    • O: Create a new line above the current line of the cursor and change it to the input mode.
  • Enter –> Edit:
    • ESC
  • Edit –> Last line:
    • :
  • At the end –> Edit:
    • ESC, ESC

6.3 Opening a File

Vim file: Open the file and start editing

6.4 Closing files

  • The last line mode closes the file
    • : q exit
    • :wq Save the configuration and exit
    • :q! Do not save and exit
    • Save: w
    • :w! To save
  • Exit in edit mode
    • ZZ: Save and exit

6.5 Moving the Cursor

  • 0: Absolute first line
  • $: Absolute end of line
  • ggThe first line:
  • G: Last line
  • #G: Jump to line #

6.6 double screen

  • Ctrl+f: Scroll down
  • Ctrl+b: Scroll up
  • Ctrl+d: Scroll down half the screen
  • Ctrl+u: Turn up half the screen

6.7 other

  • Dd: deletes the line where the current cursor resides

The user related

  • Adduser: adduser Chen

  • Set the password to password 123456

File permissions

  • Modify file permissions:chmod 755 a.txt
  • Cascading modify folder permissions:chmod -R 755 dir
  • Modify the owning user and user group of a file:chown jay:fefjay a.txt# Modify user jay and user group fefjay
  • Cascading the owning users and user groups of the modified folder:chown -R jay:fefjay my# Modify user jay and user group fefjay

Configure global environment variables

Modify/etc/profile file, add the following two lines of code at the end of the file export PATH = $PATH: / usr/local/MATLAB/R2013a/bin

Effective immediately: source /etc/profile

Replication from local to remote

scp local_file remote_username@remote_ip:remote_folder 
Copy the code

ITerm2 sets automatic login

Automatic Login Script

#! /usr/bin/expect set timeout -1 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] expect { "(yes/no)?" {send "yes\n"; Exp_continue} "password:" {send "[lindex $argv 3]\n"}} interact #Copy the code

Save the file as login.exp.

Setting File Permissions

chmod 777 login.exp
Copy the code

The profiles of iTerm2 are configured

/ Users/chentianming/Desktop/studying/login. Exp port IP user name passwordCopy the code

Background startup service

nohup command &