DEV Community

Erika Heidi
Erika Heidi

Posted on

Linux Essentials: The Singular Six

If you had to choose the most essential Linux commands to troubleshoot servers, those you really can't live without, what would that list look like to you?

I came down to six essentials that are super important to locate and identify issues within Linux servers (not considering text editors or network commands). Meet the Singular Six!

Linux's Singular Six

My list includes:

  • ls
  • ps
  • cat
  • tail
  • kill
  • rm

These are like the basic toolchain for dealing with Linux servers, and I can't think of anything more essential than these six commands. Let's have a quick recap of each one of them, just in case.

LS

This one just had to be on the list (pun intended). The ls command is used to list files from a location. If you don't provide a directory to list, it will list the files from your current directory.

Usage Examples for the ls Command

Lists all files from the current directory, including hidden files:

ls -la
Enter fullscreen mode Exit fullscreen mode

Lists all files from a directory:

ls /var/log
Enter fullscreen mode Exit fullscreen mode

PS

The ps command is used to list processes that are currently running on the system.

Usage Examples for the ps Command

Shows current active processes initiated by the logged user:

ps ux
Enter fullscreen mode Exit fullscreen mode

Shows current active processes from all users:

ps aux
Enter fullscreen mode Exit fullscreen mode

CAT

The cat command is used to output the full contents of a file. Many people don't know that you can also use cat as an improptu editor to create or update text files.

Usage Examples for the cat Command

Outputs content from a file named file.txt in the current directory:

cat file.txt
Enter fullscreen mode Exit fullscreen mode

Redirects content from the standard input to a file, until an EOF is entered:

cat > test.txt << EOF
heredoc> line1
heredoc> line2
heredoc> line3
heredoc> EOF
Enter fullscreen mode Exit fullscreen mode

If you run a cat test.txt now, you'll get the following output:

line1
line2
line3
Enter fullscreen mode Exit fullscreen mode

TAIL

The tail command is used to output only the final portion of a file, which makes it great for checking system logs. By default, it will output the last 10 lines of a file.

Usage Examples for the tail Command

Show the lasts 10 lines of a file:

tail /var/log/nginx/error.log
Enter fullscreen mode Exit fullscreen mode

Shows the last 40 lines of a file:

tail -n 40 /var/log/nginx/error.log
Enter fullscreen mode Exit fullscreen mode

Outputs new log lines in real time (blocks terminal - hit CTRL+C to exit):

tail -f /var/log/nginx/error.log
Enter fullscreen mode Exit fullscreen mode

KILL

The kill command is used to terminate processes that are currently running on the server.

Usage Examples for the kill Command

Kills a process using a PID (process ID can be obtained with ps):

kill -9 1234
Enter fullscreen mode Exit fullscreen mode

Kills all processes with a certain name:

killall -9 name
Enter fullscreen mode Exit fullscreen mode

RM

The rm command is used to permanently delete files on a server.

Usage Examples for the rm Command

Recursively removes all files from a certain location (includes directories):

rm -r location/
Enter fullscreen mode Exit fullscreen mode

Recursively removes files from a location, but asks for confirmation (interactive) before removing:

rm -ri location/
Enter fullscreen mode Exit fullscreen mode

Recursively removes all files from a location, won't ask for confirmation (force) and shows files being removed (verbose):

rm -rfv location/
Enter fullscreen mode Exit fullscreen mode

Be careful with this one, because it won't give you a second chance to avoid removing important files (just make sure you're passing in the correct directory to be removed).

It's Your Turn

Now, I want to know: what is in your top six?

Top comments (14)

Collapse
 
muneersyed156 profile image
Mohammad Muneer Syed
awk, top, free, du, df, sed
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ghost profile image
Ghost

First of all I would cheat, and put

1) htop, with it you can check resources, you'll need something to see if RAM or CPU is being hammered, and is a cheat because you can also kill and a basic ps functionality :)

well could be glances, you get extra info but you lose renice and kill

2) not really cheating but I would add cat, with it you can read a file, like tail but the whole thing and you can write on it (or Vim? could it be Vim? or better neovim?).

cp, ls and rm are unavoidable I think (unless you really cheat) but I also think that is you add them you have to add cd and sudo which is excesive

3) man should definetely be in the list

4) something for networking, nmap, ip or tcpdump? maybe?

5) df

6) mpv, you can't fix a computer without proper music, that's nonsense. unless is remote, in that case ssh and listen music in your phone (that's cheating too).

Collapse
 
endy_tj profile image
Endy Tjahjono

Six would be too few haha
ls, cd, cp, mv, rm, ssh, scp, sudo, grep, less, cat, tail, vim.

Collapse
 
ibrahimcesar profile image
Ibrahim Cesar

Well, you can’t go anywhere without cd

Collapse
 
joshdaone profile image
Joshua Tu

Great illustration!
cd, cp, chmod, chown, netstat, curl, wget, and most important, nano. XD

Collapse
 
robkenis profile image
Rob Kenis

You misspelled vim :)

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

Whoa, don't "kill -9" unless you have to. Try "kill" (without "-9") first, to let the process shutdown gracefully.

Collapse
 
chris_beef profile image
Chris B

Very good. Also df-h to check the disk space in case run out!

Collapse
 
rafaelcg profile image
Rafael Corrêa Gomes

Excellent, thank you for sharing Erika!

Collapse
 
t04glovern profile image
Nathan Glover

That artwork is AMAZING 👏
My picks are too dissimilar either.

Collapse
 
erikaheidi profile image
Erika Heidi

Thank you! 😊❤️

Collapse
 
adityamitra profile image
Aditya Mitra

Someone asked me this:

How can we change the document root of apache webserver to /web directory?

Collapse
 
scriptmunkee profile image
Ken Simeon • Edited

Edit your httpd.conf file located in either /etc/httpd/ or /etc/httpd/conf/ and change the ServerRoot path to your desired destination. Or you can create a non standard file path using the <Directory /> or <VirtualHost />.

See the Apache web server documentation. httpd.apache.org/docs/2.4/>

Collapse
 
erikaheidi profile image
Erika Heidi

Yes! What Ken said. If you would like to create a virtual host instead, I'd recommend this tutorial: digitalocean.com/community/tutoria...