Review and consolidate the basic operations of Linux, and relearn file management and search, content search, archiving, pipelines, and input and output redirection.
Table of contents
1.6. uniq deduplication command
3. locate (the most complete, most complete)
4. find (actually used the most)
3.1. Commonly used archiving commands:
1. File management
1. 1.head command
root@uos~#: head /etc/passwd root@uos~#: head -n2 /etc/passwd
The head command is to look at the first ten lines of a file, -n2 can reduce the number and content of the first ten lines, just look at the first two lines, -n1 is to look at the first line
1.2. tail command
root@uos~#: tail /etc/passwd root@uos~#: tail -n1 /etc/passwd
Correspondingly, tail is to look at the last ten lines of a file, -n2 can reduce the number and content of the last ten lines, just look at the last two lines, and -n1 is to look at the last line.
There are other uses of tail to monitor other files
root@uos:~# t ail -f /var/log/messages
root@uos:~# echo tang>> /var/log/messages
Then you go to check and you will find that there is a tang item.
1.3. more/less command
root@uos:~# more /var/log/messages
more shows where you are, for example, at 20%.
Press the space bar to scroll back
root@uos:~# less /etc/passwd
The less command can display /etc/passwd, which can be exited by pressing the q key
root@uos:~# cat /boot/grub/grub.cfg | more root@uos:~# cat /bbot/grub/grub.cfg | less
In this way, the originally sliding file can show us the content page by page.
1.4. wc statistics command
root@uos:~# wc /ect/passwd
54 represents how many users, 84 represents how many lines, 3048 represents how many words
1.5. sort sort command
root@uos:~# cat /etc/passwd | sort
It will then display the files in alphabetical order, and by default in ascending order.
root@uos:~# cat /etc/passwd | sort -r (descending)
root@uos:~# cat /etc/passwd | sort -rnk 3 -t :
-r means descending, n means number, -t as separator, k 3 means third column
1.6. uniq deduplication command
root@uos:~# vim tangtest root@uos:~# cat tangtest | uniq (only remove adjacent duplicate content) root@uos:~# cat tangtest | sort | uniq (sort first to make the same content adjacent) root@uos:~# cat tangtest | sort | uniq -c (After deduplication, you can see that there are several identical ones)
root@uos:~# df -Th (see disk information) root@uos:~# df -Th | grep tmpfs root@uos:~# df -Th | grep tmpfs | tr -s " " root@uos:~# df -Th | grep tmpfs | tr -s " " | cut -d " " -f 6 root@uos:~# df -Th | grep tmpfs | tr -s " " | cut -d " " -f 6 | cut -d % -f 1
tr -s " " means to convert spaces
1.7. paste merge command
root@uos:~# vim tang1 root@uos:~# vim tang2 root@uos:~# vim tang3 root@uos:~# paste tang1 tang2 tang3 > tangfile root@uos:~# cat tangfile
We can view our merged effect by cat
After learning the corresponding file management operations, we need to learn about file search next.
2. File search
2.1. which
Example below:
root@uos:~# which ls root@uos:~# which passwd root@uos:~# which ping
2. whereis
Example below:
root@uos:~# whereis ls root@uos:~# whereis passwd root@uos:~# whereis ping
3. locate (the most complete, most complete)
But generally speaking, the Linux system is not self-prepared and needs to be downloaded by yourself.
root@uos:~# apt install locate
The following operations are also required, which can only be performed after reading all disk information
root@uos:~# updatedb
Then you can actually use the locate command
root@uos:~# locate passwd root@uos:~# locate ls root@uos:~# locate ping
4. find (actually used the most)
To view the detailed find content first, you can do the following:
root@uos:~# I'm not sure what to do
The operation is similar to the above method
root@uos:~# find / -name passwd root@uos:~# find / -name ?passwd (here is to find paaswd with the previous one) root@uos:~# find / -name *passwd* root@uos:~# find /etc/ -name *passwd*
root@uos:~# find /etc/ -user tangyimin (search by user)
root@uos:~# find /etc/ -perm 600 (see permissions)
root@uos:~# find /etc/ -size +1k (files larger than 1k) root@uos:~# find /etc/ -szie -1k (files smaller than 1k)
root@uos:~# find /etc/ -type (find by file type)
Press the Tab key twice to see what's there:
root@uos:~# find /dev/ -type b root@uos:~# find /etc/ -type f root@uos:~# find /etc/ -type l -size -10k
root@uos:~# find /etc/ -type l -exec ls -l {} \;
{} means to find all the content found in the previous find, that is, find /etc/ -type l -exec ls -l
root@uos:~# rm -rf /tmp/* root@uos:~# ls -l /tmp/ root@uos:~# find /etc/ -type l -exec cp -rf {} /tmp/ \;
This operation makes all the contents of find placed under tmp
The last is the review of the archive, which is also quite simple, basically you can quickly master it by typing a few more times.
3. Archive
Generally available, but not commonly used in the following ways:
root@uos:~# zip root@uos:~# rar (compression command) root@uos:~# unzip root@uos:~# unrar (decompression command)
For example root@uos:~# unzip
root@uos~# unzip mydata.zip -d mydatabak (unzip mydata.zip under the /home directory into the mydatabak directory) root@uos~# unzip wwwroot.zip (unzip abc12.zip, abc23.zip, abc34.zip under the /home directory into the /home directory at the same time) root@uos~# unzip -v wwwroot.zip (check the contents of wwwroot.zip under the /home directory) root@uos~# unzip -t wwwroot.zip (verify whether wwwroot.zip under the /home directory is complete) root@uos~# unzip abc\*.zip
Common parameters:
-l | Show the files contained in the archive |
---|---|
-v | Display detailed information when executing |
-c | Display the decompressed result on the screen, and convert the characters appropriately |
-n | Do not overwrite existing files when decompressing |
-j | Do not process the original directory path in the compressed file |
3.1. Commonly used archiving commands:
root@uos:~# is not available
-x is decompression
root@uos:~# tar czv (double-click the Tab key to get)
For example, take czvf as an example,
root@uos:~# tar czvf tanglog.tar.gz /var/log/
Then you can use
root@uos:~# ls -l /var/log/
you can view it
or use
root@uos:~# du -sh /var/log/journal/ root@uos:~# du -sh /var/log/ root@uos:~# mkdir /tmp/tang (create a directory) root@uos:~# tar xzvf tanglog.tar.gz -C /tmp/tang (so that the package can be decompressed to /tmp/tang)
4. About checking time operation command
root@uos:~# date +%Y (check year year) root@uos:~# date +%m (check month) root@uos:~# date +%d (check date day) root@uos:~# date +%H (check hour hour) root@uos:~# date +%M (check minute minute) root@uos:~# date +%S(second second) root@uos:~# date +%Y%m%d%H%M%S (you can check a series) root@uos:~# date +%Y-%m-%d-%H-%M-%S root@uos:~# date +"%Y-%m-%d %H:%M:%S" (it can also be in this form) root@uos:~# date +%F (equivalent to all of the above)
Note that the capitalization here is very important, don't remember it wrong!
root@uos:~# rm `date +%F`tanglog.tar.gz /var/log/`
` This symbol is in front of the number line 1 on your keyboard, and the content enclosed by `` can be executed first
All in all, everything in Linux is a file. It seems to be very troublesome to operate, but it is actually quite simple and clear. The corresponding simple operations only need to be written a few more times, whether it is on the Linux operating system or on the VM virtual machine, practice more, and you will soon be able to learn its basic operations.