DEV Community

Cover image for 25 Essential Linux Commands (CLI)
Michael Briseno
Michael Briseno

Posted on

25 Essential Linux Commands (CLI)

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
Enter fullscreen mode Exit fullscreen mode

Output:

user
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Output:

/home/user
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Output:

file1.txt file2.txt dir1 dir2
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

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:

tar -cvf archive.tar file1.txt file2.txt dir1 dir2
tar -xvf archive.tar 
Enter fullscreen mode Exit fullscreen mode

11. Gzip

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

Example:

gzip file.txt 
gunzip file.txt.gz 
Enter fullscreen mode Exit fullscreen mode

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:

zip archive.zip file1.txt file2.txt dir1 dir2 
unzip archive.zip 
Enter fullscreen mode Exit fullscreen mode

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:

cat file.txt 
Enter fullscreen mode Exit fullscreen mode

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:

cat file.txt 
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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!

Top comments (2)

Collapse
 
overflow profile image
overFlow

this will be useful i find myself needing it since I'm using git now. awesome and thankx

Collapse
 
mike_in_tech profile image
Michael Briseno

Thanks @overflow ! I appreciate you stopping by and checking it out! I am glad it could be helpful!