Essential Shell Commands Every Java Developer Should Know
As a Java developer, it’s easy to live inside your IDE and forget that much of software development still happens in the terminal —…
Essential Shell Commands Every Java Developer Should Know
As a Java developer, it’s easy to live inside your IDE and forget that much of software development still happens in the terminal — whether you’re working locally, debugging a production server, or automating tasks in CI/CD pipelines.
Learning some basic shell (bash) commands can make you faster, more confident, and far more capable when things don’t go as planned.
In this post, we’ll explore the core shell commands every Java developer should know, explain how and when to use them, and will show simple, real-world examples.
Why Shell Knowledge Matters for Java Developers
Even if you’re not a DevOps engineer, you’ll often interact with Linux or macOS terminals in these scenarios:
- Running and deploying JAR files on a remote server.
- Debugging production issues by checking logs or killing processes.
- Automating repetitive tasks like cleaning up old logs or starting background services.
- Working in CI/CD pipelines (Jenkins, GitLab, GitHub Actions) that run shell scripts under the hood.
If you can use the shell comfortably, you’ll save hours every week and feel much more at home on any system.
Getting Started: Your Shell Environment
Before diving into commands, it’s useful to know which shell you’re in. Run:
echo $SHELL
You’ll typically see /bin/bash or /bin/zsh.
Also:
- Press the up / down arrow keys to navigate command history.
- Use Ctrl + R to search past commands.
- Enable tab completion — type a few letters of a file name and hit Tab to auto-complete.
You can also create handy aliases for frequently used commands in your ~/.bashrc or ~/.bash_profile:
alias ll='ls -alF'
alias gs='git status'
Navigating Your File System
Let’s start with the basics of moving around and inspecting files.
pwd — Print Working Directory
Displays your current location in the file system.
pwd
Example output:
/Users/himanshu/projects/my-java-app
You’ll use this constantly when jumping between folders or checking where your script is running.
cd— Change Directory
Move into another folder:
cd src/main/java
Use cd .. to move one level up, and cd — to jump back to your previous directory.
ls— List Files
Lists all files and directories in the current folder.
ls
ls -al # shows the hidden files and details
This helps you inspect project structure, especially in deep folders like target/classes or build/.
Creating, Copying, and Deleting Files
These are the bread-and-butter file operations you’ll use daily.
mkdir and rmdir
Create or remove directories:
mkdir logs
rmdir old_logs
Add the -p flag to create nested directories in one go:
mkdir -p src/test/java/com/example
touch
Create a new, empty file (or update an existing file’s timestamp):
touch .gitignore
Useful for placeholders or quick edits.
cp and mv
Copy or move files:
cp MyClass.java backup/
mv oldname.java NewName.java
You’ll use these to rename classes, move config files, or back up scripts.
rm
Delete files — but handle with care:
rm temp.txt
rm -r old_logs/
-r deletes directories recursively, and there’s no undo. To stay safe, try rm -i(interactive mode) to confirm deletions.
Reading and Searching Files
Java developers spend plenty of time reading logs or scanning through configuration files.
cat and less
cat prints file contents, while less lets you scroll through large files:
cat pom.xml
less application.log
Use / inside less to search within the file, and q to quit.
grep
Your best friend for log analysis. It searches for patterns in files:
grep "Exception" logs/app.log
grep -R "NullPointerException" src/
-R searches recursively through folders.
find
Locate files by name or type:
find . -name "*.class"
find logs/ -type f -mtime +7
This can help you locate compiled .class files, or find logs older than a week.
Viewing and Counting File Data
head and tail
Display the first or last few lines of a file:
head -n 10 file.log
tail -n 20 file.log
And when you’re debugging a live service, this is gold:
tail -f application.log
It continuously shows new log lines in real time.
wc — Word Count
Count lines, words, and characters in a file:
wc -l application.log
This returns the total number of lines — handy for checking file size or number of log entries.
Working with Permissions and Variables
chmod
Change file permissions — especially useful when writing scripts:
chmod +x deploy.sh
This makes your script executable.
export
Set an environment variable (like your Java home):
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk
Once set, you can use $JAVA_HOME anywhere in your shell or scripts.
Combining Commands and Running Processes
Command chaining
You can combine commands using:
- && → run next command only if previous succeeded
- || → run next if previous failed
- ; → run regardless of success or failure
Example:
mkdir logs && cd logs
Command substitution
Use the output of one command inside another:
echo "Today is $(date)"
Running background processes
When launching your app:
java -jar app.jar &
This runs your app in the background.
For long-running processes that survive terminal closures, use nohup:
nohup java -jar app.jar &
Managing processes
Check if your Java app is running:
ps aux | grep java
Kill a process by its ID:
kill -9 12345
Bonus Section: Getting Comfortable with Vim (vi Editor)
At some point, every Java developer working on a Linux or macOS system will be dropped into a terminal where the only available editor is Vim (or its older sibling, vi).
Maybe you SSH into a remote server to quickly edit a configuration file — and boom, Vim opens. You press keys, nothing happens, and panic sets in.
Let’s fix that once and for all.
What Is Vim?
Vim (short for Vi IMproved) is a text editor built into most UNIX-based systems. It runs entirely in the terminal and is extremely powerful — but has a bit of a learning curve because it uses modes instead of menus.
How to Open a File in Vim?
To open or create a file using Vim, just type:
vim filename.txt
If the file doesn’t exist, Vim will create it. You’ll now be inside the Vim editor, in what’s called Normal mode (the default state).
Understanding Vim Modes
Vim has three main modes that you’ll switch between:
- Normal mode — used for navigation and commands (default mode when you open Vim).
- Insert mode — used for typing text into the file.
- Command-line mode — used for saving, quitting, and running commands (entered from Normal mode using :).
Let’s break that down.
Editing Text (Insert Mode)
When you first open Vim, you can’t immediately start typing text — you’re in Normal mode. To start editing, press:
- i → Insert mode (insert before cursor)
- a → append (insert after cursor)
- o → open a new line below and start typing
You’ll notice — INSERT — at the bottom of the screen — that’s your cue.
Now you can type normally, just like in any text editor.
When done editing, press:
Esc to return to Normal mode.
Saving and Exiting Vim
Once you’re back in Normal mode, you can type commands by first pressing : to enter Command-line mode.
Here are the most important commands you’ll need:
| Action | Command | Description |
| -------------------- | ---------------- | --------------------------------------------- |
| Save (write) changes | :w | Writes file to disk |
| Quit (exit Vim) | :q | Quits the editor (only if no unsaved changes) |
| Save and quit | :wq | Writes file and exits (most common) |
| Quit without saving | :q! | Forces exit and discards unsaved changes |
| Save as new file | :w newfile.txt | Writes content to a new file |
So, a typical workflow might look like this:
-
Open file: vim config.properties
-
Press i to enter Insert mode and make changes.
-
Press Esc to return to Normal mode.
-
Type :wq and hit Enter to save and exit.
If You Ever Get Stuck in Vim…
If you’re not sure what mode you’re in — press Esc a few times to ensure you’re in Normal mode, then type:
:q!
and hit Enter to force quit.
This is the “panic escape” that every developer learns early on 😄.
Quick Navigation Tips
A few normal-mode commands you’ll use often:
- h, j, k, l — move left, down, up, right
- dd — delete the current line
- u — undo last change
- /text — search for “text” in the file
- n — move to the next search match
- gg — go to top of file
- G — go to bottom
You don’t have to memorize them all right away — just knowing how to enter, edit, save, and exit is 90% of the battle.
Why Java Developers Should Know Vim
Even though you’ll likely use IntelliJ IDEA or VS Code for everyday work, Vim skills come in handy when:
- Editing configuration files (application.properties, nginx.conf, etc.) on remote servers.
- Quickly checking logs in /var/log folders.
- Debugging CI/CD pipelines where you can only open files via SSH.
- Writing small scripts directly on a Linux machine.
In short: Vim is your terminal-side safety net. If you know just a few commands, you’ll never feel trapped again.
Vim Quick Guide
Here’s a short checklist to remember:
vim filename.txt # open file
i # enter Insert mode to start editing
<Esc> # return to Normal mode
:wq # save and exit
:q! # exit without saving
Conclusion
Shell commands might feel intimidating at first, but start small — list files, check logs, move things around. Soon you’ll wonder how you ever worked without them.
To recap, you now know how to:
- Navigate your filesystem and manage files.
- Read, search, and analyze logs.
- Control permissions and environment variables.
- Run and monitor your Java processes.
Remember: your IDE is powerful, but your terminal is limitless.
Happy Learning!!
메타데이터
- post_id
- 2e312f0c5720
- slug
- essential-shell-commands-every-java-developer-should-know-2e312f0c5720
- url
- https://medium.com/@bectorhimanshu/essential-shell-commands-every-java-developer-should-know-2e312f0c5720
- canonical_url
- https://medium.com/@bectorhimanshu/essential-shell-commands-every-java-developer-should-know-2e312f0c5720
- author_url
- https://medium.com/@bectorhimanshu
- status
- ok
- fetched_at
- 2026-08-25 06:45:45