25 Essential Linux Commands (CLI)
Tags: linux, cli, beginners, cloud
Published: 2023-08-08 15:11:55


## 25 Essential Linux Commands

Linux is a powerful operating system that is widely used in the world of computing. It is used in 83.6% of all technology (fake stat). It is known for its stability, security, and flexibility. In this article, we will discuss some of the essential Linux commands that every user should know.

Note: that these commands can also be more specified with the use of options. Just use "man" followed by any of the commands, this will send you to the manual page for that command with all the available options you can use.

### 1. whoami

The `whoami` command is used to display the username of the current user. This command is useful when you need to know which user you are logged in as.

Example:
```
whoami
```
Output:
```
user
```

### 2. pwd

The `pwd` command is used to "Print Working Directory", it will display the current working directory. This command is useful when you need to know which directory you are currently in.

Example:
```
pwd
```
Output:
```
/home/user
```

### 3. ls

The `ls` command is used to "list" the files and directories in the current working directory. This command is useful when you need to know what files and directories are in a directory.

Example:
```
ls
```
Output:
```
file1.txt file2.txt dir1 dir2
```

### 4. cd

The `cd` command is used to "change directory", will change the current directory. This command is useful when you need to navigate to a different directory.

Example:
```
cd /home/user/Documents
```
CHEAT CODE: ```cd ..``` will bring you back one directory, to the parent directory.
### 5. touch

The `touch` command is used to create an empty file. This command is useful when you need to create a new file.

Example:
```
touch file.txt
```

### 6. mkdir

The `mkdir` command is used to "make" a new directory. This command is useful when you need to create a new directory.

Example:
```
mkdir newdir
```

### 7. rm

The `rm` command is used to "remove" files and directories. This command is useful when you need to delete files or directories.

Example:
```
rm file.txt
rm -r dir1
```

### 8. cp

The `cp` command is used to "copy" files and directories. This command is useful when you need to make a copy of a file or directory.

Example:
```
cp file.txt newfile.txt
cp -r dir1 newdir1
```


### 9. mv

The `mv` command is used to "move" files and directories. This command is useful when you need to move a file or directory.

Example:
```
mv file.txt /home/user/Documents/
mv dir1 /home/user/Documents/
```


### 10. tar

The `tar` command is used to create and extract tar archives. This command is useful when you need to compress or decompress files.

Example:
```markdown
tar -cvf archive.tar file1.txt file2.txt dir1 dir2
tar -xvf archive.tar 
```


### 11. Gzip

The `gzip` command is used to compress files. This command is useful when you need to compress large files.

Example:
```markdown
gzip file.txt 
gunzip file.txt.gz 
```


### 12. Zip 

The `zip` command is used to create and extract zip archives. This command is useful when you need to compress or decompress files.

Example:
```markdown
zip archive.zip file1.txt file2.txt dir1 dir2 
unzip archive.zip 
```


### 13. Cat 

The `cat` command is used to display the contents(conCATenation) of a file. This command is useful when you need to view the contents of a file.

Example:
```markdown
cat file.txt 
```


### 14. tac 

The `tac` command is used to display the contents of a file in reverse order, think of CAT but backwards. This command is useful when you need to view the contents of a file in reverse order.

Example:
```markdown
cat file.txt 
```
### 15. nano
The nano command is used as a text editor for creating and editing text files. This command is useful when you need to edit text files.

Example:

```nano file.txt ```

### 16. vi
The vi command is also used as a text editor for creating and editing text files. This command is useful when you need more advanced editing capabilities than nano provides.

Example:

```vi file.txt``` 

### 17. vim
The vim command is an "improved" version of vi with more advanced features for creating and editing text files.

Example:

```vim file.txt``` 

### 18. sed
The sed command is used for Stream EDiting of text
files. This command can be used for search and replace operations on text files.

Example:
```
sed 's/old/new/g' file.txt 
```

### 19. awk 

The `awk` command is used for processing text files. It can be used for searching, filtering, and manipulating text data.

Example:
```
awk '/pattern/ { print $0 }' filename
```


### 20. grep 

The `grep` command searches for lines that match a pattern in one or more files. Stands for Global search / Regular Expressions / Print.

Example:
```
grep 'pattern' file.txt 
```


### 21. chmod 

The `chmod` command is used to change the permissions of a file or directory("Change mode"). This command is useful when you need to change the permissions of a file or directory.

Example:
```
chmod 755 file.txt
```


### 22. chgrp 

The `chgrp` command is used to change the group ownership of a file or directory. This command is useful when you need to change the group ownership of a file or directory.

Example:
```
chgrp users file.txt
```


### 23-25. Usermod, useradd, groupadd

The `usermod`, `useradd`, and `groupadd` commands are used for user and group management. These commands are useful when you need to add, modify, or delete users and groups.

Example:
```
useradd -m -s /bin/bash username
usermod -aG groupname username
groupadd groupname
```

As I work on learning linux and earn a certificate in Linux(LFCS) I have found these are the most recurring commands that I have used. I hope this article helps you get started with some of the essential Linux commands!