The article directories
- 1. Files and directories
-
- 1. The PWD command
- 2. The ls command
- 3. The CD command
- 4. The mkdir command
- 5. The rmdir command deletes an empty directory
- 6. Touch commands
- 7. The cp command
- 8. The rm command
- 9. The mv command
- 10. The cat command
- 11. More instructions
- 12. Less orders
- 13. The echo command
- 14. The head instructions
- 15. The tail command
- 16. > instructions and >> instructions
- 17. Ln the instructions
- 18. The history instruction
1. Files and directories
1. The PWD command
- Basic syntax:
pwd
(Function description: Display the absolute path of the current working directory) - Example: Display the absolute path of the current working directory
2. The ls command
- Basic syntax:
Ls [option] [directory or file]
- Commonly used options
-a
: Displays all files and directories in the current directory, including hidden ones.
-l
: Displays information in a list - Examples of application
Example: View all information about the current directory
3. The CD command
- Basic syntax:
CD [parameter]
(Function description: Switch to the specified directory) - Understanding: Absolute path and relative path
CD -
orcd
: Switch to your home directory, for example if you are root,CD -
to/root
cd ..
Go back to the directory one level above the current directory- Examples of application
Case 1: Switch to root using absolute path,cd /root
Case 2: Use a relative path to the /root directory, such as in/home/xdr
,cd .. /.. /root
Case 3: go to the directory one level above the current directory,cd ..
Case 4: Back home Catalog,cd ~
4. The mkdir command
- The mkdir command is used to create a directory
- Basic syntax:
Mkdir [option] Directory to create
- Commonly used options
-p
: Creates a multi-level directory application instance - Examples of application
Example 1: Create a directory /home/xdr630
mkdir /home/xdr630
Copy the code
Example 2: Create a multilevel directory /home/animal/tiger
mkdir -p /home/animal/tiger
Copy the code
5. The rmdir command deletes an empty directory
- The basic grammar
Rmdir [option] Empty directory to delete
- Examples of application
Example: Delete a directory/home/xdr630
- Using the details
rmdir
Delete the empty directory,Cannot be deleted if there is content in the directory. - Tip: Delete if neededDirectory is not empty, need to use
Rm -rf Indicates the directory to be deleted
- Such as:
rm -rf /home/animal
6. Touch commands
- The touch command creates an empty file
- Basic syntax:
Touch file name
- Examples of application
Case:/home
Directory, create an empty filehello.txt
touch hell0.txt
Copy the code
7. The cp command
- The cp command copies the file to the specified directory
- Basic syntax:
Cp [option] source dest
- Commonly used options
-r
: Recursively copies the entire folder - Examples of application
- Case 1: will
/home/hello.txt
Copy to/home/aaa
directory
cp hello.txt /home/aaa
Copy the code
- Case 2: Recursively copy an entire folder, for example, to
/home/bbb
The entire directory, copy to/opt
下
cp -r /home/bbb /opt
Copy the code
- Using the details
Methods to force overwriting without prompting:\cp
\cp -r /home/bbb/opt
Copy the code
8. The rm command
- Description:
The rm command removes a file or directory
- Basic syntax:
Rm [option] File or directory to be deleted
- Common options:
-r
: Deletes the entire folder recursively
-f
: Forcible deletion is not prompted - Examples of application
- Case 1: will
/home/hello.txt
delete
rm /home/hello.txt
Copy the code
- Case 2: Delete the entire folder recursively
/home/bbb
rm -rf/home/ BBB [delete entire folder without prompting]Copy the code
- Using the details
Forcible deletion method without prompting: Bring-f
Parameters can be
9. The mv command
- Mv Moves files and directories or renames them
- The basic grammar
mvOldNameFile newNameFileCopy the code
mv/temp/ moveFile /targetFolderCopy the code
- Examples of application
- Case 1: will
/home/cat.txt
Rename the file topig.txt
mv /home/cat.txt pig.txt
Copy the code
- Case 2: will
/home/pig.txt
File move to/root
directory
mv /home/pig.txt /root
Copy the code
- Case 3: Move the entire directory, for example
/opt/bbb
Move to the/home
下
mv /opt/bbb /home
Copy the code
10. The cat command
- Cat View file contents
- Basic syntax:
Cat [option] The file to view
- Commonly used options
-n
: Displays the line number - Examples of application
Case 1: View/etc/profile
File contents and display line numbers
cat -n /etc/profile
Copy the code
- Using the details
Cat can only browse files, but not modify them. For easy browsing, it usually carries pipe commands| more
cat -nThe/etc/profile | more interact []Copy the code
- The pipe command is used to give more the result obtained previously, as in:
cat -n /etc/profile | more
Copy the code
- Enter the enter key to change to the next line, enter space to turn the page
11. More instructions
- The MORE directive is a text filter based on the VI editor that displays the contents of a text file page by page in a full-screen manner. The more command has several built-in shortcut keys (interactive commands). For details, see operation instructions
- Basic syntax:
More Indicates the file to view
- Operation instructions:
- Example Use more to view files
more /etc/profile
Copy the code
12. Less orders
- The less command is used to view file contents in split screen. Similar to the MORE command, but more powerful than the MORE command, the less command supports various display terminals. The less command does not load the entire file at one time, but loads the content according to the display requirements, which is efficient for displaying large files.
- Basic syntax:
Less Indicates the file to view
- Operation instructions:
- Examples of application
Case: Adoptionless
View a large file file/ opt/essays. TXT
Less /opt/ articles.txtCopy the code
13. The echo command
- Echo outputs content to the console
- Basic syntax:
Echo [options] [output content]
- Examples of application
- Case: Use
echo
Instruction output environment variables, such as output$PATH or $HOSTNAME
Environment variable names are generally capitalized
echo $PATH
Copy the code
echo $HOSTNAME
Copy the code
2. Case: Useecho
Command outputHelloWorld
14. The head instructions
- Head is used to display the beginning of a file. By default, the head command displays the first 10 lines of a file
- The basic grammar
Head file (Function description: View file headers10Line)Copy the code
head -n 5File (Function description: View the file header5Line,5Can be any number of rows)Copy the code
- Examples of application
Case: View/etc/profile
The first five lines of code
head -n 5 /etc/profile
Copy the code
15. The tail command
tail
Used to print the contents of the tail of a file. By default, the tail directive displays the first part of the file10Line.- The basic grammar
Tail file
(Function description: View the last 10 lines of the file)Tail -n 5 File
(Function description: View 5 lines at the end of the file. 5 can be any number of lines.)Tail -f file
Function Description: Track all updates to this document in real time.
- Examples of application
- Case 1: View
/etc/profile
The last five lines of code
tail -n 5 /etc/profile
Copy the code
- Case 2: Real-time monitoring
mydate.txt
(Create a new empty file), see if you see the file changes, real-time append
hello,world
.
tail -f /home/mydate.txt
Copy the code
- Open another terminal, append
echo "helloworld"
, you can see the real-time change of the terminal above
16. > instructions and >> instructions
> Output redirection and >> append
- The basic grammar
Ls-1 > file
Function description: Write the contents of the list to a filea.txt
Middle (overwrite)Ls -al >> file
Function description: Appends the contents of the list to the fileaa.txt
At the end of the)Cat file 1 > file 2
Function Description: WillFile 1
Content covered toFile 2
)Echo "Content" >> File
(additional)
- Examples of application
- Case 1: will
/home
In the directoryFile listWritten to the/home/info.txt
, overwrite write
ls -l/home > /home/info.txt [ifinfo.txtIf no, it will be created.Copy the code
- View the directory to write to:
- Open the
info.txt
To view
- Case 2: Append the current calendar information to
/home/mycal
The instructions in the file (which will be created automatically without mycal) are:
cal
Command: View the current date
cal >> /home/mycal
Copy the code
17. Ln the instructions
- Soft links, also known as symbolic links, are similar to shortcuts in Windows, where links to other files are stored
- The basic grammar
Ln -s [original file or directory] [soft link name]
(Function description: to create a soft link to the original file) - Examples of application
- Case 1: in
/home
Directory to create a soft connectionmyroot
And connected to the/root
directory
ln -s /root /home/myroot
Copy the code
- At this point, switch to
myroot
Directory, is access toroot
The directory
- Case 2: Delete the soft connection
myroot
.Pay attention to: Don’t take itmyroot
At the back of the”/
“
rm -f /home/myroot
Copy the code
- Detail description
When we usepwd
Command to view the directory, still see the soft link directory.
18. The history instruction
- You can view history commands that have been executed or run history commands
- The basic grammar
history
(Function description: View historical commands that have been executed.) - Examples of application
- Example 1: Display all the history command history
- Case 2: Show the 10 most recently used commands.
history 10
Copy the code
3. Case 3: Execute the history number as1005
Command, use firsthistory
Command to view the number, at this time1005
The instruction corresponding to the number isll
!1005
Copy the code