Little Known Useful Linux Commands


What Are Some Basic Linux Commands?

In order to start using the Linux command line, you need to open something called a “terminal” application. It’s like a special program where you can type commands to control your computer. If you’re using a Linux computer, you can usually find the terminal by searching for “Terminal” in your apps menu. For Mac computers, you can find it in a folder called “Utilities” within your “Applications.” If you’re on a Windows computer, you might need to use a special program like “Git Bash” to get a similar experience. Once you open the terminal, you’ll see a blinking cursor, and that’s where you can type your commands. Just type a command and press Enter to make your computer do what you want. It might seem a bit strange at first, but it’s a really powerful way to control your computer once you get the hang of it!

MacOS command line terminal

Example MacOS command line terminal

Kali Linux command line terminal

Example Kali Linux command line terminal

The below table contains a list of linux terminal (also called a CLI or shell) commands that are common across most distribution of Linux such as Ubuntu, Kali, CentOS, Mint, and Debian. As always, be careful when running these shell commands, some commands can break your system if used incorrectly.

Table of basic linux commands that can be used with a command line interface (cli) or as part of a bash script.

Little Known, but Useful Linux Commands

Through my years of Linux system administration I have gathered several useful linux commands I now use as everyday command line arguments. I have broken each set of command line arguments into categories where they are most useful. For example, those useful linux commands that help with command line arguments are in the Terminal Management Commands section.

Process Management Commands

Command 1: We all have been there; we run a command only to realize it is going to take forever and the terminal will probably timeout and kill the job before it finishes. The command below will exit the terminal without killing your long running command.

disown -a && exit

Command 2: Okay, you have a lot of apps open on your computer, but you can’t find one in particular? That’s where pgrep comes in. It’s like a search tool for finding apps or processes running on your computer. You just tell pgrep the name of the app you’re looking for, and it will tell you if it’s running and give you its process ID number. It’s a quick and easy way to find running programs from the command line terminal. pgrep helps you quickly locate and manage processes without having to search through everything yourself.

#Add in the "-x" argument option ensure pgrep search for the whole word. I this case it will search for processes containing the whole #word firefox and nothing else.
pgrep -x firefox

#The next command below will find any process that contains the search term.
pgrep -f "chrome"

Terminal Management Commands

Command 1: I seriously love the next command! Alias is a command or collection of commands that can be executed by typing a few characters in the terminal. For example, let’s say you run a web server and frequently use a command (ls -l | grep php) to find all php files in directory.

#Find all php files in a directory
alias findphp='ls -l | grep php'

The great thing about the “alias” commands is you can make them permanent by adding them to your terminal profile. For most flavors of linux, add the “alias” command to the .bashrc or .bash_profile file in your home directory. Open the file using a text editor, add your alias command, save the changes, and then run source ~/.bashrc or source ~/.bash_profile to apply the changes immediately.

For MacOS create a zsh profile by issuing the command touch ~/.zshrc Then, using your favorite text such as nano or vim, edit the profile by typing in nano ~/.zshrc adding the below snippet to the text file that opens in the text editor. After you add the snippet, hit CTRL + O to save and CTRL + X to exit.

#Custom alias commands
alias findphp='ls -l | grep php'

Command 2: Re-run last command but as the root linux user. Use this command instead of pressing up and enter to execute the command. This linux command comes in handy when you need elevated (root) privileges on a long or complex command you ran previously without root permissions.

sudo !!

Command 3: Imagine you’re writing an essay, and you realize you made a mistake in one of the sentences you wrote earlier. You don’t want to rewrite the whole thing again, so you just want to fix that one jacked sentence. That’s kind of what the Linux command fc does.

When you use fc in the terminal, it opens up a text editor with your previously typed commands. You can then edit those commands just like you would edit text in a document. Once you’re done editing, you save and close the editor, and the changes you made to your commands are executed by the terminal.

#Use fc when you messed up a really long or complex command.

File and Text Manipulation

Command 1: This is a great command to combine multiple text files into a single file. Obviously, change the output directory after the “>” and the file extension you are looking for. The {} are important; without those the command will not loop through all the text files and combine them.

#Here are a couple of examples to use to test the command:
find . -name "*.txt" -exec echo {} +
find . -name "*.txt" -exec cat {} > "/Users/joeajim/Kali Shared/wordlists_combined.txt" \;

Command 2: Although not so much of a system administration command, rsync is still a useful linux command, important in helping maintain your computer file. Imagine you have two folders with lots of files and you want to make sure they’re exactly the same. rsync helps you do that! It’s like a super-smart copying machine that only copies the stuff that’s different between the folders. It’s really fast and saves a lot of time because it doesn’t waste time copying stuff that’s already the same. Plus, it can do this between two computers over the internet. If you want to keep your folders in sync without doing all the work yourself, rsync is where it is at!

#Command will copy all files from the source to the destination except for those files that end in ".log"
rsync -av --exclude='*.log' source/ destination/

#The rsync linux command below does a test of the file copy to determine the size and estimate how long the copy will take.
rsync -av --dry-run source/ destination/

Linux Resources

Share post:



More like this

What is the Dark Web and How Does it Work?

The internet is vast, a digital expanse that contains...

What is OPSEC? Operational Security Explained

What is OPSEC?What is the OPSEC Process?1. Identifying Critical...

Duper’s Delight: How to Tell If Someone is Lying

SummaryDuper’s Delight: Body Language of DeceptionWhat is Duper’s Delight?Psychological...

The Basics of Order Flow in Stock Trading

SummaryWhat is Order Flow in Stock Trading?The Basics of...