DEV Community

Cover image for Save your time, have these advanced Linux commands in your cheatsheet!
Sachin Jha
Sachin Jha

Posted on

Save your time, have these advanced Linux commands in your cheatsheet!

🐚 I describe Shell with words omnipresence or has ubiquity. Quick filtering or command chaining is like magic and gives us more powers, with Pipe ("|") and CLI utilities like sed, awk, grep, etc.

📓 Hence, if you are related to Linux and Server troubleshooting in any way, and that involves your day to day work. Here is some quick reference to command-line know-hows:

Note: This is Part 1, just a quick reference guide that I've had in my cheatsheet for server troubleshooting. The list I have is exhaustive, so I will keep things simple and continue to share insights in a phased-out manner.

---Super-powers with:
ps | SSH | Removing files | Grep | Find | Sudo | SSL


With curl's insecure option we can filter the output and get only the Server certificate information:

~ $ curl --insecure -v 2>&1 | \
> awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } \
>  /^\*/ { if (cert) print }'

* Server certificate:
*   subject: CN=*
*   start date: Mar 22 04:34:05 2020 GMT
*   expire date: Jun 20 04:34:05 2020 GMT
*   common name: *
*   issuer: CN=Let's Encrypt Authority X3,O=Let's Encrypt,C=US
* Connection #0 to host left intact

# ps(processes status)

Sort by the highest CPU utilization in ascending order:

~ $ ps -aux --sort -pcpu | less

Sort by the highest Memory utilization in ascending order:

~ $ ps -aux --sort -pmem | less

Print all processes running as Root:

~ $ ps -U root -u root

Show process tree of all PIDs:

~ $ ps auxwf

Show all process info and hierarchy:

~ $ ps -efH

Find top running processes by highest memory and CPU usage:

~ $ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head


~ $ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head


Generate generic ssh key pair:

~ $ ssh-keygen -q -t rsa -f ~/.ssh/<name> -N '' -C <name>

# Removing files

Remove files over 30 days old:

~ $ find . -mtime +30 | xargs rm -rf

Remove files older than 7 day starting with 'backup':

~ $ find . -type f -name "backup*" -mtime +7 -exec rm {} \;

# Grep

Look through all files in current dir for word “foo”:

~ $ grep -R "foo” .

View last ten lines of output:

~ $ grep -i -C 10 "invalid view source” /var/log/info.log

Display line number of message:

~ $ grep -n “pattern” <file>

# Find

Exclude directories in find:

~ $ find /tmp -not \( -path /tmp/dir -prune \) -type p -o -type b

# Sudo

To check sudo access for a user!

Method 1:

~ $ sudo -l -U sachcode 
User sachcode may run the following commands on host:
    (ALL) ALL

Method 2: Another way to find out if a user has sudo access is by checking if the said user is member of the sudo group.

~ $ groups sachcode
sachcode : sachcode wheel docker

Method 3: list all sudo users of your system

~ $ genet group sudo

Read more about me:
Reference on my website:

Top comments (4)

corentinbettiol profile image
Corentin Bettiol

Great article :)

For generating ssh key pair I use ed25519 algorithm, like this:

ssh-keygen -t ed25519 -C "user@email.ext"
Enter fullscreen mode Exit fullscreen mode


waylonwalker profile image
Waylon Walker

Such a great list of examples. Often these are far too basic or complicated. This is a very useful set of non-trivial examples.

aathith_r profile image

Remove files over 30 days old: from date of creation? or from date of last modified? Asking this because I can't find the file creation time for any of my files.

chathumal profile image
Chathumal Jayasinghe