Java development will be required to Linux command

As a Java developer, there are some common Linux commands you must master. Even if you do not use Linux (Unix) or MAC system during normal development, you need to be familiar with Linux commands. Because a lot of servers run Linux. So, to interact with the server machine, you need to use shell commands.

This article does not cover all commands in detail, but only common usages and explanations. You can use –help to see help or just Google it.

0. Enter the command quickly

#Automatically matches the history command entered 
ctrl + r 

#Move the tube to the front quickly
ctrl + a

#Move the tube quickly to the end
ctrl + e
Copy the code

1. Search for files

#Find filename. TXT in/by name.
find / -name filename.txt

#Find all XML files recursively
find . -name "*.xml"

#Recursively find all XML files that contain Hello World in their contents
find . -name "*.xml" |xargs grep "hello world"

#Find all the XML files that contain Spring
grep -H 'spring' *.xml

#Delete a file whose size is zero
find ./ -size 0 | xargs rm -f &

#Find all jar files in the current directory
ls -l | grep '.jar'

#Displays all files starting with D contained intestThe line.
grep 'test' d*

#Shows match in AA, BB, cc filestestThe rows of
grep 'test' aa bb cc

#Displays all lines containing strings with at least 5 consecutive lowercase characters per string
grep '[a-z]\{5\}' aa
Copy the code

2. Check whether a program is running

#View all processes related to TomcatPs - ef | grep tomcat
#Highlight the keywords to be queried
ps -ef|grep --color java
Copy the code

3. Terminate the thread

#Terminates the process at thread 19979
kill -9 19979

# or
kill 19979
Copy the code

4. View files, including hidden files

ls -al
Copy the code

5. Current working directory

pwd
Copy the code

6. Copy files

#Copy the file
cp source dest

#Recursively copy the entire folder
cp -r sourceFolder targetFolder

#Copying data from a local PC to a Remote PC (on a Mac)
#file
scp sourecFile romoteUserName@remoteIp:remoteAddr
#folder
scp sourecFile -r romoteUserName@remoteIp:remoteAddr

#Copying data from a Remote PC to a Local PC (on a Mac)
#file
scp shanghai-2-hz:javalog.txt /Users/zhengshangjin/Downloads/
#folder
scp shanghai-2-hz:javalog -r /Users/zhengshangjin/Downloads/
Copy the code

7. Create a directory

mkdir newfolder
Copy the code

8. Delete the directory

#Deleting an Empty Directory
rmdir deleteEmptyFolder

#Recursively delete all contents of a directory
rm -rf deleteFile
Copy the code

9. Move files

mv /temp/movefile /targetFolder
Copy the code

10. Renamed

mv oldNameFile newNameFile
Copy the code

11. Switch users

su -username
Copy the code

12. Modify file permissions

#File. Java permission - RWXRWXRWX, r indicates read, w indicates write, and x indicates executable
chmod 777 file.java
Copy the code

###13. Zip files

tar -czf test.tar.gz /test1 /test2
Copy the code

14. List compressed files

tar -tzf test.tar.gz
Copy the code

15. Decompress the files

tar -xvzf test.tar.gz
Copy the code

16. Look at the first 10 lines of the file

head -n 10 example.txt
Copy the code

17. Look at the last 10 lines of the file

tail -n 10 example.txt
Copy the code

18. View the log type file

#This command automatically displays the new content, and the screen displays only 10 lines of content (configurable).
tail -f exmaple.log
Copy the code

19. Run commands as the super administrator

#Delete files as administrator
sudo rm a.txt
Copy the code

20. Check the port usage

#Check the usage of port 8080
netstat -tln | grep 8080

#Check which service port 8080 is used by
netstat -tunlp | grep :8080

#Check whether a port is occupied by a service
netstat -tunlp | grep :

#Check whether the HTTPD service is started
ps aux | grep httpd
Copy the code

21. Check which program the port belongs to

lsof -i :8080
Copy the code

22. Check the process

#Viewing Java Processes
ps aux|grep java

#Viewing All Processes
ps aux
Copy the code

23. List the contents of the directory as a tree

tree a
Copy the code

Ps: Run the tree command in Mac

24. File download

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

curl http://file.tgz
Copy the code

25. Network detection

ping www.just-ping.com
Copy the code

26. Remote login

ssh userName@ip
Copy the code

27. Print information

#Prints the value of the Java Home environment variable
echo $JAVA_HOME
Copy the code

28. Common Java commands

java javac jps ,jstat ,jmap, jstack

29. Other commands

svn git maven

Original: www.cnblogs.com/dassmeta/p/…