Previously, I’ve talked about the power of Linux. The most widely used open source operating system.
We’ve discussed the benefits for the Linux command line interface (CLI) as well as the Windows CLI and some of the important commands to know.
Let’s go over just some of the use cases that Linux is great for.
You are able to filter and manipulate data in real-time, simply by stringing a few simple commands together. Having these capabilities natively, without having to install any additional tools.
Use Cases
One of the most powerful features of the Linux CLI is the ability to chain commands together using pipes "|". Allowing you to connect multiple commands together and use the output of one command as the input for another.
Let’s go over an example
find . -type f -name "*.gz" | strings -f --print-file-name | xargs zgrep "209.85.232.127"
This command will list all files ending with ".gz" as the extension in a detailed format. This combines the output of find and strings, with zgrep.
Another feature is the use of redirection operators ">" and ">>". These operators allow you to redirect and append output to a file respectively.
For example command echo "1, 2, 3" >> filelist.txt
, which will append the text “1, 2, 3” to the file filelist.txt.
There’s also the ; operator, which is used to separate commands. Think of it as a stage manager, letting you run multiple commands in sequence.
For example, echo "a test"; sleep 5 ; echo "a test". This will run the first echo command, sleep for 5 seconds, then run the final echo command.
Regex
Regular expressions with grep is another powerful feature that can be used to search for patterns in text.
For example, take the command
grep -E "^[A-Z]" file.txt
This will search for any lines in "file.txt" that start with an uppercase letter.
The following command
grep -E "^[aA-zZ]"
will look for any alphabetical letters, this time case-insensitive.
Regex101 is a good site to test any regex pattern.
In a future post, we will do a deep dive on regex, and how you can leverage the tool.
Manage System Services Using Cron
Another use case for the command line is to manage system services using cron.
Cron allows you to schedule commands or scripts to run at certain intervals, such as once per day, once per week, or once per month.
You can specify the time in the future, or the current time to repeat the action at that time. For example, you can run0 8 * * 1 tar -zcf /var/backups/home.tgz /home/
This would run a backup in the form of a tarball at 8:00 UTC every Monday.
On top of this, you can run the command line that uses cron from a script or from a script in your automation workflow.
To test different times for your cron scheduling, check out the following site.
https://crontab.guru/#0_8_*_*_1
Computing
Another use case Linux (the biggest) is used for is computing. This is one that maybe the every day user doesn’t realize, but most apps we use on a daily basis run on Linux. (That app you’re scrolling through at night 😂, it runs on Linux).
As explained in this blog post by the Linux Foundation, over 90% of public cloud instances are running on Linux. This is because this infrastructure is better suited for massive computation. And these social apps require that computation.
On the job for any Cybersecurity, DevOps or Engineering related roles, you will be working with more Linux servers than anything else.
Free Course
These are just some of the many powerful abilities of the Linux operating system to discover.
I have a free course available that goes over the fundamentals of Linux. It goes over fundamental commands, security, and where to go for help on commands all from the command line.
Check it out here.
Feel free to provide feedback, as I’m always looking to improve and iterate.
Linux will probably come up in an interview round, since it is generally the OS of Cybersecurity and Cloud Computing. Knowing the fundamentals will be a difference maker.