Table of contents
1. Shell commands and operating principles
6.rmdir command&& rm command (important)
16.fifind command: (very important) -name
21. Several important hot keys [Tab], [ctrl]-c, [ctrl]-d
1. Classification of file visitors (people)
2. File type and access permissions (thing attributes)
3. Representation method of file permission value
4. Related setting methods for file access permissions
1. Shell commands and operating principles
2. Common Linux commands
1. ls command
-a Lists all files in the directory, including implicit files starting with .-d displays the directory as a file, rather than displaying the files below it. For example: ls –d specifies the directory-i Outputs the index information of the i node of the file. For example, ls –ai specifies the file-k indicates the size of the file in k bytes. ls –alk specifies the file-l List file details.-n Use numeric UID, GID instead of name. (Introducing UID, GID)-F Attach a character after each file name to indicate the type of the file. "*" indicates an executable ordinary file; "/" indicates a directory; "@" indicatesrepresents a symbolic link; "|" represents FIFOs; "=" represents sockets. (Directory type identification)-r Sort the directory in reverse order.-t Sort by time.-s outputs the size of the file after the l file name. (Size sorting, how to find the largest file in a directory)-R List files in all subdirectories. (recursion)-1 outputs only one file per line.
2. pwd command
Displays that the kiana user is currently under the "/home" path.
3.cd command
In the Linux system, the files and directories on the disk are organized into a directory tree, and each node is a directory or file.
cd .. : Return to the upper directorycd /home/litao/linux/ : absolute pathcd ../day02/ : relative pathcd ~: Enter the user's home directorycd -: Return to the recently visited directory
4. touch command
-a or --time=atime or --time=access or --time=use only changes the access time.-c or --no-create Do not create any documentation.-d Use the specified date and time instead of the current time.-f This parameter will be ignored and will not be processed. It is only responsible for solving the compatibility problem of the BSD version of the touch command.-m or --time=mtime or --time=modify only change the change time.-r sets the date and time of the specified document or directory to be the same as the date and time of the reference document or directory.-t Use the specified date and time instead of the current time
5.mkdir command (important)
mkdir –p test/test1: Create multiple directories recursively
6.rmdir command&& rm command (important)
-p When the subdirectory is deleted, if the parent directory also becomes an empty directory, the parent directory will be deleted together.
-f Even if the file attribute is read-only (i.e. write-protected), delete it directly-i Ask for confirmation one by one before deleting-r deletes the directory and all files under it
7.man command (important)
-k Search online help based on keywordsnum is only found in chapter num-a displays all chapters, such as man printf. By default, it starts searching from the first chapter and stops when it is known. Use the a option. When pressing q to exit, it will continue to search until all chapters are searched. .
8.cp command (important)
9.mv command (important)
-f: force means force. If the target file already exists, it will be overwritten directly without asking.-i: If the destination file (destination) already exists, you will be asked whether to overwrite it!
将rm改造成mv
vim ~/.bashrc #修改这个文件
mkdir -p ~/.trash
alias rm=trash
alias ur=undelfile
undelfile() {
mv -i ~/.trash/\$@ ./
}
trash() {
mv $@ ~/.trash/
}
10.cat
-b output line numbers for non-empty lines-n numbers all lines of output-s does not output multiple blank lines
-n numbers all lines of outputq exitmore
11.less directive (important)
-i ignore case when searching-N displays the line number of each line/string: function to drill down for "string"?String: Function to search upward for "string"n: Repeat the previous search (related to / or ?)N: Repeat the previous search in reverse (related to / or ?)q:quit
12.head command
-n<number of lines> Number of lines to display
-f loop reading-n<number of lines> displays the number of lines
There is a file with a total of 100 lines of content. Please take out the 50th line of content<br>seq 1 100 > test # Generate a sequence from 1 to 100 and load it into testMethod 1 head -n50 test > tmp #Load the first 50 lines into the temporary file tmptail -n1 tmp #Get China Construction BankMethod 2 head -n50 test | tail -n1
14. Time-related instructions
date display
Date specifies the format to display time: date +%Y:%m:%d
%H : hours (00..23)%M : Minutes (00..59)%S : seconds (00..61)%X: equivalent to %H:%M:%S%d : day(01..31)%m: month (01..12)%Y: Complete year (0000..9999)%F: equivalent to %Y-%m-%d
date -s //Set the current time. Only root permissions can set it, others can only view it.date -s 20080523 //Set to 20080523, which will set the specific time to empty 00:00:00date -s 01:01:01 //Set the specific time and the date will not be changed.date -s “01:01:01 2008-05-23″ //This can set the entire timedate -s “01:01:01 20080523″ //This way you can set the entire timedate -s “2008-05-23 01:01:01″ //This way you can set the entire timedate -s “20080523 01:01:01″ //This way you can set the entire time
Time->Timestamp: date +%sTimestamp->Time: date -d@1508749502The Unix timestamp (Unix epoch, Unix time, POSIX time or Unix timestamp in English) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), regardless of leap seconds.
15.Cal instructions
-3 Display the system’s calendar of the previous month, current month, and next month-j displays the day of the year (the date of the year is calculated in days, starting from January 1st, and the number of days of the current month in the year is displayed by default)-y displays the calendar for the current year
16.fifind command: (very important) -name
17. grep command
-i: Ignore the difference in case, so the cases are treated as the same-n: Output the line number by the way-v: reverse selection, that is, display the line without the 'search string' content
18.zip/unzip command:
Compress the test2 directory: zip test2.zip test2/*Unzip to the tmp directory: unzip test2.zip -d /tmp
19.tar command (important)
-c: Parameter command to create a compressed file (meaning create);-x: Parameter command to unpack a compressed file!-t: View the files in tarfifile!-z: Does it also have the attributes of gzip? That is, do I need to use gzip compression?-j: Does it also have the attributes of bzip2? That is, do I need to use bzip2 compression?-v: Display files during compression! This is commonly used, but it is not recommended to be used in background execution processes!-f: Use the file name. Please note that the file name must be followed immediately after f! Don't add any more parameters!-C: Extract to the specified directory
example:
Example 1: Pack all the files in the entire /etc directory into `/tmp/etc.tar`[root@linux ~]# tar -cvf /tmp/etc.tar /etc<== only packaging, not compression![root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc <==After packaging, compress with gzip[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc <==After packaging, compress it with bzip2Pay special attention to the fact that the file name after parameter f is chosen by yourself. We are accustomed to use .tar as identification.If the z parameter is added, .tar.gz or .tgz will represent the gzip-compressed tar file ~If you add the j parameter, .tar.bz2 will be used as the file extension~When the above command is executed, a warning message will be displayed:『`tar: Removing leading `/" from member names`』 That is a special setting about absolute paths.Example 2: Check what files are in the above /tmp/etc.tar.gz file?[root@linux ~]# tar -ztvf /tmp/etc.tar.gzSince we use gzip compression, when we want to check the files in the tar file, we have to add the z parameter! This is very important!Example 3: Extract the /tmp/etc.tar.gz file under /usr/local/src[root@linux ~]# cd /usr/local/src[root@linux src]# tar -zxvf /tmp/etc.tar.gzBy default, we can unzip the compressed file anywhere! For this example,I first change the working directory to /usr/local/src and unzip /tmp/etc.tar.gz,The unlocked directory will be in /usr/local/src/etc! Also, if you go into /usr/local/src/etcYou will find that the file attributes in this directory may be different from /etc/!Example 4: Under /tmp, I just want to unlock etc/passwd in /tmp/etc.tar.gz [root@linux ~]# cd /tmp[root@linux tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwdI can use tar -ztvf to check the file names in the tarfile. If I only want one file,You can submit it through this method! Notice! The root directory / in etc.tar.gz has been removed!Example 5: Back up all files in /etc/ and save their permissions![root@linux ~]# tar -zxvpf /tmp/etc.tar.gz /etcThis -p attribute is very important, especially when you want to retain the attributes of the original file!Example 6: In /home, only files newer than 2005/06/01 are backed up.[root@linux ~]# tar -N "2005/06/01" -zcvf home.tar.gz /homeExample 7: I want to back up /home, /etc, but not /home/dmtsai[root@linux ~]# tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etcExample 8: Pack /etc/ and unpack it directly under /tmp without generating a file![root@linux ~]# cd /tmp[root@linux tmp]# tar -cvf - /etc | tar -xvf -This action is a bit like cp -r /etc /tmp ~ it still has its purpose!What should be noted is that the output file becomes - and the input file also becomes -, and there is another |These represent standard output, standard input and pipeline commands respectively!
20.uname -r command:
-a or –all output all information in detail, in order: kernel name, host name, kernel version number, kernel version, hardware name, processor type, hardware platform type, operating system name
21. Several important hot keys [Tab], [ctrl]-c, [ctrl]-d
[Tab] button---has the functions of "command completion" and "file completion"[Ctrl]-c key---"stop" the current program[Ctrl]-d key---usually represents: "End Of File, EOF or End OfInput"; in addition, it can also be used to replace exit
22. Shut down
Syntax :
shutdown [options] ** Common options: **-h: After stopping the system service, shut down immediately.-r: Restart the system service after stopping it-t sec: Add the number of seconds after -t, which means "shut down after a few seconds"
3.Linux permissions
1. Classification of file visitors (people)
2. File type and access permissions (thing attributes)
d: folder-: Ordinary filel: Soft link (similar to Windows shortcut)b: Block device file (such as hard disk, optical drive, etc.)p: pipe filec: character device file (such as screen and other serial devices)s: socket file
i. Read (r/4): For files, Read has the permission to read the file content; for directories, it has the permission to browse the directory information.ii. Write (w/2): For files, Write has the permission to modify the file content; for directories, it has the permission to delete files in the moved directory.iii. Execute (x/1): For files, execute has the permission to execute the file; for directories, it has the permission to enter the directory.iv. “—” means that you do not have the permission
3. Representation method of file permission value
(1) Character representation method
(2) Octal numerical representation method
4. Related setting methods for file access permissions
# chmod u+w /home/abc.txt# chmod ox /home/abc.txt
# chmod 664 /home/abc.txt# chmod 640 /home/abc.txt
# chown user1 f1# chown -R user1 filegroup1
# chgrp users /abc/f2
5.fifile command
-c displays the instruction execution process in detail to facilitate troubleshooting or analysis of program execution.-z Attempt to decipher the contents of the compressed file.
# chmod 740 /etc/sudoers# vi /etc/sudoer
6. Directory permissions
[root@localhost ~]# chmod 0777 /home/[root@localhost ~]# ls /home/ -lddrwxrwxrwx. 3 root root 4096 9月 19 15:58 /home/[root@localhost ~]# touch /home/root.c[root@localhost ~]# ls -l /home/Total usage 4-rw-r--r--. 1 root root 0 Sep 19 15:58 abc.cdrwxr-xr-x. 27 litao litao 4096 September 19 15:53 litao-rw-r--r--. 1 root root 0 9月 19 15:59 root.c[root@localhost ~]# su - litao[litao@localhost ~]$ rm /home/root.c #litao can delete files created by rootrm: Delete the write-protected ordinary empty file "/home/root.c"? y[litao@localhost ~]$ exitlogout
7. Sticky bit
When a directory is set to the "sticky bit" (using chmod +t), the files in the directory can only be accessed by
[root@localhost ~]# chmod +t /home/ # Add sticky bit[root@localhost ~]# ls -ld /home/drwxrwxrwt. 3 root root 4096 9月 19 4:00 PM /home/[root@localhost ~]# su - litao[litao@localhost ~]$ rm /home/abc.c #litao cannot delete other people’s filesrm: Delete the write-protected ordinary empty file "/home/abc.c"? yrm: cannot delete "/home/abc.c": Operation not allowed