Common Linux Commands
As we all know, Java is a platform-independent language and that means it can be run on any OS that supports JVM. However, Java web applications are usually deployed to Linux server because it is free and open source. Also the web applications can be easily administered by the Linux command line via SSH. Therefore, as a Java Developer or Programmer, you should definitely familiar with the basic Linux commands. In this article, I have summarized some common Linux commands, including few examples and short explanations.
pwd #
The pwd (print working directory) command displays the full path name of your current working directory to the standard output.
pwd
/root
- Display the full path name of your current working directory
- Output from command (1)
cd #
This command is used to change the current working directory.
cd /
cd /root
cd ..
- To change into the root directory
- To change into the /root directory
- To change into the parent directory
ls #
This command displays the contents of a directory.
ls
ls -a
ll
ls -ltr
- Display contents of current working directory
- Display contents of current working directory in long listing format
- Equivalent to command (2)
- Display contents of current working directory in long listing format (
-l
) and sort by time (-t
) in reverse order (-r
)
chmod #
This command allows you to modify the permissions on a file or directory.
chmod +x start.sh
- Grant execute permission to a shell script (run the script using
./start.sh
)
cat #
This command displays the contents of a file.
cat README.md
- View the README.md file in Linux Terminal
cp #
This command is used to copy files or directories.
cp README.md README.md.bak
cp -p README.md README.md.bak
- Copy the README.md file to a file named README.md.bak (backup)
- Similar to command (1) except preserving the attributes such as permissions, ownership and timestamps of the README.md file
mv #
This command is used to move and rename files and directories.
mv README.md.bak README.md
mv /root/filename.txt /var/log/newfile.txt
- Rename the README.md.bak file to README.md (rollback)
- Move the filename.txt from /root directory to /var/log directory and rename it to newfile.txt
mkdir #
This command is used to create directories.
mkdir log
- Create a directory named log
less #
This command is a Linux program that can be used to view the contents of a file one page at a time. Some keyboard shortcuts are shown below and they are case-sensitive.
less catalina.out
- q quit less
- g go to the first page
- G go to the last page
- /word search forward for the "word" string
- n go to the next occurrence
- N go to the previous occurrence
- d go down a half-page
- u go up a half-page
- To view the content of a file with
less
vim #
This command is used to edit a text file with Vim editor.
vim web.xml
- i enter insert mode
- esc quit insert mode
- :q! quit vim without saving changes
- :wq quit vim and save changes
- dd delete current line
- To open a web.xml file in Vim editor
rm #
This command is used to remove files or directories.
rm example.log
rm -r tmp
- Remove the example.log file
- Remove the directory
tmp
recursively (BE CAREFUL!)
grep #
This command is used to search text and strings in a given file.
grep Exception catalina.out
ps aux | grep java
- Search any line that contains the word
Exception
in catalina.out - List any java processes
ln #
This command creates link between files.
ln -s /root/home/apache-tomcat-10.0.10 tomcat10
- Create a symbolic link (shortcut) to a tomcat installation directory
tail #
This command is used to display the last part of files.
tail -f catalina.out
- Monitor the catalina.out file in realtime
ps #
The ps command stands for process status which is used to display information about your running processes.
ps aux
- Show all processes for all users in user-oriented format
top #
The top program provides a dynamic real-time view of running processes on your computer.
top
- Display running processes
- Previous: Common Git Commands
- Next: Shell Script Examples