Save your time, have these 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.

๐Ÿ’ก Command-line | Part 1

ps | SSH | Removing files | Grep | Find | Sudo | SSL

Quick reference: PS | SSH | Removing files | Grep | Find | Sudo | SSL

# ps(processes status)

  1. Print All Processes Running as Root

    ps -U root -u root
  2. Show process tree of all PIDs

    ps auxwf
  3. Show all process info and hierarchy

    ps -efH
  4. Sort by the highest CPU utilization in ascending order

    ps -aux --sort -pcpu | less
  5. Sort by the highest Memory utilization in ascending order

    ps -aux --sort -pmem | less
  6. Find top running processes by highest memory and CPU usage in Linux

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


    ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
  7. Sort by memory | CPU and display only the top ten of the result

    ps -aux --sort -pcpu,+pmem | head -n 10


Generate generic ssh key pair

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

# Removing files

  1. Remove files over 30 days old

    find . -mtime +30 | xargs rm -rf
  2. Remove files older than 7 day starting with โ€˜backupโ€™

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

# Grep

  1. Look through all files in current dir for word โ€œfooโ€

    grep -R "fooโ€ .
  2. View last ten lines of output

    grep -i -C 10 "invalid view sourceโ€ /var/log/info.log
  3. 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!

  1. Method 1:

    sudo -l -U sachcode 
    User sachcode may run the following commands on host:(ALL) ALL
  2. 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
  3. Method 3: list all sudo users of your system

    genet group sudo


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



devtolinux You can read this on as well!

Written by@[Sachin Jha]
An old-school guy seeking new adventures :) When Iโ€™m not building cloud solutions @DigitalOcean, you can find me exploring the mountains. I love spending time outdoors. Iโ€™m a photographer and high altitude trekker.