DEV Community

John Au-Yeung
John Au-Yeung

Posted on • Originally published at thewebdev.info

Essential Linux Command Line Programs

Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62

Subscribe to my email list now at http://jauyeung.net/subscribe/

If we work as developers, we have to work with the Linux command line eventually.

In this article, we’ll look at some basic Linux programs we should know to work with the Linux command line.

curl

curl lets us make HTTP requests to a server a get a request back.

We can use it to specify the headers and body of the request in addition to any cookies.

python -m json.tool / jq

python -m json.tool and jq are 2 separate programs that we can use to pretty-print JSON so that we can read them easily.

They all work after the pipe. For instance, we can run both as follows assuming test.json has JSON text in it:

cat test.json | jq
Enter fullscreen mode Exit fullscreen mode

or:

cat test.json | python -m json.tool
Enter fullscreen mode Exit fullscreen mode

ls

ls lists the files and directory in a directory.

Once we run this, we get the permissions of the files and folders and when they changed.

tail

tail shows us the end of a text file. As the text file updates with new content, it’ll show the latest and keep showing the end of the file if new things are added if we add the -f option

cat

cat is used to concatenate and print files on the screen. We just add the paths that we want to the end of the list and the content of all the files will be concatenated one after the other on the screen.

grep

grep lets us search for patterns from the output of another command.

This is very handy for searching for data from any large blocks of text.

ps

ps shows the status of the running processed in our computer.

The date, process ID, and time are all included.

env

env prints out environment variables. It’s useful if environment variables are added incorrectly.

top

top shows us the number of resources used by the currently running processes in our system.

netstat

netstat shows us the network status of our system. It shows us the ports that are used and the IP address they connected from.

Also, we can see the processes that are using network connections in one table.

ip address

The iproute2 package has the ip address programs that show us which interfaces are connected to which network.

lsof

The lsof package shows us the item that are listening for incoming data in our network.

it lists the ports that it’s listening to and the ID of the process that’s listening to a given port.

df

The df program shows us the free disk space that’s on our system.

We can see which volumes are full and which aren’t.

du

We can get more information our disk volumes than df with du .

The -h flag makes the output human-readable and -s shows the total size.

id

The id command returns the currently logged in user’s identify.

chmod

chmod is used to change the permissions of our files and directories.

This can help us fix permission errors when we encounter them.

dig / nslookup

dig and nslookup let us troubleshoot DNS errors. We can see whether we can resolve the some URL to their IP address with it.

Just put the URL we want to find the IP address after each and check the output.

iptables

iptables is used to block or allow traffic on a Linux system. It’s similar to a network firewall.

We can whitelist and blacklist by IP address with this package.

sestatus

We can check if we have SELinux enabled with this command. Then we can check if it’s enabled or not.

history

history shows us the commands that we’ve run recently. It’s easy to look at what we’ve run so we can run them again.

tar

tar can be used to created archives and uncompress them.

We create one by running tar cvf archive.tar /dirname to create an archive out of the /dirname directory.

The extract data from an archive, we run tar xvf archive.tar .

To view an archive, we run tar tvf archive.tar .

Conclusion

There’re many commands that we can use to do things on the Linux command.

Commands like curl and tar are important for making requests and extracting files.

There’re also packages that we can install like jq to pretty-print JSON.

And there’re many more that’ll come in handy for troubleshooting networks and processes.

Top comments (0)