Linux Command Cheat Sheet, Ubuntu, CentOS – GitHub Gist

open terminal

: Ctrl + Alt + T Ctrl + C is used to kill a process with

SIGINT signal, in other words, it is a polite assassination. Ctrl +

Z is used to suspend a process

by sending it the SIGTSTP signal, which is like a sleep signal, which can be undone and the process can be resumed again

. Ctrl+

D: Close the current session, similar to exiting.

History | grep “command looking”


    R: Type to display a recent command

  • !! – repeat the last command

  • Exit – Log out Current

  • fg in foreground or bg in background

  • Ctrl+W – clears

  • one word on the current

  • line

  • Ctrl+U – clears the entire line

  • Change password

  • for

  • user passwd user sudo groupadd ic-api sudo usermod -g ic-api



Search find

. -type f -name “*.conf”



grep -lr ‘gceu’ .

grep pattern dir – Pattern search in dir.


The –

l (or -files-with-matches) option is used only to print matching file names, and not matching lines (this could also improve speed, since grep stops reading a file at first matches this option).

r recursive

i ignore-case –

include search

only for files that match the

grep file pattern -ril -include *.py -include *.html command “.id” | grep pattern –

  • find pattern in command output

More about regex.

Grep OR

7 Linux Grep OR, Grep AND, Grep NOT Operator Examples

grep ‘pattern1|pattern2’ filename grep -E ‘pattern1|pattern2’ filename

Grep before after grep

-B 4 -A 4 Find

all file instances

Locate file cal –

    show calendar

  • this month Uptime
  • – Show

  • current uptime
  • W – Show

  • who’s online
  • Whoami – Who is logged in as
  • a finger user –

  • Show information about the user
  • htop – a lightweight process viewer in text mode packed with useful features like killing processes without entering their PID, displaying complete command lines, etc. with a color display

Operating system version



information uname -a


lsb_release -a



CPU information

cat /proc/cpuinfo

Show only the number of cores

grep -c ^processor /proc/cpuinfo


of memory cat /proc/meminfo Show

memory and swap usage, display output in gigabytes.

Free -g

Date Time

Display the current date and time,

in the format of: date+”T”+hour+minute+second+UTC time zone offset $ date

+”%FT%H%M%S%z” 2019-02-19T104943+1100


df -h

Show disk usage with a human-readable drive.

du -h -max-depth=1

displays directory space usage, just one level deep.


ip a

One-line command to simply grep the ip: ip

a | GREP “Global Reach” | grep -Po ‘(?<=inet )[d.] +’

For older versions of centOS:

ifconfig | Grep “Inet” | grep -v | awk ‘{print $2}’

CentOS older

netstat – Print network connections, routing tables, interface statistics, masking connections, and multicast memberships

a, -all Show listening and non-listening sockets (for TCP this means established connections). Using the -interfaces option, display interfaces that are not active

-numeric ,

-n Show numeric addresses instead of trying to determine symbolic host, port, or user names

. –

p, -program Displays the PID and the name of the program to which each socket belongs.

netstat -ANP | grep :8

CentOS 7 Netstat, which is part of the net-tools package, has officially been deprecated, so you should use SS (part of the iproute2 package), in the future. ss –

anp | grep :8443

ss -lnpt ‘sport = :3000’ -l, -listening Show only listening sockets

(ignored by default).

-n, –

numeric Do not attempt to resolve service names

. -p, -processes Show process using socket. –

t, -tcp Show TCP sockets


journalctl -u nginx.service

from today

Ubuntu document

Prints the names and

values of all currently defined environment variables printenv

Examine the value of a particular variable

printenv DBPASS


echo $ TERM



The dollar sign $ can be used to combine the values of environment variables into many shell commands. For example, the following command can be used to enumerate the contents of the “Desktop” directory within the current user’s home directory.

ls $HOME/


environment variables

Add var to this file:

sudo -H nano /etc/environment

It is important to do it exactly the way above, and not as a root user, as it can cause problems like not being able to log in. If you use normal sudo to launch graphical applications (including editors, for example, gedit), sometimes you make configuration files owned by root, read more about this here.

The only time the file is read

is at login, when the PAM stack is activated, specifically, which reads the file


Logging out and logging back in would apply the changes, and indeed you must if you want all your processes to receive the new environment. All other solutions will only apply the environment to the single shell process, but not to anything that boots through the GUI, including new terminal windows.

Which application

shows which application will run by default

man command display

the manual for the whereis app command

– show

  • possible locations of the
  • miranda-zhang

/ application

dir dir – change directory to dir

  • cd – switch to start
  • pwd – show
  • current directory mkdir dir – create a
  • dir rm directory

  • file – delete rm -r dir file – delete

  • dir
  • directory rm

  • -f
  • file – force delete rm -rf dir file –

  • force delete dir directory *
  • cp1 file2 – copy file1 to file2 cp -r dir1 dir2 – copy dir1 to dir2

  • ; create dir2 if mv1 file does not exist
  • file2

  • – rename or move file1 to file2 If File2 is an existing directory, moves File1 to the Contact File2 directory
  • File:

  • Create or update
  • file

  • File > Cat: Places the standard input in
  • the file More File

  • : generates
  • the contents of the file

  • HEAD
  • file – output of the first 10 lines of file tail file – output of the last 10 lines of file

  • tail -f file – output of file contents as it grows, starting with the last 10 lines
  • GUI file manager xdg-open


Directory listing:

show hidden files with-a,

show details with -l ls –

al Determine the file type,

i.e. check if something is a symbolic link.


Counting files in the current directory

ls -1 | wc -l

This uses wc to count the number of lines (-l) in the output of ls –


  • Chmod file permissions OCTAL file – change file permissions to octal, which can be found separately for user
  • , group, and world by adding: 4 – read (r)

  • 2
  • – write (w) 1 – run

  • (x)


  • chmod 777 – read, write, run for all Chmod
  • 755 – RWX for owner, RX for group and world


tar CF compression.tar files: create a file named tar.tar containing tar xf file.tar – extract files from the archive.tar tar czf file.tar.gz files – create a tar with compression Gzip tar file XZF.tar.gz – extract a tar using Gzip tar cjf file.tar.bz2 – create a tar

    with Bzip2 compression tar

  • xjf file.tar.bz2 – extract a tar using Bzip2
  • gzip
  • file

  • – compresses
  • the file and renames it to
  • file.gz gzip -d file.gz –

  • unzip file.gz back to top of file

– show all running processes kill pid – kill process id

  • id killall
  • proc –

  • kill all processes named proc *
  • bg – lists stopped or background jobs; Resume a stopped job in the background
  • FG:

  • foregrounds
  • the latest job FG N: Brings the job n to the foreground

ps Show

currently active processes


Show the complete command, including arguments.



-p [PID] -o args ping host –

  • ping host and
  • whois

  • output results
  • domain – get whois information for domain dig domain –

  • get DNS information for domain dig
  • -x host –

  • reverse lookup host
  • – wget file – download file

  • wget
  • c file – continue a stopped download


dpkg -i pkg.deb


rpm -Uvh pkg.rpm


yum install pkg Ubuntu apt update apt

upgrade apt install pkg

Node.js, Javascript npm install package manager

Install from source:

  • ./configure
  • make

  • make


Possible log location

/var/log/audit/audit /audit.log grep “denied” /var/log/audit



Graph with gnuplot interactively: apt update apt install gnuplot-x11


Create symbolic link to

ln -s file source_file

Sin -s link, then create a hard link.

Contact US