Original address: http://www.hollischuang.com/archives/800
As a Java developer, there are some common Linux commands that you must master. Even if you do not use Linux (Unix) or mac system in the usual development process, you also need to be proficient in Linux commands. Because many servers are Linux systems. Therefore, to interact with the server machine, it is necessary to pass shell commands.
This article does not explain all the commands in detail, only common usage and explanations are given. The specific usage can be used to --help
view the help or learn directly through google search.
1. Find the file
find / -name filename.txt
Find the filename.txt file under the / directory by name.
find . -name "*.xml"
Find all xml files recursively
find . -name "*.xml" |xargs grep "hello world"
Recursively find xml files containing hello world in all file content
grep -H 'spring' *.xml
Find all the xml files that contain spring
find ./ -size 0 | xargs rm -f &
Delete files with zero file size
ls -l | grep '.jar'
Find all jar files in the current directory
grep 'test' d*
Show all lines that contain test in files starting with d.
grep 'test' aa bb cc
Show lines matching test in aa, bb, cc files.
grep '[a-z]\{5\}' aa
Displays all lines containing strings with at least 5 consecutive lowercase characters per string.
2. See if a program is running
ps –ef|grep tomcat
View all processes related to tomcat
ps -ef|grep --color java
Highlight the keyword you want to query
3. Terminate the thread
kill -9 19979
Terminate the process with thread number 19979
4. View files, including hidden files
ls -al
5. Current working directory
pwd
6. Copy files
cp source dest
copy file
cp -r sourceFolder targetFolder
Copy entire folder recursively
scp sourecFile romoteUserName@remoteIp:remoteAddr
remote copy
7. Create a directory
mkdir newfolder
8. Delete the directory
rmdir deleteEmptyFolder
delete empty directory rm -rf deleteFile
recursively delete all contents in a directory
9. Move files
mv /temp/movefile /targetFolder
10. Heavy order
mv oldNameFile newNameFile
11. Switch users
su -username
12. Modify file permissions
chmod 777 file.java
//Permission of file.java - rwxrwxrwx, r means read, w means write, x means executable
13. Compressed files
tar -czf test.tar.gz /test1 /test2
14. Make a list of compressed files
tar -tzf test.tar.gz
15. Unzip the file
tar -xvzf test.tar.gz
16. View the first 10 lines of the file
head -n 10 example.txt
17. View the last 10 lines of the file
tail -n 10 example.txt
18. View log type files
tail -f exmaple.log
//This command will automatically display the new content, and the screen only displays 10 lines of content (can be set).
19. Execute commands as super administrator
sudo rm a.txt
Delete files as administrator
20. View port occupancy
netstat -tln | grep 8080
Check the usage of port 8080
21. See which program the port belongs to
lsof -i :8080
22. View the process
ps aux|grep java
View java process
ps aux
View all processes
23. List the contents of the directory as a tree diagram
tree a
ps: Use tree command under Mac
24. File Download
wget http://file.tgz
Install wget command under mac
curl http://file.tgz
25. Network Detection
ping www.just-ping.com
26. Remote login
ssh userName@ip
27. Printing Information
echo $JAVA_HOME
Print the value of the java home environment variable
28.java common commands
java javac jps ,jstat ,jmap, jstack
29. Other commands
svn git maven
28.Linux command learning website:
References:
The solution to the occupied Linux port (Error: JBoss port is in use. Please check)
Powerful and common commands in linux: find, grep