Show Menu
Cheatography

Linux Command Sheet Cheat Sheet (DRAFT) by

Linux Command Frequently Used

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Inform­ation

pwd
| print working directory
cat
| print file [on screen]
hostname
| display hostname
-i [displays network address] -l [displays all local IPs]
date
| set/di­splay date & time
whois
uptime
| display how long the system has been running
cal
| displays calendar
uname -a
| displays Linux system info
uname -r
| displays kernel info
lsb_re­lease -s

Manage Users

su -
| switch to root user & move to that directory
adduser
| add new user
usermod -aG sudo username
| add user to sudo list
groups username
| list groups a user belongs too
su mfsmith
| switch to listed user mfsmith
passwd
| change password for current user name
passwd mfsmith
| change password for listed user
adduser mfsmith -or- useradd mfsmith
| Creates a new user
usermod mfsmith
| modify username account
deluser mfsmith -or- userdel
| Deletes user
deluser mfsmith --remo­ve-­all­-files
| Deletes the user and removes all files in directory
getent powerusers | less
| print user groups
usermod -l newuse­rname olduse­rname
| change user name
sudo chfn mfsmith
| edit basic info i.e. full name, room #, phone #

Process Management

ps
| displays users current processes
ps -ef
| displays all processes
pmap
| displays memory usage
pstree
| display in a tree
ps -ef | grep wa
| display all info reference this process
ps kill 84679
| kill process id 84679
ps killall java
| kill all processes named java
top
| show all running proicesses

Disk/H­ardware Mgmt

df -h
| disk usage
ps
| running processes

System Monitoring

whoami
| display user
uptime
| system run time
cat /proc/­cpuinfo
|
free -h
| display free memory}
lshw
| print hardware config­uration
last reboot
| disaply date & time of last reboot
w
| display currently logged in users

Searching

locate [name of file]
| searches system & locates that directory
find . -name [94148­11_­497­94.pdf]
| search in current directory for file name
find /home -name *.jpg
| search file type in listed directory
Using GREP
| grep searches for patterns in files
grep -r
command | grep
| searches the output of a command

OS Mainte­nance

sudo apt update
| check for updates in current version
apt-get install docker
| install docker
apt-get updater && apt-get upgrade

Misc Need Organizing

ssh mfsmit­h@s­rv-­tower
log into machine
scp mfsmit­h@s­rv-­tower :srv-dc
scp<us­ern­ame.@<­hos­t:[­remote sourse] <local.
copies files from the host to the destin­ation

Working with Processes

pstree
| display a tree of processes
systemctl proces­sname
| control the systemd init system & service manager

Working with File Permis­sions

chmod 777 [name of file]
| assign read, write & execute to all users
chmod 755 [name of file]
| read, write & execute for owner - read & execute for all other users
chmod 766 [name of file]
| full permission to owner - read and write to others

SuperUser

su -
Change to superuser & stay at root directory

General Mainte­nance

Update & Upgrade the Debian OS
 
sudo apt-get update && sudo apt-get upgrade

Installs - Frequently Used

vagran­t@d­ebi­an11:/ sudo apt-get install nano -y

Basic Network Mgmt

vagran­t@d­ebi­an11:/ ip -c link show
| displays network devices
vagran­t@d­ebi­an11:/ sudo cp /etc/n­etw­ork­/in­ter­faces ~/
| creates a copy of the network file
 
vagran­t@d­ebi­an11:/ sudo nano /etc/n­etw­ork­/in­ter­faces
| opens the network file for editing i.e. creating a static IP
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
-auto enp0s3
iface enp0s3 inet static
-address 192.16­8.1.97
-netmask 255.25­5.255.0
-gateway 192.16­8.1.1
-dns-d­omain exampl­e.com
-dns-n­ame­servers 1.1.1.1

sudo systemctl restart networking
 

Directory Structure

/
| root directory of operating system
/etc
| host system config files
/var
| storage for file which grow in size
/bin
| user binary files i.e. cat, grep, etc.
/proc
| system processes
/srv
| system services
/mnt
| ppermenet storage
/home
| home directory for logged in user
/lib
| shared library files and kernel modules
/usr
| user utilities and apps
/dev
| device files i.e. mouse, keyboard, harddrive, etc.
/sbin
| system binary files
/opt
| option software
/media
| temp storag­e/flash drives

Directory Colors

Blue | Directory
Yellow | Device
Green | Executable
Magenta | Graphic Image
Cyan | symbolic Link
Red | Archive File
 
Red & Black | Broken link

Working with Direct­ories

ls
| list contents of current directory
ls -r
| list files in subdir­ect­ories
ls -al
| list files with direct­ories, size, permis­sions etc.
ls-l
|list files and permis­sions
 
r [read] w[write] x [execute] -= [no permis­sions
ls -a
| list contents of current directory including hidden files
ls -lart
| long, include hidden, ,
ls -d*/
| list direct­ories
cd ~
| jump to users home
cd..
| jump to last directory
cd /
| jump to root home directory
cd -
| previous working directory
cd ../../
| back up two levels

File Management

cp file name [-r creates destin­ation]
mv Linux Command Cheatsheet to Linux Command Line Cheatsheet
| is also for renaming
cat filename
less
mkdir\rm directory
rm
cd

Troubl­esh­ooting

Issue:
usermod command not found
Resolu­tion:
use su - instead of su root
Issue:
wget command not found
Resolu­tion:
sudo apt-get install wget
Issue:
cannot access reposi­tories
Resolu­tion:
manually add site via nano /etc/a­pt/­sou­rce­s.list

Basic Mariadb Commands

Log into DB
sudo systemctl enable mysql
 
sudo systemctl restart mysql
 
sudo mysql -u root -p

Basic Queries

select user from mysql.u­ser;
| displays all database users
show grants for 'zabbi­x'@­'lo­cah­osts'
| displays user privileges
set password for 'zabbi­x'@­'lo­calhost = password ('zabb­ix');

Install Mariad­b-S­erver

sudo apt install mariad­b-s­erver
sudo mysql_­sec­ure­_in­sta­llation
sudo mariadb
CREATE DATABASE exampl­e_d­ata­base;
ALTER DATABASE test CHARACTER SET='utf8' COLLAT­E='­utf­8_bin';
GRANT ALL ON exampl­e_d­ata­base.* TO 'examp­le_­use­r'@­'lo­cal­host' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVIL­EGES;
exit
sudo mariadb
mariadb -u exampl­e_user -p
SHOW DATABASES;

Networking Comman­d/Q­ueries

ip a
| display IP Address, routing, devices and tunnels
netstat
| displays all active TCP connec­tions, ports
-nutlp [displays tcp/udp ports & applic­ation running on port]
-e [includes ethernet stats] -o [includes PIDs] -p [displays protocols] -r [displays routing table]
ping
| test commun­ication with machines
traceroute srv-dc
print packet route
host
| DNS lookup utililty
hostname
| show or set system name
iptables
|utililty for packet filtering and NAT
mtr
| network diagnostic tool
telnet
| access to the telnet tool
ufw
| applic­ation to mange filters and firewalls
mtr
| diagnostic tool
nbtstat
| displays netbios over tcp
arp
| displays caches apr table
pathping
| disaplys info about network latenc­y/loss between hops
tcpdump

Firewall

sudo apt-get install ufw
| install firewall applic­ation
sudo ufw allow 'Nginx HTTP'
| allow applic­ation to pass through firewall
sudo ufw status
| check firewall status
sudo ufw disable
| disable firewall
sudo ufw enable
| enable firewall
sudo ufw allow 22
| allow port number to pass
sudo ufw reset
| reset firewall