pwd

Print working directory: View the current directory

pwd
Copy the code

cd

Change directory: Switch a directory

#Switch directory
cd home

#Switch to the previous directory
cd ..

#Switch to the root directory
cd /

#Switch to the current user directory
cd
#Or (~ represents the home directory of the current user)
cd ~
Copy the code

ls

List: Displays the list of files in the current directory

#View folders and files in the current directory
ls

#View folders and files in a directory, such as TMP
ls tmp
Copy the code

mkdir

Make directory: creates a directory or file

#Creating a single directory
mkdir dir0

#View folders and files in a directory, such as TMP
ls tmp

#Created in a directory
mkdir /tmp/tutorial

#Create multiple directories
mkdir dir1 dir2 dir3

#Create a layer by layer directory
mkdir -p dir4/dir5/dir6
Copy the code

echo

Echo: print

#Print to console
echo "This is test"

#Print to a file
echo "test1" > test_1.txt
Copy the code

cat

Concatenate: a link; Check the file

#Viewing a single file
cat test_1.txt

#View multiple filescat test_1.txt test_2.txt test_3.txt cat test_? .txt cat test_*
#Multiple file contents are consolidated into one file
cat t* > combined.txt
cat combined.txt
Copy the code

Note: Repeated execution of the command overwrites an existing file. If you need to append content rather than replace it, use multiple “>>” :

#Append the whole thing
cat t* >> combined.txt

#Let's add one more line
echo "Add a line" >> combined.txt

cat combined.txt
Copy the code

less

Less: The file is viewed in paging mode when the file content is too much

#Viewing a single file
less combined.txt
Copy the code

q

Quit: Exits the less view mode

q
Copy the code

mv

Move: Moves a file or directory. Change the file name or directory name

#Move files to a directory
mv combined.txt dir1

#. Indicates the current directory
mv dir1/combined.txt .

#Move multiple files to a directory, the last one is the target directory, for example, move the following files and folder dir3 to dir2
mv combined.txt test_* dir3 dir2

#Modify the file name and directory name
mv test_1.txt test1.txt
mv "folder 1" folder_1
Copy the code

cp

Copy: copies files or directories

#Copy the file
cp combined.txt combined_backup.txt

#Copy files to another directory
cp combined.txt dir1
Copy the code

rm

Remove: Removes a file or directory

#Deleting a single file
rm combined_backup.txt

#Delete files in a directory
rm dir4/dir5/dir6/combined.txt

#Deleting multiple files
rm combined_backup.txt dir4/dir5/dir6/combined.txt
rm test_*.txt

#Forcibly delete a directory and all files in the directory
rm -r dir4

#Delete with prompt (Y or N)
rm -i combined.txt
Copy the code

rmdir

Remove directory: Deletes a directory

#Delete directories (note that only empty directories are deleted)
rmdir folder_1
rmdir dir*
Copy the code

|

Pipe pipe, which passes one command to another

wc

Count: indicates the statistics quantity

  • -l: line Indicates the number of lines or files
#View the number of file lines
wc -l combined.txt

#Check the number of files in the home directory
ls ~ | wc -l

#Open the etc directory in paging mode
ls /etc | less
Copy the code

other

  • man: manual View the operation manual
  • uniq: unique Prints unique lines in a file
  • sort: sorting
  • reset: Clears the current window
  • whoami: Displays the current user name
  • sudo: Run with supermanaged identity