0% found this document useful (0 votes)
16 views

Linux Cmds

Linux commands

Uploaded by

chandu518cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Linux Cmds

Linux commands

Uploaded by

chandu518cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Here is a concise set of notes covering essential **Linux commands** and their

uses. These commands help with file management, process control, system monitoring,
and more.

---

### **Basic Commands**


1. **`pwd`**
- Prints the current working directory (path).
- Example: `pwd`

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`

11. **`more`** / **`less`**


- Views file content page by page.
- Example: `less file.txt`, `more file.txt`

12. **`head`** / **`tail`**


- Shows the first or last 10 lines of a file.
- Example: `head file.txt`, `tail file.txt`, `tail -f log.txt` (track log file
in real-time)

---
### **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`

---

### **File Searching**


1. **`find`**
- Searches for files in a directory hierarchy.
- Example: `find /home -name "*.txt"` (find `.txt` files)

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)

---

### **Text Processing**


1. **`echo`**
- Displays a line of text.
- Example: `echo "Hello, World!"`

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)
---

### **System Monitoring**


1. **`top`**
- Displays real-time system processes and resource usage.
- Example: `top`

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`

---

### **Process Management**


1. **`kill`**
- Sends a signal to a process, usually to terminate it.
- Example: `kill 1234` (terminate process with PID 1234)

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`

---

### **System Management**


1. **`shutdown`**
- Shuts down or reboots the system.
- Example: `shutdown -h now` (shutdown immediately), `shutdown -r now` (reboot)

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)

---

### **File Compression**


1. **`tar`**
- Archives files and directories.
- Example: `tar -cvf archive.tar folder/` (create tar archive), `tar -xvf
archive.tar` (extract tar archive)

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`

---

### **User Management**


1. **`useradd`**
- Adds a new user.
- Example: `sudo useradd newuser`

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.

You might also like