almost all of the operations under Linux can be implemented by the command line, familiar with the command line operation can not only bring convenience to our work, but also have a significant effect on the improvement of our working efficiency. To summarize, a few common commands and how to use Linux.
User Management
New user Add useradd UserName After creating a new user, a folder named UserName is created under the/home directory, which is automatically located to the folder each time the user logs on. Add a password (password) passwd UserName Delete User (user delete) Userdel UserName Use the –p option to delete files in the user directory and other files associated with the user. New group Add groupadd groupname delete Group Delete groupdel groupname user identity WhoAmI View login user who [option] -A display all information for all users- H display column header user Switching (substitute user) su UserName such as: su or su root switch to root user root user as the highest user, default The root user does not have a password set, and sudo only temporarily gets the highest root privilege. We can passwd root to the root user to set the password before the SU root user can successfully
Directory Management
Create directory (make directory) mkdir direcname Delete directory (remove directory) rmdir direcname (empty directory) <span style= "COLOR: #FF0000; " > rm-rf forcibly delete a non-empty directory and all of its files </span> display working directory (print working directory) pwd display directory contents (list) ls [options] option:- A displays all files in the current directory, including files that begin with. - L Displays a list of files in the form of a long list, such as: -rw-r--r--1 Haison haison 2 10:10 haison.c- R reverse, from post-forward enumeration directory contents- r Recursively enumerate the contents of all directories- s Sort by file size change the current directory (changes directory) CD or CD ~ Enter the home directory at login CD/go to the root directory CD. Go to the top level directory Cd/home Enter the system's home directory CD home to enter the home directory under the current directory ./indicates the current directory directory rename (move) MV Sourcedirecname Targetdirec Name directory copy (copy) CP Sourcedirec targetdirec-r files, subdirectories, and subdirectories under the copy directory
File Management
A file is described by 1 types and 9 permission bits, and 9 permission bits are divided into 3 groups, each set of 3 permission bits, as shown below:
When the ls-l command displays all files in the directory on time
Drwxr-xr-x codebat codebat 4096 August 12:29 apue.2e/-rw------- 1 codebat codebat 3335 August 28 12:58 .bash_history</span>
File type
--representing ordinary documents; D represents the directory; b represents a block device file; c denotes a character device file; l means link file; P indicates the pipeline file; s indicates socket interface local socket
File permissions
Once a file is created, there are 3 permissions: r-- reads, read permissions, octal notation as 2^2=4w--write, write permissions, octal representation as 2^1=2x--excute, execute permissions, octal representation for 2^0=19 permissions divided into 3 groups, respectively, u-- User, the owner of the file G--group, the file owner's group O--other, the other users rights management and A--all, which means that all users
File operations
New file >filename or touch FileName or VI FileName or cat >filename Delete file (remove files) RM [options] FileName option:-I system prompt Do you really want to delete the file-F delete file without prompting for any confirmation message-r recursively delete content file copy of all subdirectories under directory (copy) CP sourcefile targetfile file link ln– S sourcefile targetfile Create a file link, ls–l view, you will see Targetfile->sourcefile </u> Show file contents more filename One screen display file content, space or carriage return to display the next screen Less FileName Displays the contents of the file one screen at a time, a space or carriage return displays the contents of the next screen cat filename all the files at once cat File1 File2>file3 will file1, File2 's content is written to File3, covering file3 original content &NBSP;&NBSP;&NBSP;&NBsp; Cat File1>>file2 appends file1 content to file2,file2 original content head FileName shows only the first 10 lines of the file head–n FileName Displays the first n rows of the file tail filename Show only the following 10 lines of files tail–n FileName Displays the last n rows of the file nl filename The contents of the file all at once in numbered form, ignoring spaces </u> file Move/rename (move) MV SourceFile targetfile move one or more files to another Record, or rename a file to another file. File Find Find [path] [option] such as: Find/-name "Linux"-print file content lookup (grep) such as: grep "main" haison.c file type command ls–l displays the type of file in a long list, such as:- rw-r--r--changing File/directory permissions (change mode) chmod [u/g/o/a] [+/-/=] [permissions] filename/direcname where: +: Increase the specified permissions -: Remove the specified permission = : Clears the selected permissions and sets them to the established permissions chmod allows you to change permissions using the octal notation as a pattern. Change the owner of the file/directory chown owner Filename/direcname Change the genus Group of files/directories CHGRP Group Filename/direcname change file/directory for the owner and the genus Chown owner:group filename/direcname
backup and compression of files
bzip2 command bzip2 filename, file is saved filename.bz2 bzip2 savename.bz2 filename1 /directory/catalog. Will filename2, Filename2 and directories are compressed and stored in the savename.bz2 folder bunzip filename.bz2 unzip the files gzip filename gunzip filename.gz gzip-r savename.gz file1 file2/directory/Directory Tar command (this is just a packaged command) create a tar file tar -cvf Filename.tar Directory/file (represents the file or directory to be packaged) tar -tvf filename.tar lists the contents of the tar file tar - XVF Filename.tar contacts the archived content into the current working directory and does not delete the tar file to create a file that is compressed using tar and bZIP archive tar -cjvf Filename.tbz de-Archive tar bzip file tar -xjvf filename.tbz Create a file compressed with tar and gzip archive tar -czvf filename.tgz file , this command creates an archive file File.tar and then compresses it into file.tgz files
System Administration Commands
Shutdown -k warning message -R reboot, restart-t time after shutdown, Power off PS command------see which programs are running and their usage PS- l Lists the user's situation and usage time by using the long format------ list Memory Usage top command-----View the current program's execution scenarios and memory use, press CTRL + C Leave this program KILL command----Terminate a running process kill PID
Linux Common commands