Summary of Mac terminal operation commands

1. Common commands for operating the terminal

  1. Quickly open: command+space, enter ter and press Enter
  2. Multiple windows: command+N (the cursor is in the terminal to perform this operation)
  3. Multiple tabs: command+T (the cursor is in the terminal to perform this operation)

2. Directory and file operations

command name Function description Examples or remarks
cd Enter the specified folder path cd ~/Desktop
pwd Show current directory path /Users/xz/Desktop
ls Display the contents of the current directory
ls - her Display detailed contents in the current directory

ls -a

Display the contents of the current directory .Files starting with dot ( )
mkdir Create a directory mkdir dir_name
touch file.format Create a file in a specified format
is mv Move directory mvdir dir1 dir2
mv Move/Rename---Files/Folders mv dir1 dir2
MAC has no rename command
rm Delete files or  empty directories
rm -rf dir Delete a  non-empty  directory rm -rf dir
is rm Delete  empty  directories Usually used less
cp Copy a file or directory cp file1 file2
file Show file types file file_name
find Find files using a match expression find *.file_format
open Open file using default program open file_name
cat Display or connect file contents cat file
ln Create a join for files ln -s file1 file2
s indicates soft connection
head Display the first few lines of the file head -20 file_name
tail Display the last few lines of the file tail -10 file_name
paste Horizontally splicing file content paste file1 file2
diff Compare and display the content differences of two files diff file1 file2
wc Count the number of characters, words and lines of a file wc file_name
unique Remove duplicate lines from file uniq file_name
grep Search files by simple regular expression

3. Common commands

CTRL+A: Move the cursor to the beginning of the line
CTRL+E: Move the cursor to the end of the line
CTRL+X: Hold down CTRL and double-click X to switch between the current position and the beginning of the line
ESC+B: Move the cursor one word to the left
ESC +F: Move the cursor one word to the right
CTRL+U: Delete all characters before the cursor
CTRL+K: Delete all characters after the cursor
CTRL+W: Delete the word before the cursor (identify word separation based on spaces)
CTRL+Y: Paste before ( CTRL+U/K/W) Deleted content
CTRL+C: Interrupt operation

4. Process operation

  1. ps: Display the current process status
  2. kill: kill the current process

5. Icons correspond to keyboard shortcuts  

⌘——Command ()

⌃ ——Control

⌥——Option (alt)

⇧——Shift

⇪——Caps Lock

fn——The function key is fn

.mh switch ⌘+⌃ +↓or↑

Forward and backward text file ⌘+⌃ +←or→

Close the current text file ⌘+⌃+w

Automatic typesetting code ⌃+i

Left and right indent ⌘+[or]

Comment ⌘+/

To view the name definition, enter the header file ⌘+left mouse button

View name api documentation ⌥ + left mouse button

6. Webshell commonly used log viewing commands

  • [ls] View all folders and files in the current directory
  • [cd file] Enter a file folder
  • 【cat file】Open a file online
  • [trail -f file] Open the file file and view the log content in real time

Guess you like

Origin blog.csdn.net/LoveHaixin/article/details/129813011