1, Background
I have accumulated a lot of commands related to the server in my work, which are commonly used. Record and share them with you. I hope it will be helpful.
2, Common commands
1. vim enters the file, exits the editing mode, executes DD to delete a whole line, and 20dd to delete 20 lines under the cursor
2. When bash execution is complete, enter $? You can view the return value 0 or 1
3. Add this sentence at the beginning of bash script.
#!/bin/bash
4. Execute bash file, prompt insufficient permission, execute command
chmod +x ./Your program
5. How do I exit bash when executing a bash script?
(1) Open a new cmd and execute
ps -ef|grep exportsql.sh
(2) Get the port number and execute the following command:
kill -9 pid
6. View the folder size in the current directory
du -h --max-depth=1 |sort
7. View disk space size
df -h
8. Migrate files
(1) (download the remote dbconfig.xml to the local test directory)
scp -P 54321 -r root@ip:/root/dbconfig.xml /home/jiankangxu/test
(2) Upload file to server:
scp -P 22 -r D:\springdubbo20210902\nacos-server-2.0.3.tar.gz root@bj0:/nacos
9. View server version
uname -n
10. Switch root user
sudo -s
11. Modify the permissions of all files in the directory, readable, writable and executable
chmod -R 777 /home/jiankangxu/var/atlassian/application-data/jira/data
12. Switch sub user test
su - test
13. View which user the current user is
whoami
14. To modify the server language, centos7 goes to / etc/locate.conf and executes the following command
source /etc/locale.conf
15. View task running status and parent process number
ps -ef|grep scp
16. View directory permissions
ls -l
17. Move the attachments directory to the data directory
mv /home/jiankangxu/var/atlassian/application-data/jira/datas/attachments /home/jiankangxu/var/atlassian/application-data/jira/data
18. The files are arranged from small to large
du -sh * | sort -nr
19. Find file
whereis aaa.txt
20. Find out if the jdk is installed on the system
rpm -qa | grep jdk
21. Extract the cenos file to the specified directory
sudo tar -xzvf j.tar.gz -C java
22. Extract the cenos file to the current directory
sudo tar -zxvf a.tar.gz
23. Return to the root directory
cd /
24. Add user
useradd ftpuser
25. Modify file permissions. Both user name and user group are ftpuser
sudo chown -R ftpuser.ftpuser ./ftpfile/
26. Modify user password
sudo passwd ftpuser
27. Modify security policy
sudo vim /etc/selinux/config
28. View ports
ps -ef | grep nginx
sudo lsof -i:8000
29. Kill a port
sudo kill -9 850
30. Check whether nginx is started
ps aux|grep nginx
31. View the contents of a file
cat ~/.ssh/id_rsa.pub
32. Check whether there are iptables in the current directory
ll | grep ipt
33. Grant a user permission for the whole directory
sudo chown -R geely /developer/
34. Modify the file permissions in the directory, which are readable, writable and executable
(1) Write
sudo chmod u+w -R /developer
(2) Read
sudo chmod u+r -R /developer
(3) Execute
sudo chmod u+x -R /developer
35. View local ip
ifconfig -a
36. Switch to the following user
sudo -s
37. Return to normal user
su jiankang
38. Use find to fuzzy match the file path whose name contains kafka
find / -name "*kafka*"
39. Permission to view the file
ls -la
40. File executable rights granted to all users
chmod a+rwx swapfile
41. View file attributes
lsattr
42. Delete file attributes
chattr -i filename
43. Viewing ports
netstat -tunlp
44. View specific ports
netstat -tnlp | grep :80
45. unix obtains the full path of the file
readlink -f file.txt
46. Delete directory
rm -rf mysql
47, View remaining memory
free -h
48. View the current directory file size
ls -lht
49. Download files
sudo wget --no-check-certificate https://dlcdn.apache.org/kafka/3.0.0/kafka-3.0.0-src.tgz
3, Summary
The above are some commands commonly used in work. Please record them here. I hope they can help you. If you think it's good, welcome wechat search to pay attention to the basic notes of java. Later, we will constantly update relevant knowledge and make progress together.