Linux Cmds
Linux Cmds
uses. These commands help with file management, process control, system monitoring,
and more.
---
2. **`ls`**
- Lists files and directories in the current directory.
- Example: `ls -l` (detailed list), `ls -a` (show hidden files)
3. **`cd`**
- Changes the directory.
- Example: `cd /home/user/`, `cd ..` (move to the parent directory)
4. **`mkdir`**
- Creates a new directory.
- Example: `mkdir new_folder`
5. **`rmdir`**
- Removes an empty directory.
- Example: `rmdir old_folder`
6. **`touch`**
- Creates an empty file or updates the timestamp of a file.
- Example: `touch newfile.txt`
7. **`cp`**
- Copies files or directories.
- Example: `cp file1.txt file2.txt` (copy file), `cp -r dir1 dir2` (copy
directory)
8. **`mv`**
- Moves or renames files or directories.
- Example: `mv file1.txt /new_location/` (move file), `mv oldname.txt
newname.txt` (rename)
9. **`rm`**
- Removes files or directories.
- Example: `rm file.txt`, `rm -r folder/` (remove folder and its content)
10. **`cat`**
- Displays the contents of a file.
- Example: `cat file.txt`
---
### **File Permissions**
1. **`chmod`**
- Changes file permissions.
- Example: `chmod 755 script.sh` (owner can read, write, execute; others can
read, execute)
2. **`chown`**
- Changes file owner and group.
- Example: `chown user:group file.txt`
---
2. **`locate`**
- Quickly finds files by name (uses a pre-built database).
- Example: `locate file.txt`
3. **`grep`**
- Searches for a pattern in files.
- Example: `grep "pattern" file.txt`, `grep -r "pattern" /path/` (recursive
search)
---
2. **`sort`**
- Sorts lines in text files.
- Example: `sort file.txt`
3. **`uniq`**
- Removes duplicate lines from a sorted file.
- Example: `uniq file.txt`
4. **`wc`**
- Counts words, lines, and characters in a file.
- Example: `wc file.txt`
5. **`cut`**
- Cuts out sections from each line of files.
- Example: `cut -d',' -f1 file.csv` (cut the first field in a comma-separated
file)
6. **`sed`**
- Stream editor used for searching, finding, and replacing.
- Example: `sed 's/old/new/g' file.txt` (replace "old" with "new")
7. **`awk`**
- Pattern scanning and processing language.
- Example: `awk '{print $1, $2}' file.txt` (print the first two columns)
---
2. **`htop`**
- An improved version of `top`, with better interface.
- Example: `htop`
3. **`ps`**
- Displays information about running processes.
- Example: `ps -ef` (detailed list of all processes)
4. **`df`**
- Shows disk space usage.
- Example: `df -h` (human-readable format)
5. **`du`**
- Estimates file and directory space usage.
- Example: `du -h folder/` (summary in human-readable format)
6. **`free`**
- Displays the amount of free and used memory.
- Example: `free -h` (human-readable format)
7. **`uptime`**
- Shows how long the system has been running and load average.
- Example: `uptime`
---
2. **`killall`**
- Kills all processes with a specified name.
- Example: `killall firefox`
3. **`bg`** / **`fg`**
- Runs jobs in the background or foreground.
- Example: `bg` (resume job in the background), `fg` (bring job to the
foreground)
4. **`jobs`**
- Lists background jobs.
- Example: `jobs`
---
### **Networking**
1. **`ping`**
- Tests the connectivity to a remote host.
- Example: `ping google.com`
2. **`ifconfig`** / **`ip`**
- Displays or configures network interfaces.
- Example: `ifconfig`, `ip a` (show all interfaces)
3. **`netstat`** / **`ss`**
- Displays network connections, routing tables, interface statistics.
- Example: `netstat -tuln`, `ss -tuln` (list listening ports)
4. **`curl`**
- Transfers data from or to a server.
- Example: `curl http://example.com`
5. **`wget`**
- Downloads files from the web.
- Example: `wget http://example.com/file.txt`
---
2. **`reboot`**
- Reboots the system.
- Example: `reboot`
3. **`systemctl`**
- Controls system services.
- Example: `systemctl status apache2` (check status of a service), `systemctl
restart apache2` (restart a service)
4. **`service`**
- Controls system services (older syntax).
- Example: `service apache2 status`
5. **`crontab`**
- Schedules periodic tasks.
- Example: `crontab -e` (edit crontab file), `crontab -l` (list crontab jobs)
---
2. **`gzip`** / **`gunzip`**
- Compresses or decompresses files.
- Example: `gzip file.txt`, `gunzip file.txt.gz`
3. **`zip`** / **`unzip`**
- Compresses and extracts files in `.zip` format.
- Example: `zip archive.zip file.txt`, `unzip archive.zip`
---
2. **`passwd`**
- Changes a user's password.
- Example: `passwd username`
3. **`whoami`**
- Displays the current logged-in username.
- Example: `whoami`
4. **`su`**
- Switches user.
- Example: `su - root` (switch to root user)
5. **`sudo`**
- Executes a command with superuser privileges.
- Example: `sudo apt update`
---
These Linux commands are a great starting point for interacting with the system,
handling files, monitoring performance, and managing resources effectively.