Unix commands are instructions used to interact with the Unix operating system through a terminal, allowing users to manage files, processes, users, and system resources efficiently. Unix is a powerful, multi-user, and multi-tasking operating system originally developed at Bell Labs and later inspired many modern systems, including Linux.
- Unix was developed in the 1970s at AT&T Bell Labs by Dennis M. Ritchie and Ken Thompson.
- The C programming language was created specifically to build the Unix operating system.
- Linux is a Unix-like operating system that follows the same design philosophy and command structure.
- The core of Linux is the Linux Kernel, first released in the early 1990s by Linus Torvalds.
- All Unix/Linux commands are case-sensitive, meaning Hello and hello are treated differently.
Below are several sections that explain the most essential Linux commands:
1. File System Navigation Unix Commands
Command | Description | Example |
|---|---|---|
cd | Changes the current working directory. | cd Documents |
ls | Lists files and directories in the current directory. | ls |
pwd | Prints the current working directory. | pwd |
mkdir | Creates a new directory. | mkdir new_folder |
rmdir | Removes an empty directory. | rmdir empty_folder |
mv | Moves files or directories. | mv file1.txt Documents/ |
2. File Manipulation Unix Commands
Command | Description | Example |
|---|---|---|
touch | Creates an empty file or updates the access and modification times. | touch new_file.txt |
cp | Copies files or directories. | cp file1.txt file2.txt |
mv | Moves files or directories. | mv file1.txt Documents |
rm | Remove files or directories. | rm old_file.txt |
chmod | Changes the permissions of a file or directory. | chmod 644 file.txt |
chown | Changes the owner and group of a file or directory. | chown user:group file.txt |
ln | Creates links between files. | ln -s target_file symlink |
| cat | Concatenates files and displays their contents. | cat file1.txt file2.txt |
| head | Displays the first few lines of a file. | head file.txt |
| tail | Displays the last few lines of a file. | tail file.txt |
| more | Displays the contents of a file page by page. | more file.txt |
| less | Displays the contents of a file with advanced navigation features. | less file.txt |
| diff | Compares files line by line. | diff file1.txt file2.txt |
| patch | Applies a diff file to update a target file. | patch file.txt < changes.diff |
3. Process Management Unix Commands
Command | Description | Example |
|---|---|---|
| ps | Displays information about active processes, including their status and IDs. | ps aux |
| top | Displays a dynamic real-time view of system processes and their resource usage. | top |
| kill | Terminates processes using their process IDs (PIDs). | kill <pid> |
| pkill | Sends signals to processes based on name or other attributes. | pkill -9 firefox |
| killall | Terminates processes by name. | killall -9 firefox |
| renice | Changes the priority of running processes. | renice -n 10 <pid> |
| nice | Runs a command with modified scheduling priority. | nice -n 10 command |
| pstree | Displays running processes as a tree. | pstree |
| pgrep | Searches for processes by name or other attributes. | pgrep firefox |
| jobs | Lists active jobs and their status in the current shell session. | jobs |
| bg | Puts a job in the background. | bg <job_id> |
| fg | Brings a background job to the foreground. | fg <job_id> |
| nohup | Runs a command immune to hangups, with output to a specified file. | nohup command & |
| disown | Removes jobs from the shell's job table, allowing them to run independently. | disown <job_id> |
4. Text Processing Unix Commands
Command | Description | Example |
|---|---|---|
| grep | Searches for patterns in text files. | grep "error" logfile.txt |
| sed | Processes and transforms text streams. | sed 's/old_string/new_string/g' file.txt |
| awk | Processes and analyzes text files using a pattern scanning and processing language. | awk '{print $1, $3}' data.csv |
5. Network Communication Unix Commands
| Command | Description | Example |
|---|---|---|
| ping | Tests connectivity with another host using ICMP echo requests. | ping google.com |
| traceroute | Traces the route that packets take to reach a destination. | traceroute google.com |
| nslookup | Queries DNS servers for domain name resolution and IP address information. | nslookup google.com |
| dig | Performs DNS queries, providing detailed information about DNS records. | dig google.com |
| host | Performs DNS lookups, displaying domain name to IP address resolution. | host google.com |
| whois | Retrieves information about domain registration and ownership. | whois google.com |
| ssh | Provides secure remote access to a system. | ssh username@hostname |
| scp | Securely copies files between hosts over a network. | scp file.txt username@hostname:/path/ |
| ftp | Transfers files between hosts using the File Transfer Protocol (FTP). | ftp hostname |
| telnet | Establishes interactive text-based communication with a remote host. | telnet hostname |
| netstat | Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. | netstat -tuln |
| ifconfig | Displays or configures network interfaces and their settings. | ifconfig |
| iwconfig | Configures wireless network interfaces. | iwconfig wlan0 |
| route | Displays or modifies the IP routing table. | route -n |
| arp | Displays or modifies the Address Resolution Protocol (ARP) cache. | arp -a |
| ss | Displays socket statistics. | ss -tuln |
| hostname | Displays or sets the system's hostname. | hostname |
| mtr | Combines the functionality of ping and traceroute, providing detailed network diagnostic information. | mtr google.com |
6. Coding and Development Unix Commands
| Command | Description | Example |
|---|---|---|
| vim / nano | Used to write and edit source code files from the terminal. | vim main.c |
| gcc | Compiles C programs into executable files. | gcc program.c -o program |
| make | Automates compilation using a Makefile. | make |
| ./program | Runs a compiled executable file. | ./program |
| python3 | Executes Python scripts. | python3 script.py |
| git | Manages source code version control. | git status |
| grep | Searches code files for specific patterns or keywords. | grep "main" *.c |
7. System Administration Unix Commands
Command | Description | Example |
|---|---|---|
df | Displays disk space usage. | df -h |
du | Displays disk usage of files and directories. | du -sh /path/to/directory |
crontab -e | Manages cron jobs, which are scheduled tasks that run at predefined times or intervals. | crontab -e |
8. Text Editors in Unix
| Text Editor | Description | Example |
|---|---|---|
| Vi / Vim | Vi (Vim) is a highly configurable, powerful, and feature-rich text editor based on the original Vi editor. Vim offers modes for both command-line operations and text editing. | Open a file with Vim: vim filename Exit Vim editor: Press Esc, then type :wq and press Enter |
| Emacs | Emacs is a versatile text editor with extensive customization capabilities and support for various programming languages. | Open a file with Emacs: emacs filename Save and exit Emacs: Press Ctrl + X, then Ctrl + S and Ctrl + X, then Ctrl + C to exit |
| Nano | Nano is a simple and user-friendly text editor designed for ease of use and accessibility. | Open a file with Nano: nano filename Save and exit Nano: Press Ctrl + O, then Ctrl + X |
| Ed | Ed is a standard Unix text editor that operates in line-oriented mode, making it suitable for batch processing and automation tasks. | Open a file with Ed: ed filename Exit Ed editor: Type q and press Enter |
| Jed | Jed is a lightweight yet powerful text editor that provides an intuitive interface and support for various programming languages. | Open a file with Jed: jed filename Save and exit Jed: Press Alt + X, then type exit and press Enter |