As a Java developer, there are some common Linux commands that you must master. Even if you don’t use Linux (Unix) or MAC during your development, you need to be familiar with Linux commands. Because many of the servers are Running Linux. So, to interact with the server machine, you need to use shell commands.

This article does not cover all the commands in detail, only common usage and explanations. You can use –help to see help or Google to learn.

1. Search for files

TXT Searches for the filename. TXT file in the/directory by name.

Find.name “*.xml” recursively searches all XML files

. Find -name “*. XML” | xargs grep “hello world” recursive search for all the file content contained in the hello world of XML file

Grep -h ‘spring’ *.xml to find all XML files containing spring

The find. / – size 0 | xargs rm -f & delete the file size is zero

The ls -l | grep ‘jar’ search all the jar files in the current directory

Grep ‘test’ d* Displays all lines that contain test in files beginning with d.

Grep ‘test’ aa bb cc The line matching test is displayed in the AA, bb, and cc files.

Grep ‘[a-z]\{5\}’ aa displays all lines containing strings with at least 5 consecutive lowercase characters per string.

2. Check whether a program is running

Ps – ef | grep tomcat to see all process about tomcat

Ps – ef | grep — color Java highlight to query keyword

3. Terminate the thread

Kill -9 19979 Terminates 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 Copies the file

Cp -r sourceFolder targetFolder Recursively copies the entire folder

SCP sourecFile romoteUserName@remoteIp:remoteAddr Remote copy

7. Create a directory

mkdir newfolder

8. Delete a directory

Rmdir deleteEmptyFolder Deletes an empty directory rm -rf deleteFile Deletes all contents in a directory recursively

9. Move files

mv /temp/movefile /targetFolder

10. Renamed

mv oldNameFile newNameFile

11. Switch to a user

su -username

12. Modify file permissions

Java // File. Java permission -rwxrwxrwx, r means read, w means write, x means executable

13. Compress files

tar -czf test.tar.gz /test1 /test2

14. List the compressed files

tar -tzf test.tar.gz

15. Decompress 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 the log type file

Tail -f exmaple.log // This command automatically displays the new content. The screen only displays 10 lines of content (configurable).

19. Run commands as the super administrator

Sudo rm a.tb Deletes files as an administrator

20. Check whether the port is occupied

Netstat TLN | grep 8080 view port 8080

21. Check which program the port belongs to

lsof -i :8080

22. View the process

Ps aux | grep Java to check the Java process

Ps aux View all processes

23. List the contents of a directory in a tree

tree a

Ps: Run the tree command on the Mac

24. File download

Wget http://file.tgz Install the wget command on the MAC

curl http://file.tgz

25. Network detection

ping www.just-ping.com

26. Remote login

ssh userName@ip

27. Print information

Echo $JAVA_HOME Prints the value of the Java Home environment variable

28. Common Java commands

java javac jps ,jstat ,jmap, jstack

29. Other commands

svn git maven

Linux command Learning website:

explainshell.com/

References:

Error: JBoss port is in use. Please check

The common and powerful commands in Linux are find and grep

Linux command

Welcome to add! ~