Linux commands used in day-to-day life

Here are the top 10 Linux commands I use in my day-to-day activities as a DevOps engineer. These are super important for basic-level debugging.

Netstat

Used to check if an application is running on a particular port or not.

netstat -apn | grep <port-no>

a (All) - List both listening & non-listening ports.

p - Shows PID & name of process running.

n - Display numeric addresses.

Telnet

Used to check if 2 servers are connected or not on a particular port.

In our day-to-day life, we need to ssh into servers or scp some files/directories. So checking if the destination server can accept our connection at Port 22 is important.

telnet <Destination-IP> <Port-No>

ps

Used to check if a process is running on a machine or not. If, we need to check the Java application which is running on our machine, then -

ps -aux | grep java

a (All) - Select all processes.

u - Select by User ID, so this gives us the username in this this java application is running.

x - Prints the full username/group name, name not truncated.

curl

Curl (Client URL) allows data transfer over various network protocols.

A common use case of this command is to check if an application with its context is running or not on the machine.

curl -v http://localhost:<Port-No>/context

There are times when we set the health check path in our Load balancer's Target group, and we get 404, so to check it we can run this command.

mv

Very important, when we need to revert a delivery. First, rename the current jar, Check the latest available backup, and then move the old jar/ application from the backup folder to the application directory. Restart the application by either restarting the service file or killing the process & running the jar.

mv app.jar app_bkp.jar
ls -lhrt backup/
mv backup/app_bkp_2023_08_15.jar app.jar

ll

On most Linux systems, these days, ll is aliased as ls -l for our convenience.

Used to get a list of files & directories in the current directory.

ll

Also, these can be used to get a list of users we have in our system.

ll /home

Also, there's

ls -lhrt

To get the most recent files & directories easily.

cd

To change the current working directory.

cd /home/stalin/scripts

tail

Mostly used in log files, to view the current logs.

tail -f catalina.out

rm

Used to delete files & folders. It's a good practice to check the file/directory name, & its path before you execute this command.

rm <file-name>
rm -r <directory-name>

The above command will ask for your consent, if that particular directory has contents in it, to delete it forcefully,

rm -rf <file-name>

systemctl

In Linux, a service is a process running in the background. So to keep the process running, we use it rather than manually running the application. When we restart the service file, it handles both killing the process started by it, & starting the process again.

systemctl status app.service
systemctl restart app.service