Operations 7 min read

Common Linux Commands for Java Developers

This article provides Java developers with a concise reference of essential Linux shell commands, covering process inspection, file manipulation, permission changes, compression, networking checks, remote access, and other common operations needed for interacting with Linux servers during development and deployment.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
Common Linux Commands for Java Developers
As a Java developer, certain common Linux commands must be mastered. Even if you usually develop on Windows or macOS, you need to be proficient with Linux commands because many servers run Linux, and interacting with those servers requires shell commands.

This article does not explain every command in detail; it only presents common usage and explanations. For full usage, you can view help with --help or search online.

2. Check if a program is running

ps
-ef|
grep
tomcat

View all processes related to tomcat

3. Terminate a process

kill
-9 19979

Terminate the process with PID 19979

4. List files, including hidden ones

ls
-al

5. Show current working directory

pwd

6. Copy files

cp
source
dest

Copy a file

cp
-r sourceFolder targetFolder

Recursively copy an entire directory

scp
sourceFile remoteUserName@remoteIp:remoteAddr

Copy a file to a remote host

7. Create a directory

mkdir
newfolder

8. Delete a directory

rmdir
deleteEmptyFolder

Delete an empty directory

rm
-rf deleteFile

Recursively delete all contents of a directory

9. Move a file

mv
/temp/movefile
/targetFolder

10. Rename a file

mv
oldNameFile newNameFile

11. Switch user

su
-username

12. Change file permissions

chmod
777
file.java

Set permissions to rwxrwxrwx (read, write, execute for all)

13. Compress files

tar
-czf
test.tar.gz
test1 test2

Create a gzipped tar archive of test1 and test2

14. List contents of a compressed file

tar
-tzf
test.tar.gz

List files inside the archive

15. Extract a compressed file

tar
-xvzf
test.tar.gz

Extract the gzipped tar archive

16. View first 10 lines of a file

head
-n 10 example.txt

17. View last 10 lines of a file

tail
-n 10 example.txt

18. Monitor a log file

tail
-f example.log

Continuously display new content appended to the log (default shows last 10 lines)

19. Execute a command as superuser

sudo
rm
a.txt

Delete a.txt with administrator privileges

20. Check port usage

netstat
-tln | grep 8080

Show whether port 8080 is in use

21. Identify which program uses a port

lsof
-i :8080

22. View processes

ps
aux| grep java

Show Java processes

ps
aux

Show all processes

23. List directory contents as a tree

tree a

Display directory a in a tree format (available on macOS)

24. Download files

wget http://file.tgz

Download using wget

curl http://file.tgz

Download using curl

On macOS, install wget if needed.

25. Network testing

ping www.just-ping.com

Ping a host to test connectivity

26. Remote login

ssh
userName@ip

Connect to a remote host via SSH

27. Print information

echo
$JAVA_HOME

Print the value of the JAVA_HOME environment variable

28. Common Java commands

java, javac, jps, jstat, jmap, jstack

29. Other useful commands

svn git maven

Source: java一日一条

Long press the QR code to open in a browser.

Download the online course app instantly.

Supports Android and iOS.

Qunar’s latest and hottest video courses are all here!

JavaoperationsDevOpsLinuxShellCommandLine
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.