Main Linux Commands Cheat Sheet
Main Linux Commands Cheat Sheet
Getting around
Command
Descrip/on
Tip
–
Tab
Comple/on
cd logs Move
to
the
logs
directory,
which
is
located
in
the
current
directory.
Use
tab
comple/on
to
type
filenames
faster.
cd /logs Move
to
the
logs
directory,
which
is
located
in
the
top-‐level
directory.
As
you’re
typing
a
filename
(or
directory),
hit
the
tab
key.
If
cd .. Move
up
one
directory.
there’s
only
one
file
that
matches
what
you’ve
typed,
the
cd ~ Move
to
your
home
directory
(the
“:lde”
character
is
le<
of
the
1
key).
rest
of
the
filename
will
be
filled
in.
If
nothing
happens
when
cd - Move
to
the
directory
you
were
previously
in.
you
hit
tab,
simply
hit
tab
again
to
see
a
list
of
matches.
Tip
–
Compressed
Files
Tip
–
Documenta/on
Tip
–
Working
With
Big
Files
Files
that
end
in
.gz
are
compressed,
and
Linux
commands
are
all
well
Commands
take
longer
to
run
on
larger
might
require
some
different
commands:
documented.
To
view
the
files.
Some
things
to
keep
in
mind
are:
documenta:on:
• Use
grep
–F
instead
of
plain
grep.
Command
Modifica/on
for
.gz
• For
viewing
the
file,
use
less
instead
of
cat.
• Run
the
command
with
-‐-‐help
(e.g.
tail
cat
or
grep
Use
zcat
or
zgrep.
-‐-‐help)
to
see
the
op:ons.
• Try
to
use
grep
as
early
as
possible,
so
if
• Use
the
manual
pages
for
more
detail
you
pipe
to
other
tools,
there’s
less
data
to
head
or
tail
Use
zcat
|
head
or
zcat
|
tail
(e.g.
man
tail).
Note:
these
open
in
less.
crunch.
In
order
to
promote
its
wide
distribu:on,
this
work
is
licensed
under
the
Crea:ve
Commons
Abribu:on-‐NonCommercial-‐ShareAlike
4.0
Interna:onal
License
(hbp://
crea:vecommons.org/licenses/by-‐nc-‐sa/4.0/).
We
at
Broala
are
commibed
to
helping
you
understand
Bro
to
the
fullest
so
you
can
be
a
monitoring
hero.
©
Broala
LLC.
78
65
Basic Linux Commands
SYSTEM
uname -a =>Displaylinux system information NETWORK
uname -r =>Display kernel release information ip addr show =>Display all network interfaces and ip address
uptime =>Show how long the system has been running + load ip address add 192.168.0.1 dev eth0 =>Set ip address
hostname =>Show system host name ethtool eth0 =>Linux tool to show ethernet status
hostname -i =>Display the IP address of the host mii-tool eth0 =>Linux tool to show ethernet status
last reboot =>Show system reboot history ping host =>Send echo request to test connection
date =>Show the current date and time whois domain =>Get who is information for domain
cal =>Show this month calendar dig domain =>Get DNS information for domain
w =>Display who is online dig -x host =>Reverse lookup host
whoami =>Who you are logged in as host google.com =>Lookup DNS ip address for the name
finger user =>Display information about user hostname –i =>Lookup local ip address
HARDWARE wget file =>Download file
dmesg =>Detected hardware and boot messages netstat -tupl =>Listing all active listening ports
cat /proc/cpuinfo =>CPU model COMPRESSION / ARCHIVES
cat /proc/meminfo =>Hardware memory tar cf home.tar home =>Create tar named home.tar containing home/
cat /proc/interrupts =>Lists the number of interrupts per CPU per I/O device tar xf file.tar =>Extract the files from file.tar
lshw =>Displays information on hardware configuration of tar czf file.tar.gz files =>Create a tar with gzip compression
the system gzip file =>Compress file and renames it to file.gz
lsblk =>Displays block device related information in Linux INSTALL PACKAGE
free -m =>Used and free memory (-m for MB) rpm -i pkgname.rpm =>Install rpm based package
lspci -tv =>Show PCI devices rpm -e pkgname =>Remove package
lsusb -tv =>Show USB devices INSTALL FROM SOURCE
dmidecode =>Show hardware info from the BIOS ./configure
hdparm -i /dev/sda =>Show info about disk sda make
hdparm -tT /dev/sda =>Do a read speed test on disk sda make install
badblocks -s /dev/sda =>Test for unreadable blocks on disk sda SEARCH
USERS grep pattern files =>Search for pattern in files
id =>Show the active user id with login and group grep -r pattern dir =>Search recursively for pattern in dir
last =>Show last logins on the system locate file =>Find all instances of file
who =>Show who is logged on the system find /home/tom -name 'index*' =>Find files names that start with "index"
groupadd admin =>Add group "admin" find /home -size +10000k =>Find files larger than 10000k in /home
useradd -c "Sam" =>g admin -m sam #Create user "sam" LOGIN (SSH AND TELNET)
userdel sam =>Delete user sam ssh user@host =>Connect to host as user
adduser sam =>Add user "sam" ssh -p port user@host =>Connect to host using specific port
usermod =>Modify user information telnet host =>Connect to the system using telnet port
chgrp => Changes a users group FILE TRANSFER
FILE COMMANDS sftp 192.16875.2 =>Connect remote host
ls –al =>Display all information about files/ directories scp
pwd =>Show the path of current directory scp file.txt server2:/tmp =>Secure copy file.txt to remote host /tmp
mkdir directory-name =>Create a directory folder
rm file-name =>Delete file rsync
rm -r directory-nam =>Delete directory recursively rsync -a /home/apps /backup/ =>Synchronize source to destination
rm -f file-name =>Forcefully remove file DISK USAGE
rm -rf directory-name =>Forcefully remove directory recursively df –h =>Show free space on mounted filesystems
cp file1 file2 =>Copy file1 to file2 df -i =>Show free inodes on mounted filesystems
cp -r dir1 dir2 =>Copy dir1 to dir2, create dir2 if it doesn’t exist fdisk -l =>Show disks partitions sizes and types
mv file1 file2 =>Rename source to dest / move source to directory du -ah =>Display disk usage in human readable form
ln –s /path/to/file-name link-name #Create symbolic link to file-name du -sh =>Display total disk usage on the current directory
touch file =>Create or update file findmnt =>Displays target mount point for all filesystem
cat > file =>Place standard input into file mount device-path mount-point =>Mount a device
more file =>Output contents of file DIRECTORY TRAVERSE
head file =>Output first 10 lines of file cd .. =>To go up one level of the directory tree
tail file =>Output last 10 lines of file cd =>Go to $HOME directory
tail -f file =>Output contents of file as it grows starting with the cd /test =>Change to /test directory
last 10 lines
gpg -c file =>Encrypt file
gpg file.gpg =>Decrypt file
wc =>print the number of bytes, words, and lines in files
xargs =>Execute command lines from standard input
PROCESS RELATED
ps =>Display your currently active processes
ps aux | grep 'telnet' =>Find all process id related to telnet process
pmap =>Memory map of process
top =>Display all running processes
kill pid =>Kill process with mentioned pid id
killall proc =>Kill all processes named proc
pkill process-name =>Send signal to a process with its name
bg =>Resumes suspended jobs without bringing them to
foreground
fg =>Brings the most recent job to foreground
fg n =>Brings job n to the foreground
79
66