The Ultimate List of Ubuntu Linux Commands Categorized by Usage
Mastering Linux commands is key to becoming proficient in system administration, programming, and efficient computing. Ubuntu, one of the most popular Linux distributions, provides a plethora of commands for various tasks. This comprehensive guide categorizes these commands by their usage, ensuring you can quickly find what you need. Whether you’re a beginner or a seasoned user, this list will be an invaluable resource.
1. File and Directory Management
Navigation
-
pwd
– Print the current working directory. -
ls
– List directory contents.-
ls -l
– Detailed list with permissions. -
ls -a
– Include hidden files. -
ls -lh
– Display sizes in human-readable format. -
ls -R
– List subdirectories recursively. -
ls -t
– Sort by modification time. -
ls --color=auto
– Highlight file types with colors.
-
-
cd
– Change directory.-
cd ..
– Move up one level. -
cd ~
– Go to the home directory. -
cd -
– Go to the previous directory.
-
File Manipulation
-
touch <file>
– Create an empty file. -
cp <source> <destination>
– Copy files or directories.-
cp -r
– Copy directories recursively. -
cp -i
– Prompt before overwrite. -
cp -u
– Only copy files that are newer than the destination.
-
-
mv <source> <destination>
– Move or rename files/directories.-
mv -i
– Prompt before overwrite.
-
-
rm <file>
– Remove files.-
rm -r
– Remove directories recursively. -
rm -i
– Prompt before deletion. -
rm -f
– Force delete without prompt.
-
Directory Management
-
mkdir <directory>
– Create a new directory.-
mkdir -p <directory>
– Create nested directories.
-
-
rmdir <directory>
– Remove an empty directory. -
tree
– Display directories as a tree (requires installation).- Install:
sudo apt install tree
-
tree -d
– Display only directories. -
tree -L <level>
– Limit depth of the tree display.
- Install:
2. File Viewing and Searching
Viewing File Contents
-
cat <file>
– Concatenate and display file contents.-
cat -n <file>
– Number the output lines. -
cat -s <file>
– Squeeze multiple blank lines.
-
-
less <file>
– View file content one screen at a time.-
less +F <file>
– Follow the file updates.
-
-
more <file>
– Similar toless
but less powerful. -
head <file>
– Display the first 10 lines of a file.-
head -n <num> <file>
– Display the firstnum
lines.
-
-
tail <file>
– Display the last 10 lines of a file.-
tail -n <num> <file>
– Display the lastnum
lines. -
tail -f <file>
– Continuously monitor file updates.
-
Searching
-
find <path> -name <filename>
– Search for files by name.-
find <path> -iname <filename>
– Case-insensitive search. -
find <path> -type f
– Search only files. -
find <path> -type d
– Search only directories. -
find <path> -mtime -<days>
– Find files modified within the last<days>
days.
-
-
grep <pattern> <file>
– Search for a string in a file.-
grep -i <pattern> <file>
– Case-insensitive search. -
grep -v <pattern> <file>
– Exclude lines matching the pattern. -
grep -c <pattern> <file>
– Count occurrences. -
grep -l <pattern> <directory>
– List files containing the pattern.
-
-
locate <file>
– Find files quickly (requires updated database).- Update database:
sudo updatedb
-
locate -i <file>
– Case-insensitive search.
- Update database:
-
which <command>
– Show the path of a command.
3. Permissions and Ownership
-
chmod <permissions> <file>
– Change file permissions.-
chmod u+x <file>
– Add execute permission to the owner. -
chmod g-w <file>
– Remove write permission from the group. -
chmod 777 <file>
– Grant all permissions to everyone.
-
-
chown <owner>:<group> <file>
– Change file ownership.-
chown <owner> <file>
– Change file owner. -
chown :<group> <file>
– Change file group. -
chown -R <owner>:<group> <directory>
– Recursively change ownership.
-
-
ls -l
– View file permissions and ownership.
4. User Management
-
whoami
– Display the current user. -
id
– Show user and group IDs.-
id -u
– Display only the user ID. -
id -g
– Display only the group ID.
-
-
who
– List logged-in users.-
who -u
– Display idle time of users. -
who -q
– Display only usernames and count.
-
-
adduser <username>
– Add a new user. -
passwd <username>
– Change the user password.-
passwd -l <username>
– Lock a user account. -
passwd -u <username>
– Unlock a user account.
-
-
deluser <username>
– Remove a user.-
deluser --remove-home <username>
– Remove user and their home directory.
-
-
usermod
– Modify user accounts.-
usermod -aG <group> <user>
– Add user to a group. -
usermod -L <user>
– Lock a user account. -
usermod -U <user>
– Unlock a user account.
-
5. Process Management
-
ps
– List running processes.-
ps aux
– Detailed list of processes. -
ps -e
– Display all processes.
-
-
top
– Real-time view of processes.-
top -u <user>
– Show processes of a specific user.
-
-
htop
– Interactive process viewer (requires installation).- Install:
sudo apt install htop
- Install:
-
kill <PID>
– Terminate a process by PID. -
killall <name>
– Kill all processes by name. -
pkill <name>
– Kill processes by name.-
pkill -u <user>
– Kill all processes of a user.
-
-
bg
– Resume a job in the background. -
fg
– Resume a job in the foreground. -
jobs
– List active jobs.
6. Disk and Storage Management
-
df
– Show disk space usage.-
df -h
– Human-readable format. -
df -i
– Show inode usage.
-
-
du
– Show directory/file size.-
du -sh <path>
– Human-readable summary. -
du -a
– Display sizes of all files.
-
-
mount
– Mount a filesystem.-
mount -a
– Mount all filesystems in/etc/fstab
.
-
-
umount
– Unmount a filesystem. -
lsblk
– List information about block devices.-
lsblk -f
– Display filesystems. -
lsblk -a
– Show all devices, including empty ones.
-
-
blkid
– Display block device attributes.-
blkid -o list
– Show output in list format.
-
-
fdisk
– Partition management.-
fdisk -l
– List partitions.
-
-
mkfs
– Format a filesystem.-
mkfs.ext4 /dev/sdX
– Create an ext4 filesystem. -
mkfs.vfat /dev/sdX
– Create a FAT filesystem.
-
7. Package Management
-
apt update
– Update the package index. -
apt upgrade
– Upgrade all packages. -
apt install <package>
– Install a package.-
apt install -y <package>
– Automatically answer yes to prompts.
-
-
apt remove <package>
– Remove a package. -
apt autoremove
– Remove unused packages. -
dpkg -l
– List installed packages. -
dpkg -i <package.deb>
– Install a.deb
package.-
dpkg --configure -a
– Reconfigure broken packages.
-
8. Networking
-
ping <host>
– Test connectivity to a host.-
ping -c <count> <host>
– Send a specific number of packets.
-
-
wget <URL>
– Download files from the web.-
wget -c <URL>
– Continue an interrupted download. -
wget -r <URL>
– Recursively download a website.
-
-
curl <URL>
– Transfer data from/to a server.-
curl -I <URL>
– Fetch headers only. -
curl -O <URL>
– Save the downloaded file.
-
-
ifconfig
– Display or configure network interfaces.-
ifconfig <interface>
– Display information about a specific interface.
-
-
ip
– Show/manipulate network configurations.-
ip a
– Show all network interfaces. -
ip r
– Display routing table. -
ip link set <interface> up
– Bring an interface up. -
ip link set <interface> down
– Bring an interface down.
-
-
netstat
– Show network connections (deprecated, usess
).-
netstat -tuln
– Display listening ports. -
netstat -a
– Show all connections.
-
-
ss
– Display detailed socket statistics.-
ss -tuln
– Show listening ports. -
ss -p
– Display processes using sockets.
-
-
nslookup <domain>
– Query DNS for domain/IP information. -
traceroute <host>
– Show the route packets take to a host (requires installation).- Install:
sudo apt install traceroute
- Install:
-
dig <domain>
– Perform DNS lookups.-
dig +short <domain>
– Display concise DNS results.
-
-
ftp <host>
– Connect to an FTP server.-
ftp -i
– Disable interactive prompts.
-
9. System Information
-
uname
– Show system information.-
uname -a
– Display all system information. -
uname -r
– Display the kernel version.
-
-
hostname
– Display or set the system hostname. -
uptime
– Show how long the system has been running. -
dmesg
– Display system boot and kernel logs.-
dmesg | grep <keyword>
– Search logs for specific keywords.
-
-
free
– Display memory usage.-
free -h
– Show human-readable memory usage.
-
-
vmstat
– Show system performance statistics.-
vmstat -s
– Display memory usage in detail.
-
-
lscpu
– Display CPU architecture information. -
lsb_release
– Display Ubuntu release information.-
lsb_release -a
– Display all details.
-
-
uptime
– Show system uptime. -
who
– Show who is logged into the system.
10. Compression and Archiving
-
tar
– Archive files.-
tar -cvf <archive.tar> <files>
– Create an archive. -
tar -xvf <archive.tar>
– Extract an archive. -
tar -czvf <archive.tar.gz> <files>
– Create a compressed archive. -
tar -xzvf <archive.tar.gz>
– Extract a compressed archive.
-
-
zip
– Compress files.-
zip <archive.zip> <files>
– Create a zip archive. -
zip -r <archive.zip> <directory>
– Zip a directory recursively.
-
-
unzip <archive.zip>
– Extract a zip archive. -
gzip
– Compress a file.-
gzip <file>
– Compress a file. -
gzip -d <file.gz>
– Decompress a.gz
file.
-
-
7z
– Manage 7-zip files (requires installation).- Install:
sudo apt install p7zip-full
-
7z a <archive.7z> <files>
– Create a 7z archive. -
7z x <archive.7z>
– Extract a 7z archive.
- Install:
11. System Monitoring
-
uptime
– Show system uptime. -
top
– Monitor active processes. -
htop
– Interactive process monitor (requires installation). -
vmstat
– Report on system performance. -
iotop
– Show disk I/O (requires installation).- Install:
sudo apt install iotop
- Install:
-
sar
– Collect and report system activity (requires installation).- Install:
sudo apt install sysstat
-
sar -u 1
– Display CPU usage every second.
- Install:
12. Advanced Text Processing
-
awk
– Pattern scanning and processing language.-
awk '{print $1}' <file>
– Print the first column of a file. -
awk '/pattern/ {action}' <file>
– Execute actions on lines matching a pattern.
-
-
sed
– Stream editor for filtering and transforming text.-
sed 's/old/new/g' <file>
– Replace all occurrences ofold
withnew
in a file. -
sed -n 'p' <file>
– Print specific lines.
-
-
sort
– Sort lines in a file.-
sort <file>
– Sort lines alphabetically. -
sort -n <file>
– Sort lines numerically.
-
-
uniq
– Remove duplicate lines.-
uniq -c <file>
– Display counts of duplicate lines.
-
This comprehensive list continues to evolve. Stay tuned for updates, and don’t hesitate to suggest additional commands to make this the ultimate Linux command reference.
Top comments (0)