A List of Linux Commands
Tags: bash, linux, ubuntu, cli
Published: 2024-07-04 07:22:15

Here's an easy-to-understand documentation for the listed Linux commands.

### Directory Operations

**1. `ls` - List directories**
```bash
ls
```
The most frequently used command in Linux to list the contents of a directory.

**2. `pwd` - Print working directory**
```bash
pwd
```
Displays the current directory path.

**3. `cd` - Change directory**
```bash
cd directory-name
```
Navigates to the specified directory.

**4. `mkdir` - Make directory**
```bash
mkdir directory-name
```
Creates a new directory.

**5. `mv` - Move or rename files or directories**
```bash
mv source destination
```
Moves or renames files or directories. If moving, it will transfer the file or directory to the new location. If renaming, it will change the name.

**6. `cp` - Copy files or directories**
```bash
cp -r source destination
```
Copies files or directories. The `-r` option allows copying of directories recursively.

**7. `rm` - Remove files or directories**
```bash
rm file-name
rm -r directory-name
```
Deletes files or directories. Use the `-r` option to remove directories recursively.

**8. `touch` - Create empty files**
```bash
touch file-name
```
Creates a blank file if it does not already exist.

### File Content and Display

**9. `cat` - Concatenate and display file content**
```bash
cat file-name
```
Displays the contents of a file.

**10. `echo` - Display message**
```bash
echo "your message"
```
Prints the provided message to the terminal.

**11. `less` - View file contents one page at a time**
```bash
less file-name
```
Displays file content one page at a time, allowing for navigation.

**12. `head` - Display the first few lines of a file**
```bash
head -n number-of-lines file-name
```
Shows the specified number of lines from the top of the file.

**13. `tail` - Display the last few lines of a file**
```bash
tail -n number-of-lines file-name
```
Shows the specified number of lines from the bottom of the file.

### System and User Information

**14. `uname` - System information**
```bash
uname -a
```
Displays basic information about the operating system.

**15. `whoami` - Current username**
```bash
whoami
```
Shows the active username.

### Search and Compare

**16. `grep` - Search for a string in files**
```bash
grep "search-string" file-name
```
Searches for a specified string within a file.

**17. `diff` - Compare files line by line**
```bash
diff file1 file2
```
Displays the differences between two files.

**18. `cmp` - Compare two files byte by byte**
```bash
cmp file1 file2
```
Checks if two files are identical.

**19. `comm` - Compare two sorted files line by line**
```bash
comm file1 file2
```
Combines the functionalities of `diff` and `cmp`.

### File Compression and Archiving

**20. `tar` - Archive files**
```bash
tar -cvf archive-name.tar directory-name
tar -xvf archive-name.tar
```
Creates (`-cvf`) or extracts (`-xvf`) tar archives.

**21. `zip` - Compress files**
```bash
zip archive-name.zip file1 file2
```
Compresses specified files into a zip archive.

**22. `unzip` - Decompress files**
```bash
unzip archive-name.zip
```
Extracts files from a zip archive.

### Process and System Management

**23. `ps` - Display active processes**
```bash
ps aux
```
Lists all currently running processes.

**24. `kill` and `killall` - Terminate processes**
```bash
kill process-id
killall process-name
```
Terminates processes by their ID or name.

**25. `df` - Disk space usage**
```bash
df -h
```
Displays disk space usage in a human-readable format.

### Network Commands

**26. `ifconfig` - Network interface configuration**
```bash
ifconfig
```
Displays network interfaces and IP addresses.

**27. `traceroute` - Trace network path**
```bash
traceroute destination-address
```
Traces all network hops to reach the destination.

**28. `wget` - Download files from the internet**
```bash
wget url
```
Downloads files from the specified URL.

### Security and Permissions

**29. `chmod` - Change file permissions**
```bash
chmod permissions file-name
```
Changes the permissions of a file.

**30. `chown` - Change file owner**
```bash
chown owner:group file-name
```
Changes the ownership of a file.

**31. `sudo` - Execute command with superuser privileges**
```bash
sudo command
```
Runs the command with elevated (superuser) privileges.

### System Utilities

**32. `clear` - Clear terminal screen**
```bash
clear
```
Clears the terminal display.

**33. `man` - Manual pages**
```bash
man command
```
Accesses the manual pages for the specified command.

**34. `alias` - Create command shortcuts**
```bash
alias new-command='existing-command'
```
Creates a custom shortcut for a regularly used command.

**35. `cal` - Display a calendar**
```bash
cal
```
Displays a simple calendar in the terminal.

**36. `top` - Display active processes in real-time**
```bash
top
```
Shows a real-time view of active processes and their system usage.

### User Management

