Common operations on the command line (add, Delete, change, query)

1. Search: View files or directories

View the absolute path of the current directory

 pwd
Copy the code

View the current directory

ls
Copy the code

View the contents of a specified directory

Ls pathCopy the code

Viewing file Contents

  • Cat Path: View all contents of the fileCopy the code
  • Head path: view the first 10 lines of the file content by default.Copy the code
    • Head path -n xx: xx Indicates the first xx line of a fileCopy the code
  • Tail path: view the last 10 lines of the file content by default.Copy the code
    • Tail Path -n xx: xx indicates a number. You can view the content in line (XX) after the fileCopy the code
  • Less path: View file contents in pagesCopy the code

2. Add: Create a file

Creating an empty file

Touch the file nameCopy the code

Create a file and type in: > will overwrite content, >> will append content

echo111 > File nameecho -e "11/n22"> File name (with carriage return)Copy the code

Create a directory (folder) a/

mkdir a
Copy the code

Create directories A /b/c/d/e

mkdir - p  a/b/c/d/e
Copy the code

Copy the 1.txt file to 2.txt

cp 1.txt 2.txt
Copy the code

Copy directory A to directory B

cp -r a b
Copy the code

3. Delete: Deletes files or directories

Delete the file

rm 1.txt
Copy the code

Delete directories (folders)

Rm -r a // -r recursive, deleting files layer by layer rm -rf a // f force forcibly deleting files is not recommendedCopy the code

4. Modify a file or directory

Modifying file Contents

echo// add 111 to 1.txt, >> Append code file or directory // use VScode to open start file or directory // Use default to open (window) open file or directory // Use default to open (Apple)Copy the code

Move a file or directory (rename a file or directory)

TXT Specifies the name of the file // Can be moved or renamedCopy the code

Change the last update time of a file

Touch file // (if there is no file, it will be created, if there is a file, 'touch it, it will make it up to date')Copy the code