This article will introduce the most basic and most commonly used commands of the linux system, which beginners can refer to;
Operating environment: Remotely connect to Tencent cloud server through termius terminal, remotely operate linux system (ubuntu)
After entering the system interface, we demonstrate common commands one by one.
Table of contents
Command 1: clear, clear the screen
Command 2: pwd, directory location
Command 3: ls, view all files (including folders) in the current directory
Command 4: cd, switch directory
Command five: touch, create a file
Command 6: echo, write content
Command seven: cat, display content
Command eight: mv, rename the file
Command nine: rmv, delete files
Command ten: mkdir, create folder (directory)
Command eleven: rmdir, delete folder (directory)
Command 1: clear, clear the screen
After typing "clear" and hitting the Enter key, the screen will be cleared, as shown in the following figure:
Command 2: pwd, directory location
Enter "pwd" and press Enter, the system will display the current path of the user
Command 3: ls, view all files (including folders) in the current directory
Enter "ls" and press the Enter key to display all files and folders in the current directory. Those with suffixes are files, and those without suffixes are folders. The colors of the two are different.
Common parameters:
- -l: list long data strings, including file attributes and permission data, etc.
- -a: List all files, together with hidden files (files beginning with .) (commonly used)
- -d : list only the directory itself, not the file data of the directory
- -h: list the file capacity in a more readable way (GB, kB, etc.)
- -R : List together with the contents of subdirectories (recursive listing), equal to all files in this directory will be displayed
Command 4: cd, switch directory
Command format:
cd [directory name]
enter the root directory
cd /
Enter the home directory
cd home
On a Linux server, each account corresponds to its own home directory. This home directory is called the home directory. From the above figure, we can see that there is an ubuntu folder in the home directory. We enter the folder through the cd command and display the files it contains.
It can be seen that the ubuntu folder under the home folder is the default folder when we enter the system.
Return to the previous directory
cd ..
Command five: touch, create a file
Command format:
touch file
If
touch
the file does not exist, it will be created automatically. If it existstouch
, no error will be reported.
Add 2.txt file in the test folder
Command 6: echo, write content
Command format:
echo content
This will output the content to the screen
Command format:
echo content > filename
This will output the content to the specified file in an overwritten manner
Command format:
echo content >> filename
This will append the content to the specified file
Command seven: cat, display content
Command format:
cat filename
It can be seen that the content written in the 2.txt file was successfully read to the screen
It can be seen that >> is the appended content, and > is the overwritten content.
cat -b filename
Line numbers will be displayed when displaying content
Command eight: mv, rename the file
Command format:
mv old_file_name new_file_name
Command nine: rm, delete files
Command format:
rm file
Command ten: mkdir, create folder (directory)
Command format:
mkdir dir_name
Command eleven: rmdir, delete folder (directory)
Command format:
rmdir dir_name
This article introduces the eleven most basic commands of the linux system based on actual operations. The content is relatively simple and is mainly for beginners to quickly get started. If you need further study, please refer to the relevant documents.