Useful Linux Commands Flashcards
You must know all of these 100%
Show system information
uname -a
Display memory usage
free -h
Show disk space usage
df -h
Show disk usage per directory
du -sh [directory]
Show running processes
ps aux
Show real-time system resource usage
top
Interactive system monitoring tool
htop
Show system uptime and load average
uptime
Display last system boot time
who -b
Show currently logged-in users
who
Show last login history
last
Check system logs
journalctl -xe
Show kernel logs
dmesg
Display open network connections
netstat -tulnp
Display listening ports
ss -tulnp
Display current network interfaces and IP addresses
ip a
Restart a service
systemctl restart [service]
Stop a service
systemctl stop <service></service>
Start a service
systemctl start [service]
Enable a service to start on boot
systemctl enable [service]
Disable a service from starting on boot
systemctl disable [service]
Check service status
systemctl status [service]
List all active services
systemctl list-units –type=service
Show disk partitions
lsblk
Show detailed partition information
fdisk -l
Mount a filesystem
mount [device] [mount_point]
Unmount a filesystem
umount <mount_point></mount_point>
Check disk health (SMART)
smartctl -a /dev/sdX
Create a new user
useradd -m [username]
Delete a user
userdel -r [username]
Change user password
passwd [username]
Add a user to a group
usermod -aG [groupname] [username]
Show group memberships for a user
groups [username]
Show system resource limits
ulimit -a
Monitor real-time system logs
tail -f /var/log/syslog
Shut down the system immediately
shutdown -h now
Reboot the system
reboot
Securely delete a file
shred -u [file_name]
List files in a directory
ls -lah
Change directory
cd [directory]
Create a new directory
mkdir [directory]
Remove an empty directory
rmdir <directory></directory>
Remove a directory and its contents
rm -rf [directory]
Copy a file
cp [source] [destination]
Move or rename a file
mv <source></source> <destination></destination>
Create a new empty file
touch <file_name></file_name>
View file contents
cat <file_name></file_name>
Display file contents with pagination
less <file_name></file_name>
Show the first 10 lines of a file
head <[file_name]
Show the last 10 lines of a file
tail <file_name></file_name>
Find files by name
find /path/to/search -name “<file_name>"</file_name>
Find files larger than 1GB
find / -size +1G
Search for a string inside files
grep “pattern” [file]
Search recursively in directories
grep -r “pattern” /path/to/directory
Show file type
file [file_name]
Change file permissions
chmod 755 [file_name]
Change file ownership
chown user:group [file_name]
Compress a file with gzip
gzip [file_name]
Decompress a gzip file
gunzip [file_name.gz]
Compress a file with bzip2
bzip2 [file_name]
Decompress a bzip2 file
bunzip2 [bzip file]
Create a tar archive
tar -cvf archive.tar [directory]
Extract a tar archive
tar -xvf archive.tar
Create a compressed tar.gz archive
tar -czvf archive.tar.gz [directory]
Extract a tar.gz archive
tar -xzvf archive.tar.gz
Create a compressed tar.bz2 archive
tar -cjvf archive.tar.bz2 [directory]
Extract a tar.bz2 archive
tar -xjvf archive.tar.bz2
How to use scp?
scp [user]@[remote ip]:/path/to/file
How to add something to $PATH?
export PATH=”[new path to add]:$PATH”