Learning common commands in Unix
1. Change the permissions of a file or directory
Q: create the file a.txt, change the user master of the file to read-write execution, the user group to read-write, and the rest to read-only
A:
Create: files can be created with vim.
Modify permissions: the default permission after creation is-rw-r--r--, adds the execution permission of the user head and the write permission of the user group according to the requirements of the problem. The command is as follows:
Chmod upright x a.txt
Chmod Grouw a.txt
A:touch a.txt
Chmod 764 a.txt
two。 Copy command
Q: copy the a.txt file to a b.txt file while preserving the properties of the source file
A:cp-p a.txt b.txt
3. Cut a file
Q: displays the 2nd to 8th characters of each line of the file
A:cut-c 2-8 a.txt
4. Generate difference information
Q: compare the differences between the two files and generate the difference information
A:diff filename1 filename2
5. Identify the file type
Q: show the file types under the / var/log folder
A:ls-l / var/log
A:file / var/log
6. Find a directory or file
Q: find the file name under / usr/bin is openssl file
A:find / usr/bin-name "openssl"
Q: find files that have been modified within 24 hours under the home directory
A:find / home-mtime-1
Q: find files that have been modified within 30 minutes under the home directory
A:find / home-mmin-30
7. Link a file or directory
Q: establish a symbolic link to the file a.txt la.txt
A:ln-s a.txt la.txt
8. Merge the columns of a file
Q: a.txt b.txt is merged column by column and output to standard output.
A:paste a.txt b.txt
9. Package and compress and extract files at the same time
Q: package a.txt and b.txt to c.tar.gz
A:tar zcvf c.tar.gz a.txt b.txt
10. Read data from standard input to standard output and save it as a file
Q: export the file a.txt to standard output and save it as d.txt
A:cat a.txtwitcp a.txt d.txt
A:cat a.txt | tee d.txt
11. Sorting of text content
Q: sort the output of the file a.txt in reverse order
A:tac a.txt
A: sort-r a.txt
twelve。 Show working directory A:pwd
13. Display or configure network devices
Q: displays the working status of the current network device
A: ifconfig
14. Show network status
Q: displays the network status in the listening state of the system
A:netstat-anp | grep LISTEN
15. Encrypted remote login
Q: log in to 172.17.0.20 remotely with quwenqing user
A:ssh quwenqing@172.17.0.20
16. Kill the process in progress
Q: find out the processes in the system that contain the php keyword and kill one of them
A:ps-auxww | grep php
Kill-9 xxx
17. Execute an order in another capacity
Q: display disk usage as root
A:sudo df-h
18. Set or display environment variables
Q: set the environment variable A=ttt to display the environment variable
A:export A = "ttt"
Echo $A
19. Awk displays the matching line containing ab in the file a.txt
A:awk'/ ab/ {print} 'a.txt
20. Awk displays the current record number of the file a.txt, the number of fields, and the first and last fields of each line.
A:awk'{print NR,NF,$1,$NF} 'a.txt
21. Use awk filtering to check the number of connections in netstat
A: netstat-an | awk'/ ^ tcp/ {A [$NF] + +} END {for (an in A) print a, A [a]}'
twenty-two。 Delete 3-5 lines from the a.txt with sed, replace all a with A, and output to the monitor
A:sed '3pm 5d incense a.txt an Accord A Universe
A: sed-e '3mai 5d'-e's Unip. A Unique Amax g 'a.txt
F.A.H ^ _ ^ Amber