Cheatography
https://cheatography.com
Linux Command Frequently Used
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Information
pwd |
| print working directory |
cat |
| print file [on screen] |
hostname |
| display hostname |
-i [displays network address] -l [displays all local IPs] |
date |
| set/display 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_release -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 --remove-all-files |
| Deletes the user and removes all files in directory |
getent powerusers | less |
| print user groups |
usermod -l newusername oldusername |
| 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/Hardware 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 configuration |
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 [9414811_49794.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 Maintenance
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 mfsmith@srv-tower |
log into machine |
scp mfsmith@srv-tower :srv-dc |
scp<username.@<host:[remote sourse] <local. |
copies files from the host to the destination |
Working with Processes
pstree |
| display a tree of processes |
systemctl processname |
| control the systemd init system & service manager |
Working with File Permissions
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 Maintenance
Update & Upgrade the Debian OS |
|
sudo apt-get update && sudo apt-get upgrade |
Installs - Frequently Used
vagrant@debian11:/ sudo apt-get install nano -y |
Basic Network Mgmt
vagrant@debian11:/ ip -c link show |
| displays network devices |
vagrant@debian11:/ sudo cp /etc/network/interfaces ~/ |
| creates a copy of the network file |
|
vagrant@debian11:/ sudo nano /etc/network/interfaces |
| 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.168.1.97
-netmask 255.255.255.0
-gateway 192.168.1.1
-dns-domain example.com
-dns-nameservers 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 storage/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 Directories
ls |
| list contents of current directory |
ls -r |
| list files in subdirectories |
ls -al |
| list files with directories, size, permissions etc. |
ls-l |
|list files and permissions |
|
r [read] w[write] x [execute] -= [no permissions |
ls -a |
| list contents of current directory including hidden files |
ls -lart |
| long, include hidden, , |
ls -d*/ |
| list directories |
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 destination] |
mv Linux Command Cheatsheet to Linux Command Line Cheatsheet |
| is also for renaming |
cat filename |
less |
mkdir\rm directory |
rm |
cd |
Troubleshooting
Issue: |
usermod command not found |
Resolution: |
use su - instead of su root |
Issue: |
wget command not found |
Resolution: |
sudo apt-get install wget |
Issue: |
cannot access repositories |
Resolution: |
manually add site via nano /etc/apt/sources.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.user; |
| displays all database users |
show grants for 'zabbix'@'locahosts' |
| displays user privileges |
set password for 'zabbix'@'localhost = password ('zabbix'); |
Install Mariadb-Server
sudo apt install mariadb-server |
sudo mysql_secure_installation |
sudo mariadb |
CREATE DATABASE example_database; |
ALTER DATABASE test CHARACTER SET='utf8' COLLATE='utf8_bin'; |
GRANT ALL ON example_database.* TO 'example_user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION; |
FLUSH PRIVILEGES; |
exit |
sudo mariadb |
mariadb -u example_user -p |
SHOW DATABASES; |
Networking Command/Queries
ip a |
| display IP Address, routing, devices and tunnels |
netstat |
| displays all active TCP connections, ports |
-nutlp [displays tcp/udp ports & application running on port] |
-e [includes ethernet stats] -o [includes PIDs] -p [displays protocols] -r [displays routing table] |
ping |
| test communication 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 |
| application to mange filters and firewalls |
mtr |
| diagnostic tool |
nbtstat |
| displays netbios over tcp |
arp |
| displays caches apr table |
pathping |
| disaplys info about network latency/loss between hops |
tcpdump |
Firewall
sudo apt-get install ufw |
| install firewall application |
sudo ufw allow 'Nginx HTTP' |
| allow application 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 |
|