LINUX COMMAND CHEAT SHEET
MOST USED LINUX COMMANDS LINUX FILE COMMANDS
pwd Displays the current working directory rm -r [directory_name] Remove a directory and files
path, starting from the root (/) recursively
cp -r [directory_name1] Used to copy a directory including
rm [file_name] To remove files you no longer need [directory_name2] all its content from a source
directory to the destination
directory.
Shows a file's contents one screen
less [filename] at a time Move file_name1 to file_name2
mv [file_name1] [file_name2]
Is used to change the current working
cd [directory] directory in Linux tail [file_name] Prints the last 10 lines from the file
ls To list files or directories in Linux Used to enlist the current directory
ls -a
including the hidden files
grep [PATTERN] [FILE] Used to search for a string of
characters in a specified file
cp [file_name1] [file_name2] Used to copy files or group of files
Used to enlist the current directory or directory
ls-a
including the hidden files
rm [file_name] Deletes a file
cp [file] [destination] Copying files from one location to
another pwd Displays the current working
directory path, starting from the
mv [file] [destination] Used to move files and directories root (/)
from one location to another
rmdir It removes an empty directory on
various operating systems
mkdir [directory] Allows users to create or make new
directories
mkdir [directory] Allows users to create or make new
directories
curl [options] [URL] A tool that enables data transfer
over various network protocols.
LINUX DIRECTORY NAVIGATION Supported protocols (HTTP,
HTTPS, SCP, SFTP, FTP)
cd - Controls to the previous directory level
diff [file_name_1] Is used to display the differences in
[file_name_2] the files by comparing the files line
Used to change directory to the home by line
cd or cd ~
directory
tar Used to compress a group of files
cd / Used to change directory to the root into an archive
directory
locate [file_name] Finds files in Linux using the file
cd... Used to move to the parent directory name
of current directory
cat [file1] [file2] It reads data from the file and
gives their content as output
cd Go directly to directory
[/path/to/directory] tar -cf Creates or extracts archived files
wget [URL] Used to download files from
the internet.
echo [text]>>[file_name] Used to display line of text/string
that are passed as an argument
mv [file name Used to move files and directories
/path/to/new/location from one location to another
tar -xvf [file_name] Used to compress a group of files
into an archive
-x includes the eXtended attributes
of the files (metadata)
-v is verbose mode
-f tells tar what file/archive you are
unarchiving
gpg [file_name.gpg] Encrypts the files securely
LINUX COMMAND CHEAT SHEET
LINUX SSH (LOGIN) LINUX FILE COMMANDS
ssh -i ~/.ssh/specific_ssh_fkey Distinguished other ssh key for ln -s
Creates a symbolic link to a file
connection /path/to/[file_name] [link_name]
ssh user@server -p other_port Operate a specific port declared touch [file_name] Used to create, change and
in sshd_config modify timestamps of a file
ssh [IP address] Connect to a host wc Used to find out number of lines,
word count, byte and characters
count in the files
ssh-copy-id hostname_or_IP Copy a unique key pair to server
gpg -c [file_name] Decrypts the files securely
ssh user@server Connect to a server (default port)
head [file_name] Allows you to easily get the top
lines from the specified file or the
ssh user@server [command to run] Run a command on a remote server standard input
ls To list files or directories in Linux
LINUX NETWORK DIAGNOSTICS COMMANDS
ifup [options] -a [device] Used to activate the specified
network interface
LINUX PIPES/REDIRECTION
hostname Used to obtain the DNS name and set
the system's hostname or NIS domain << Launch a file and and captures
name user input until EOF
traceroute [host] Perform traceroute to [host] > Represents output redirection
and redirects output to a file and
overwriting the file
ifdown [options] -a|[device] Disables a network interface
ex. A Linux pipe is a form of
hostname -l (capital ‘i’) Shows all IP addresses of computer command_1 | command_2 redirection used to combine two
| command_3 or more commands where the
output of one command acts as
netstat Displays information about different the input of the next command in
interface statistics,including open the sequence.
sockets, routing tables, and
connection information
>> Redirects output to a file and
appends the redirected
ifconfig/ip Used to configure, control the output rather than overwrites
queries from CLI and to enable or
disable the IP address, view all
network interfaces. Also to set up < Represents input redirection and
any/all the network interfaces such as redirects the given input file
Ethernet, wireless, modem and so on
that are connected to your computer
dig [record type] [domain] Gather information about a particular
domain. Try “dig txt google.com”
nettop Monitor network activity, showing a
list of processes and corresponding
process IDs with network
connections
ping [address] Send ICMP ECHO_REQUEST packets
to network host at [address]
nslookup [address] Use the IP address to discover a
domain name, or vice versa.
LINUX COMMAND CHEAT SHEET
USER CONTROLS AND MANAGEMENT USER WARNING: SOME OF
SYSTEM INFORMATION
THESE COMMANDS CAN BE DANGEROUS. USE WITH CAUTION.
cat /proc/cpuinfo Display detailed information about (sudo) service ssh stop Stop ssh service
the CPU
(sudo) service ssh start Start ssh service
pstree Display a tree of running processes
(sudo) service ssh restart Restart ssh service
du Return disk usage
(sudo) service ssh status Check ssh service status
df –m Display free storage in megabytes
sudo passwd root Set a new password for the
du –h [directory Return disk usage in a readable file root user, can be used to
size format Eg. 1.1K or 15M 1.5G circumvent the sudo
(-m shows file in megabytes and command
-g shows a file in gigabytes)
passwd Change your password
lshw | less List all hardware and pipes to the
less command for easy reading and
pagination useradd [user_name] Create a new user
swapon -s Swap information useradd –r [user_name] Delete a user
lsusb (or -v for verbose) Show information about all usb finger [username] Display information about a
devices. user
pmap –x PID [pid] Display memory information about a
chmod [permission] [file_name] Change the permissions of
process
a file
Eg. chmod 777 /path/to/file
lspci (or -v for verbose) Show information about all PCI
Display sorted information about groups [username] Display the groups a user
top belongs to
processes
sudo systemctl restart Restart a service chown user:group /path/to/file Change ownership of a file
[service_name] Eg. sudo systemctl restart apache2
chown –R user:group /path/to Change the ownership of
dmidecode | less Summarize BIOS information /directory a directory and files
chroot [path] [command] Change the root directory
kill [pid] Terminate a process. Use the ‘top’ of a process
command to find the pid of a
process
quit Logout
cat /etc/issue The cat command shows
information about a given directory w Display currently logged
, in this cat /ect/issue. in users
free Free shows system information
such as free memory and swap in
kibibytes
LINUX COMMAND CHEAT SHEET
OTHER
alias [new command name] Create a temporary alias for
=[command] a command
date Display current system date and
time
env Display environment variables
[tab] Autocomplete command you are
typing, if autocomplete has been
configured for your shell session.
history Display prior used commands
shutdown Turns a computer off
shutdown –r Reboots a computer
at [-V] [-q queue] [-f file] Run a command at a specific time
[-mldbv] TIME
iostat List CPU and I/O statistics
clear Clear all information from the
terminal window. Not useful for
security.
crontab –e Create a new crontab or edit an
existing crontab
man [command name] Display the manual or help file for a
command
unset [variable_name] Remove environment variable
export [variable_name]
Create a new environment variable
=[variable_value]
100% Linux Hands-on Exercise on Linuxpath.org
These Linux exercises from Linuxpath.org will help you learn everything about Linux from the boot process to advanced networking