Linux Commands Flashcards
list of basic Linux commands
ls
Lists files and directories.
ls -l
(detailed listing with permissions, owner, size)
ls -a
(show hidden files)
cd
Changes the current directory
cd /path/to/directory
(change to specified directory)
cd ..
(move up one directory level)
cd ~
(go to home directory)
pwd
Prints the current working directory.
mkdir
Creates a new directory
rmdir
Removes an empty directory
rm
Removes files or directories.
rm filename
(remove file)
rm -r dirname
(remove directory and its contents)
rm -f filename
(force remove)
cp
Copies files or directories.
cp -r source_dir destination_dir
(copy directory recursively)
mv
Moves or renames files or directories
cat
Concatenates and displays the contents of a file ex. cat filename
more** / **
less
View file contents one screen at a time.
- more filename
less filename` (allows backward scrolling)
head
– Displays the first few lines of a file.
- head filename
tail
Displays the last few lines of a file.
- tail filename
nano
/ vim
/ vi
– Text editors.
- nano filename
(basic editor)
- vim filename
or vi filename
(advanced editor)
chmod
Changes file permissions.
- chmod 755 filename
chown
Changes file ownership.
- chown user:group filename
chgrp
Changes group ownership.
- chgrp groupname filename
locate
Quickly finds files by name (needs updated database).
- locate filename
which
Shows the full path of shell commands.
- which command_name
tar
Archives and extracts files.
- tar -cvf archive.tar /path
(create archive)
- tar -xvf archive.tar
(extract archive)
- tar -czvf archive.tar.gz /path
(create compressed archive)
- tar -xzvf archive.tar.gz
(extract compressed archive
gzip
/ gunzip
Compresses and decompresses files.
- gzip filename
- gunzip filename.gz
zip
/ unzip
Creates and extracts zip files.
- zip archive.zip filename
- unzip archive.zip
grep
Searches for patterns in files.
- grep "pattern" filename
find
Searches for files in a directory hierarchy.
- find /path -name "filename"
netstat** / **
ss`**
Displays network connections, routing tables, and interface statistics.
- ss
(modern replacement for netstat
)
wget
Downloads files from the web.
- wget http://example.com/file
curl
Transfers data from or to a server.
- curl http://example.com
ip a
Displays network configuration.
- ip a
(preferred over ifconfig
on newer systems)
ps
Displays currently running processes.
- ps aux
(all running processes)
top / htop
Shows running processes and resource usage.
- top
(real-time view)
- htop
(colorful and interactive, may need installation)
free
Displays memory usage.
- free -h
(human-readable format)
du
– Shows disk usage of files and directories.
- du -sh
(summary of current directory)
df
– Shows disk usage of file systems.
- df -h
(human-readable format)
uname
Displays system information.
- uname -a
(detailed system info)
adduser / useradd
Adds a new user to the system.
adduser username (interactive and simpler)
useradd username (manual setup)
deluser / userdel
Deletes a user from the system.
deluser username
userdel username
usermod
Modifies a user’s account.
usermod -aG groupname username (add user to a group)
passwd
Changes a user’s password. passwd username
groups
Displays the groups a user is in.
groups username
id
Shows user and group IDs for the current user or specified user.
id username
chage
Changes user password expiration information.
chage -l username (list expiration info)
newgrp
Logs in to a new group.
umask
Sets the default permission for new files.
kill
Terminates a process by PID.
kill PID
killall
Kills all processes by name.
killall process_name
systemctl
Controls the system’s services and daemons.
systemctl start service_name
systemctl stop service_name
systemctl status service_name
systemctl enable service_name (enable at boot)
systemctl disable service_name
service
Manages services (older systems).
service service_name start
service service_name stop
nice / renice
Adjusts the priority of processes.
nice -n priority command
renice priority PID
fdisk
Partition a hard drive.
fdisk /dev/sdX
mount
Mounts a file system.
mount /dev/sdX /mount/point
umount
Unmounts a file system.
umount /dev/sdX
lsblk
Lists information about block devices.
lsblk
blkid
Identifies the UUID and type of a filesystem.
fsck
Checks and repairs file systems.
fsck /dev/sdX
rsync
Synchronizes files between locations.
rsync -avz /source/ /destination/
dd
Copies and converts files, often used for creating disk images.
dd if=/dev/sdX of=/path/to/image.img
traceroute
Traces the route packets take to a network host.
traceroute hostname_or_IP
nslookup / dig
Queries DNS for domain name information.
nslookup domain_name
dig domain_name
iptables
Configures IP packet filter rules for firewalling.
iptables -L (list current rules)
iptables -A (add a rule)
firewalld
Manages firewall dynamically.
firewall-cmd –state (check firewall status)
firewall-cmd –permanent –add-port=8080/tcp
nmap
Scans networks and services.
nmap hostname_or_IP
hostnamectl
Set or display the system’s hostname.
scp
Securely copies files over the network.
scp file user@remote:/path
ssh
Securely logs into a remote machine.
ssh user@hostname_or_IP
curl
Transfers data to/from a server.
curl http://example.com
sudo
Executes a command with superuser privileges.
sudo command
ufw
Simplified firewall tool (for iptables).
ufw status
ufw allow 22/tcp
ufw enable
fail2ban
Bans IPs with failed login attempts (usually needs to be installed).
fail2ban-client status
fail2ban-client unban IP
last
Displays the last login history.
who
Shows who is logged into the system.
history
Shows the command history for the current user.
auditd
Auditing daemon for security monitoring (audit logs)
selinux
Security-Enhanced Linux status and control (if enabled).
getenforce (check mode)
setenforce 0 (disable SELinux temporarily)
tcpdump
Captures and analyzes network packets.
tcpdump -i eth0
dmesg
Displays kernel ring buffer messages (hardware-related logs).
uptime
Shows how long the system has been running and the load averages.
reboot / shutdown
Reboots or shuts down the system.
reboot
shutdown -h now
crontab
Schedules tasks (cron jobs).
crontab -e (edit cron jobs)
at
Schedules one-time tasks.
at now + 5 minutes
timedatectl
Manages system time and date.
timedatectl
ip link
Manages network interfaces.
ip link show (list all interfaces)
ip link set eth0 up (bring up an interface)
ip link set eth0 down (bring down an interface)
ethtool
Displays or changes network interface card (NIC) settings.
ethtool eth0 (show NIC settings)
nmcli
Manages network connections (used with NetworkManager).
nmcli device status (show status of all devices)
nmcli connection show (list saved network connections)
nmcli connection up “connection_name” (activate a connection)
iwconfig
Shows or configures wireless network interfaces (for wireless devices).iwconfig (show wireless interface status)
ifup / ifdown
Brings a network interface up or down (older systems).
ifup eth0 (bring up interface)
ifdown eth0 (bring down interface)
netstat / ss
Displays network connections, routing tables, and interface statistics.
netstat -tuln (list all listening ports)
ss -tuln (modern replacement for netstat)
nmap
Scans networks and discovers open ports.
nmap -sP 192.168.1.0/24 (ping scan to detect live hosts in a subnet)
nmap -p 22 192.168.1.1 (scan port 22 on a specific host)
mtr
Combines ping and traceroute to diagnose network issues.
mtr google.com
nc / netcat
Network utility for reading/writing data over TCP/UDP.
nc -zv 192.168.1.1 22 (check if port 22 is open on the host)
arp
Shows or modifies the system’s ARP (Address Resolution Protocol) table.
arp -a (display ARP table)
arp -d 192.168.1.1 (delete ARP entry)
iptables
Manages IPv4 packet filtering rules.
iptables -L (list rules)
iptables -A INPUT -p tcp –dport 22 -j ACCEPT (allow incoming SSH traffic)
iptables -A INPUT -p tcp –dport 80 -j DROP (block incoming HTTP traffic)
firewall-cmd
Controls the firewall (for systems using firewalld).
firewall-cmd –list-all (show all firewall rules)
firewall-cmd –add-port=8080/tcp –permanent (open port 8080)
firewall-cmd –reload (reload firewall rules)
ufw
Simplified firewall tool (for Ubuntu/Debian-based systems).
ufw status (check firewall status)
ufw allow 22 (allow SSH traffic)
ufw enable (enable firewall)
host
Performs DNS lookups.
host google.com
nload
Shows network traffic and bandwidth usage.
nload eth0
vnstat
Monitors network traffic usage statistics over time.
vnstat (show traffic statistics for all interfaces)
vnstat -i eth0 (show traffic statistics for a specific interface)
Timothy is a system admin, and his work involves complex knowledge of executables and
shared libraries in Linux. There are several commands that he uses often; which one does he
use to access shared object dependencies?
A. tar
B. zip
C. ldd
D. uname -a
C. The man page explains ldd as printing the shared objects (shared libraries) required by
each program or shared object specified on the command line. The command tar is used to
work with tarballs (or files compressed in a tarball archive) in the Linux command line. You
can use the command zip to compress files into a zip archive, and use unzip to extract
files from a zip archive. Use uname to display information about the system your Linux
distro is running. Using the command uname -a
prints most of the information about the
system. It prints the kernel release date, version, processor type, and more.