Information
pwd |
| print working directory |
cat |
| print file [on screen] |
user head or tail instead of cat |
| shows the first few lines at beginning or end |
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 |
passwd -S sysadmin |
| displays the status of the users password |
|
[P] Unlocked |
|
[L] locked |
|
[NP] no password |
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 |
General Maintenance
Shutdown [OPTIONS] TIME [MESSAGE] |
| sudo shutdown =1 "System scheduled for restart" |
Update & Upgrade the Debian OS |
|
sudo apt-get update && sudo apt-get upgrade |
Package management | OS Maintenance
sudo apt-get update |
| check for updates in current version |
apt-get updater && apt-get upgrade |
|
apt-cache search docker |
| search for packages with the word "Docker" in the file name |
apt-get install docker |
| install docker |
|
apt-get remove |
| removes a package |
apt-get purge |
| removes and deletes |
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 |
SuperUser
su - |
| change to superuser & stay at root directory |
sudo - |
| execute a command as root |
- or - |
sudo -u |
| execute a command as a particular user |
Installs - Frequently Used
vagrant@debian11:/ sudo apt-get install nano -y |
Basic Network Mgmt
iwconfig |
| wireless interface |
ifconfig |
| ethernetinterface |
# 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
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 |
ping -c 4 |
| limits the ping response to 4 replies |
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 |
Other Commands
; [semi colon] |
| allows a user to stack/insert multiple command on one command line |
&& [double ampersand] |
| if the command on the left is suceesful then run the command on the right |
| | [double pipe] |
based on the results of the first command, skip the second command |
|
|
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 |
**On many Linux distributions, directories may be displayed in blue, executable files may be displayed in green, and symbolic links may be displayed in cyan.
Colored output is not the default behavior for the ls command, but rather the effect of the --color option. The ls seems to perform this coloring automatically because there is an alias for the ls command, so it runs with the --color option.**
sysadmin@localhost:~$ type ls
ls is aliased to `ls --color=auto'
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 |
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 |
Searching & Sorting
which i.e. which ls |
| which command identifies the stored location of a command |
type -a |
| displays directory location of command |
-t |
| sort by time |
-r |
| sort by reverse order |
Regular Expressions |
. |
| Any one single character |
[ ] |
| Any one specified character |
[^ ] |
| Not the one specified character |
* |
| Zero or more of the previous character |
^ |
| If first character in the pattern, then pattern must be at beginning of the line to match, otherwise just a literal ^ |
$ |
| If last character in the pattern, then pattern must be at the end of the line to match, otherwise just a literal $ |
Extended Expressions |
+ |
| One or more of the previous pattern |
? |
| The preceding pattern is optional |
{ } |
| Specify minimum, maximum or exact matches of the previous pattern |
| |
| Alternation - a logical "or" |
( ) |
| Used to create groups |
Anchor Characters |
'search term' |
| single quotes "protects" the word |
'^ search term' |
| ^ means the first place |
'search term $' |
| $ means the last place |
[ ] |
| [ ] match the blocked in character |
. |
| |
* |
| within a search, this character acts as a wildcard |
? |
| in a search, this character indicates other letters/numbers |
! |
| in a search, this character = does not |
echo [D-P]*
echo [!D-P]*
echo ?????*s
echo Dns
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 |
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 |
Redirection
Redirect the output of a command |
| add ">" |
i.e. |
cat food.txt > newfoodfile.txt |
|
| use ">>" to overwrite a file |
Fucnctions
Functions - |
are typically utilized in scripting |
are utilized to execute multiple commands |
function_name ()
{
commands
}
Quotation Marks
There are [3] types of quotes |
Section [5] Linus Essentials |
" " | double quotes |
tell the system to ignore special characters |
' ' | single quotes |
the system does not consider it a variable |
` ` | backwards quotes |
the system interprests the word in single quotes as an execution |
|
each of these marks tells the system the text inside the quotes are to be handled differently |
|