linux operation instructions

1. View as action directory location
> pwd

2. View the file content in the (current) directory
> ls //list
> ls -l or ll //Show detailed information of the file
> ls -al //all show detailed information of the file (including hidden files)
> ls -a //Display all file names in the directory (including hidden files)
> ls [-al] directory //View the file information of the specified directory

3. Directory switching
> cd directory name
> cd .. or cd ../ //Switch to the upper directory
> cd . or cd ./ //Switch to the current directory
> cd ~ or cd //Directly switch to the user's home directory

4. User switch
> su - or su - root //Switch to root super administrator
> su ordinary user name //Switch to ordinary user
> exit //Return to the original user and

user switching will cause a superposition effect, so do not repeat su Action (use su and exit in pairs)
jinnan--->root--->jinnan--->root--->jinnan

5. Check who the current user is
> whoami //Display the user currently running the operating system
> who am i //Display the user information logging in to the system (it has nothing to do with su)

6. Switch between graphical interface and command interface
># init 3 //Switch to command interface
># init 5 //Switch to graphical interface

7. View the executable file location corresponding to the
instruction > which instruction

8. Directly output the contents of the file to the terminal
> cat file

9. Clear the screen
> clear

10. Directory operations
① Create a directory make directory
> mkdir directory name //Create a single directory
> mkdir -p newdir1/newdir2/newdir3 //Create a multi-level directory recursively
> mkdir dir1/dir2/newdir
> mkdir -p dir1/newdir2/newdir3 If
the level of the new directory is greater than or equal to 2, you need the -p parameter, if it
is equal to 1, you do not need
> mkdir /home/jinnan/shandong //The "absolute path method" relative to the root directory creates the shandong directory

② Move the directory move
> mv dir1 dir2 //dir1 moves to the directory of dir2
> mv dir1/dir2 dir3 //dir2 moves to the directory of dir3
> mv dir1/dir2 dir3/dir4 //dir2 moves to the directory of dir4
> mv /home/jinnan/beijing /home/jinnan/shandong //Absolute path method: beijing is moved to the shandong directory
(the target directory moved to is all [existing])


The second parameter of the mv command to change the directory name The new name is the rename operation.
The existing name is the move operation.
mv is the combined instruction of [move and rename]
> mv dir1 newdir //dir1 moves to the current directory and changes its name to newdir
> mv dir1/dir2 dir3 // dir2 is moved to the dir3 directory and renamed to the original name
> mv dir1/dir2 dir3/newdir //dir2 is moved to the dir3 directory and renamed to newdir

④ Copy (and change the name) operation copy
-R recursive recursive
> cp -R dir1 dir2 //dir1 is copied to dir2, and renamed to the original name
> cp -R dir1/dir2 dir3/newdir //dir2 is copied to dir3 , and change the name to newdir
> cp -R dir1/dir2 newdir //dir2 is copied to the current directory and renamed to newdir

> cp dir1/filea dir2 //filea is copied to dir2 and renamed to its original name
> cp dir1/filea dir2/dir3/newfile //filea is copied to dir3 and renamed to newfile

⑤ Delete operation remove
-f force forced
> rm file //delete file file
> rm -r dir //delete directory
> rm -rf filename //recursively force delete file (directory)

> rm -rf // recursively force delete "/slash" root directory

11. Simple file operation
① View file content
> cat filename //Output all the content to the terminal at one time
> more filename //View the file content line by line by hitting Enter
q key to end the view

> less filename //"up, down, left and right" keys to view the contents of each part of the file (support for review)
q key to end viewing
> head -n filename // view the first n lines of the file
> tail -n filename // view the end of the file N lines of content
> wc filename //View the number of lines of file content

② Create a file
> touch filename //Create a filename file in the current directory
> touch dir/filename //Create a filename file in the specified directory
> touch /home/jinnan/dir/newfile //Create a newfile file through an absolute path

③ Append content to the file
> echo content > file //add "content" to the file by overwriting
> echo content >> file //add "content" to the file by "appending"
(using the above two command, the file does not exist will be automatically created)

12. The corresponding configuration file for user operations (create, modify, delete)
: /etc/passwd
① Create useradd
># useradd -g group code -d home directory -u user number username
># useradd username

② Modify usermod
># usermod -g group -d home directory (manually created) -u user number -l newname user name

③ Delete userdel
># userdel -r username//delete user information and also delete "home directory"

13. The corresponding configuration file for group operations (create, modify, delete)
: /etc/group
① Create groupadd
> # groupadd group name
② Modify groupmod
> # groupmod -g own number -n new name group name
③ Delete groupdel (Note: There is user information in the group and it is forbidden to delete)
># groupdel group

14. View the parameters that can be used by the
command > man command

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887309&siteId=291194637