**37. `useradd` and `usermod` - User management**
```bash
sudo useradd username
sudo usermod -aG groupname username
```
Adds a new user or modifies an existing user.

**38. `passwd` - Update user passwords**
```bash
passwd username
```
Creates or updates the password for a specified user.

### Miscellaneous

**39. `ln` - Create symbolic links**
```bash
ln -s target link-name
```
Creates a symbolic link to a target file or directory.

**40. `dd` - Data duplicator for creating bootable USBs**
```bash
dd if=input-file of=/dev/sdX
```
Used for low-level copying and conversion of raw data.

**41. `export` - Set environment variables**
```bash
export VARIABLE_NAME=value
```
Sets or exports environment variables.

**42. `whereis` - Locate binary, source, and manual pages for a command**
```bash
whereis command
```
Finds the location of the binary, source, and manual pages for the specified command.

**43. `whatis` - Display a one-line description of a command**
```bash
whatis command
```

### Directory and File Operations

**44. `basename` - Extract the base name of a file or directory**
```bash
basename /path/to/file
```
Prints the file name without the directory path.

**45. `dirname` - Extract the directory path of a file**
```bash
dirname /path/to/file
```
Prints the directory path without the file name.

**46. `find` - Search for files in a directory hierarchy**
```bash
find /path -name "filename"
```
Searches for files and directories within a specified path.

### File Content and Manipulation

**47. `awk` - Pattern scanning and processing language**
```bash
awk '{print $1}' file
```
Processes and analyzes text files, often used for extracting specific fields from text.

**48. `sed` - Stream editor for filtering and transforming text**
```bash
sed 's/old-text/new-text/' file
```
Performs basic text transformations on an input stream (file or input from a pipeline).

### System and User Information

**49. `uptime` - Show how long the system has been running**
```bash
uptime
```
Displays the current time, how long the system has been running, and system load averages.

**50. `who` - Show who is logged on**
```bash
who
```
Displays a list of users currently logged into the system.

**51. `last` - Show a listing of last logged-in users**
```bash
last
```
Displays a list of users logged in and out since the log file was created.

### Network Commands

**52. `ping` - Send ICMP ECHO_REQUEST to network hosts**
```bash
ping host
```
Sends packets to a network host to test connectivity.

**53. `netstat` - Network statistics**
```bash
netstat -tuln
```
Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

**54. `curl` - Transfer data from or to a server**
```bash
curl -O url
```
Transfers data from or to a server using various protocols (HTTP, FTP, etc.).

### System Management

**55. `htop` - Interactive process viewer**
```bash
htop
```
Displays an interactive view of system processes and their resource usage.

**56. `systemctl` - Control the systemd system and service manager**
```bash
systemctl start|stop|restart|status service-name
```
Manages services and the system state.

### Package Management

**57. `apt` - Package management for Debian-based distributions**
```bash
sudo apt update
sudo apt install package-name
```
Updates package lists and installs packages on Debian-based systems.

**58. `yum` - Package management for Red Hat-based distributions**
```bash
sudo yum update
sudo yum install package-name
```
Updates package lists and installs packages on Red Hat-based systems.

**59. `pacman` - Package management for Arch-based distributions**
```bash
sudo pacman -Syu
sudo pacman -S package-name
```
Updates package lists and installs packages on Arch-based systems.

### Miscellaneous

**60. `nc` (netcat) - Network troubleshooting and debugging tool**
```bash
nc -zv host port
```
Checks the connectivity to a host on a specified port.

**61. `scp` - Secure copy (remote file copy program)**
```bash
scp source-file user@remote-host:/path/to/destination
```
Copies files between hosts on a network.

**62. `rsync` - Remote file and directory synchronization**
```bash
rsync -avz source destination
```
Synchronizes files and directories between two locations over a network.

**63. `crontab` - Schedule periodic jobs**
```bash
crontab -e
```
Edits the crontab file to schedule periodic tasks.

**64. `at` - Schedule commands to run at a specific time**
```bash
at time
```
Schedules a command to run at a specified time.

**65. `hostname` - Show or set the system's hostname**
```bash
hostname
```
Displays or temporarily sets the system's hostname.

**66. `df` - Disk space usage of file systems**
```bash
df -h
```
Shows the disk space usage of file systems in a human-readable format.

**67. `du` - Disk usage of files and directories**
```bash
du -sh directory-name
```
Displays the disk usage of a specified directory.

**68. `history` - Show command history**
```bash
history
```
Lists the command history for the current session.

**69. `watch` - Execute a program periodically, showing output fullscreen**
```bash
watch -n interval command
```
Runs a specified command at regular intervals and displays the output.

**70. `xargs` - Build and execute command lines from standard input**
```bash
echo 'arguments' | xargs command
```

These commands further enhance your ability to manage and navigate a Linux system effectively.