Linux commands-linux File and permission management commands-linux permission management
1. ubuntu tips:
In ubuntu, you can press ctrl + alt + t to open the terminal, and press ctrl + shift + t to open the second terminal.
Adjust the font in ubuntu terminal
Font increase: ctrl + shift + plus sign
Reduce Font: ctrl + minus sign
After entering the vi/vim Editor, enter: set number in command line mode to display the travel number in text.
: Set nonumber
The colors of files, folders, compressed files, and executable programs in ubuntu are different.
If the file name is long, you can press the table key to automatically complete the file.
Press ctrl z or ctrl c to terminate the program being executed.
There are three network connection methods in ubuntu: NAT bridging is only applicable to hosts.
2. linux File and permission management commands:
Clear: clear screen
View help documentation: 1. -- help such as ls -- help
2. man For example: man ls (abbreviation of manual)
History: View historical history-c deletion history
Switch the supermanager permission: After sudo-s, enter the root user
Execute the file as Administrator: su xxx
Root User Switch back to normal user input exit
Root User Password: sudo passwd root
Ls: displays all files and folders in the current path.
Ls-l lists detailed information, ls-lh shows the file size, and ls-lha shows hidden files.
Wildcard
* All characters in the file name
Ls AB * search for files starting with AB ls x *. c list all files with x Headers
Ls *. html search end with the html file ls *. py ls *. c to list all. py. c files.
? Represents any character in the file
Ls ?. C is used to search for any file with the first character and suffix. c.
Ls .? It can only contain three characters. The first two characters are a, and the last character is any file.
[] Enclose character groups to match any one of the character groups. -Used to indicate the character range
[Abc] matches any one of abc
[A-f] matches any character from the-f range
Ls [a-f] * searches for files starting with any character in the-f range
Ls a-f: searches for a file named a-f. If-is out of square brackets, the wildcard is lost.
Ls \ * a find the file named * a \ is an escape character
Touch creates a file
Touch 1.c touch 1.py
> Output redirection command
Linux can redirect the command execution result to a file, and the content displayed on the terminal should be saved to the specified file.
Ls> test.txt is created if it does not exist. If it exists, it overwrites its content.
More split-screen display
When there is too much information, use the more command to view only one page at a time. The space will display the next page, q will exit, and h will help
| Pipeline: the output of one command can be output by pipeline as another command
| It can be divided into left and right ends, left ends, and right ends.
Ls-alh | more
Cd: Jump command
Cd ~ Switch to the current user's home directory
Cd... switch to the parent directory
Cd-returns the last path
Pwd: view the current path
Mkdir: Creates directories and folders.
Mkdir apple: Create an apple folder
Rmdir: delete a directory
You can use the rmdir command to delete a directory. The directory must be left and the exposed directory must be empty. Otherwise, the deletion fails.
Rm: delete an object
Rm 123.py Delete common files
Rm apple-r Delete recursive folder
Rm apple-f force delete file
Rm apple-I execution in interactive mode
Ln: create a link file
Link: soft connection: no disk occupation. If the source file is deleted, the soft link becomes invalid.
Hard connection: hard links can only link common files, but cannot link directories.
Ln source file
Ln-s source file link file
If the source file in the soft link is deleted, the link created later becomes invalid.
In a hard connection, the content of a file contains multiple file names and will not be lost due to the deletion of the file name.
Cat displays information in the file
Cat 1.c cat 1.txt
Cat and redirection can merge multiple files
Cat 1.txt aaaaa
Cat 2.txt content bbbbb
Cat 1.txt 2.txt> 3.txt aaaaa
Bbbbb
> The output redirection overwrites the original content.
> The output redirection is appended to the end of the file.
Also available
Cat 1.txt> a.txt
Cat 2.txt> a.txt
Then a.txt displays 1.txtand 2.txt.
Grep: Text Search
In linux, The grep command is a powerful text search tool. grep allows mode searches for text files, and grep prints all lines in the contain mode.
General grep format:
Grep [-Option] 'search string' file name
Grep 'A' 1.txt
Common options:
Grep 'xxx' B. py
Grep-n 'xx' B. py shows the number of rows
Grep-n '^ xx' B. py displays the fields that can be found starting with xx.
Grep-n 'xx $ 'B. py displays the fields that can be found at the end of xx.
Grep-n '[Hh] ell [Oo]' B. py search for included Fields
Find: find Files
Find./-name xx. sh find all files named xx in the current directory
Find./-name '*. Sh' find all files with the suffix. sh in the current directory.
Find./-name "[A-Z] *" find all files starting with an uppercase letter in the current directory
Find/tmp-size 2 M search for files equal to 2 MB in the current directory
Find/tmp size + 2 M find files larger than 2 MB in the current directory
Find/tmp size-2 M find files smaller than 2 MB in the current directory
Find./-size + 4 k-size-5 m search for files larger than 4 k and smaller than 5 MB in the current directory
Find./-perm 0777
Cp: copy a file or document directory
Cp 123.py apple/copy 123. py to the apple folder
Cp apple orange/-r recursively copy files in the folder to another folder
Tree/xxxx/display the current or xxx path
Mv: Move a file
Mv file1 file2 will
You can also modify the file name.
Mv 123.py 1234.py
Mv 1234.py 321.py
Tar: Archive Management Package
Format: tar [parameter] package file name
Packaging command: tar-c xxx.tar
Command: tar-x xxx.tar
Tar-cvf test.tar 1.txt 2.txt 3.txt
Tar-cvf a.tar *. py pack all py files
Tar-xvf xxx.tar unpack xxx package
Gzip: A. GZ file generated after File compression
Tar and gzip commands can be used together to package and compress files to generate extension names for xxx.tar.gz
Gzip format
Gzip [Option] compressed file gzip-d decompress
Gzip-r: compress all subdirectories gzip-r test.tar test.tar.gz
Compressed: tar-zcvf test.tar.gz 1.c 2.c 3.c
Decompress: tar-zxvf test.tar.gz
Decompress the package to the specified directory:-C tar-xvf xxx.tar.gz-C./mmmm/decompress it to the mmmm path
Bzip2: File compression to generate bz2 files
Use the extension name with the tar command is generally the xxx.tar.bz2 file.
Add an option in the tar command-j. Call bzip2 to implement the compression function.
Compression usage: tar jcvf xxx.tar.bz2 *. c
Decompress: tar jxvf xxx.tar.bz2
Zip: File compression and unzip
Compressed file: zip [-r] The source file of the target file (No extended name). zip: apple *.*
Decompress the file: unzip-d. decompress the file directory and compress the file unzip-d apple.zip.
Which: view the command location
Which ls: locate the ls directory
3. linux system management commands
Cal: view the current calendar-y displays the calendar of the entire year
Date: display or set the time
Modify system time date [MMDDhhnn [[cc] YY] [. SS] + format
For example, if cc is set to year, YY indicates year, And MM indicates month DD indicates day hh indicates hour nn indicates minute ss indicates second.
Date 010203042018.25
Ps: View Process Information
Ps displays the processes run by the current system. A process is called a program before it is run.
Ps-aux
To terminate a process, enter ps-aux on the second terminal to find the pid of the process.
Top: dynamically displays the resource usage of processes
Input "top" and "M" as memory usage P as cpu usage T as running duration U user name filtering K According to pid killing process q exit h help
Kill: Terminate the process
Use with ps commands
Format: kill [-signal] pid kill 1827
Add the parameter-9 to force the process to end
Kill-9 1827 force Process Termination
Reboot, shutdown, init shutdown and restart
Reboot restart
Shutdown-r now reboot operating system prompt
Shutdown-h now shut down immediately
Shutdown-h shutdown at today
Shutdown-h + 10 minutes later shutdown
Init 0 Shutdown
Init 6 restart
Df: disk space detection
Df command is used to check disk space usage and free space of the file system. df-lh df-m is displayed in 1024 bytes.
Du: disk space occupied by the detection directory
The du command is used to measure the disk space occupied by a directory or file. The result focuses on the disk usage.
The format of the du command is as follows: du [Option] directory or file name du-alh
Ifconfig: view or configure Nic Information
Ping: Test Remote Host connectivity
Ping general rules can communicate with ping 10.222.1.34
4. user permission management commands in linux
Ctrl + alt + (F1-F6) character Interface
Ctrl + alt + F7 exit character Interface
Ctrl + alt find the mouse
Whoami view current user name
Who-q view users
Ssh remote login
After ping, log on to another computer using the ssh command.
Format: ssh username @ IP address exit
Useradd: Add a user account
Switch to supermanager mode in unix/linux and add user accounts
Useradd xxx
Paswd xxx
Switch user su-xxxx exit to exit
Cat/etc/passwd view current user name of the system
Useradd xxxx-m
Passwd: Set the User Password
Userdel xxx: User Deletion
Userdel-r xxx deletes the user directory
Su: Switch users
Switch the Administrator in a non-ubuntu environment, such as in redhat.
Use su root
Su xxx logs in to the original path
Log on to the working directory of su-xxx.
View the number of users
Cat/etc/group or groupmod + three-way tab key
Groupadd abc Add User abc Group
Groupdel abc delete user group abc account
Usermod: Modify the user group
Usermod-g user group Username
Groups xxx
Cat/etc/group | grep 'sudo' from The sudo User group
Add sudo permission
Sudo usermod-a-G adm User Name
Chmod: Modify file permissions
Two methods are available for chmod permission modification.
Ten-rwx
1st-indicates that the file is a normal file.
U and 3 are file owner permissions g and 3 are the permissions of the file owner in the same group. o is the permissions of others.
Chmod u/g/o + r/w/x chmod u + x 1.py add executable permissions to 1. py
Digital method, privilege, R-4, W-2, x-1
Chmod 777 xx. py gives xx. py full Permissions
Chmod u-x 1.py delete executable permissions of the file owner in 1. py
Chown: Modify the file owner
Chown user name file or directory
Chown xxx 1.py
Chgrp: Modify the group to which the file belongs
Chgrp user group name file name chgrp root 1.txt