28 Basic Linux Commands for Beginners

Linux command cheats sheet, newbie must know!

1. cd (Change Directory)

Used to move between directories. To use it, simply type cd followed by the directory path you want to go to, for example

cd /home/user

Use the command above to move to the /home/user directory

2. pwd (Print Working Directory)

Used to see the location of the directory you are currently in

3. ls (list)

ls is the command used to view directories on Linux. This Basic Linux commands is used to view or display/list the contents of a folder/directory in Linux. If typed directly it will display the contents of the directory you are currently in.

You can also use it to view the contents of other directories by adding the directory path after the ls command. For example, to see the contents of the /etc/ folder, you can use the ls /etc command

4. touch

Touch is the easiest Basic Linux commands to create an empty file and can also be used to change the timestamp. To create an empty file, just type touch filename1

You can also create many empty files at once by typing more than one file name separated by spaces.

Example: touch filename1 filename2 filename3

5. mkdir (Make Directory)

This command is used to create an empty folder. If you just type the command mkdir foldername it will create the folder where you are.

If you want to create a folder somewhere else without needing to go to that folder, you can use the command

mkdir /path/to/folder

6. cp (Copy)

Used to copy and paste files and directories, how to use it is quite easy, just type cp /path/file/origin /path/file/destination

7. mv (Move)

Used to move and rename files or folders mv /path/to/origin /path/to/destination

If the destination is the same as the origin then this method can be used to rename files and folders on Linux

8. rm (Remove)

The rm command in Linux can be used to delete anything, whether files or folders, adding the -rf option will delete the entire folder and its contents.

Example: You want to delete a folder that contains folders and files too, then you have to use the -rf option, for example rm -rf my folder

9. rmdir (Remove Directory)

rmdir can only be used to delete empty directories/folders, if you want to delete a folder with its contents then you can use the command rm -rf foldername

Basic Linux Command illustration
Basic Linux command ilustration

10. du (Disk Usage)

du command is used to see the use of storage/disk space used by files or folders.

For example, to find out the size of files and folders in the /var/www/html directory, you can use the command du -sch /var/www/html/*

11. cat 

cat (acronym for concatenate) is one of the basic commands of the Linux operating system that is often used. This command functions to create a list of contents or file contents in standard output (sdout). To run this command, type cat followed by the file name and extension. For example: cat file.txt.

Here are some ways to use the cat command:

cat > filename to create a new file.
cat filename1 filename2>filename3 to combine two files (1 and 2) and save the output in a new file (3).
cat filename | tr az AZ >output.txt to convert the file to uppercase or lowercase.

12. find 

Just like the locate command, the find Basic Linux commands can also be used to search for files and directories. The difference is, the find command is intended to search for files located in a given directory.

For example, the command find /home/ -name notes.txt will search for a file named notes.txt in the home directory and its subdirectories.

Here are some variations that can be paired with find:

find . – name notes.txt to search for files in the current directory.
/ -type d -name notes.txt to search the directory.

13. grep 

Another Basic Linux commands that is very useful for completing daily tasks is grep. With this command, you can search all the text in a given file.

For example, type grep blue notepad.txt to search for the word blue in the notepad file. The line containing the searched word will be displayed completely.

14. sudo 

sudo is an abbreviation of “SuperUser Do” and functions to run tasks that require administrative or root permissions.

However, we do not recommend using the sudo command for daily tasks because errors can occur at any time if you make a mistake.

15. df 

To get a report on system disk space usage, use the df command. The reports provided are in the form of percentages and KB. If you want to see a report in megabytes, type df -m.

16. du 

du is a basic Linux command that functions to check how much space is used by a file or directory.

It’s just that the disk usage summary format is displayed in the form of disk block numbers instead of the usual size format.

If you want to see the disk usage count in bytes, kilobytes, and megabytes, add the -h argument to the command line.

17. head 

The head command is used to view the first line of all text files. By default, this command will display the first ten lines. However, the number of rows can be changed according to your wishes. For example, if you only want to display the first five lines, then type head -n 5 filename.ext

18. tail 

The tail command has the same function as the head command. Only, instead of the first line, the tail command will display the last ten lines of a file. For example, tail -n filename.ext.

19. diff 

diff is a basic Linux command that compares the contents of two files on a line by line basis. After analyzing the file, this command will produce output in the form of lines or lines that do not match. Programmers often use this command when they need to make program changes, instead of rewriting all the source code.

The simplest format of this basic Linux command is diff file1.ext file2.ext.

20. tar 

tar is the most widely used Linux command to archive multiple files into a tarball – a Linux file format similar to the zip format, where the compression action is optional.

The basic commands of this Linux operating system are quite complex with a long list of functions, such as adding new files to an existing archive, listing the contents of an archive, extracting contents from an archive, and much more. 

21. chmod 

chmod is another basic Linux command used to read, write, and execute file and directory permissions. Because this command is quite difficult, to run it, please read this complete tutorial first.

22. chown 

On the Linux operating system, all files are owned by a special user. As a basic Linux command, chown allows you to change or transfer file ownership to a specific username.

For example, chown linuxuser2 file.ext will specify linuxuser2 as the owner of file.ext.

23. jobs 

The jobs command will display all current jobs along with their status. Basically a job is a process started by the shell.

24. kill 

If no program is responsive, you can kill it manually using the basic Linux kill command. This basic Linux command will send a certain signal to the problematic application and give instructions to the application to end or shut down by itself.

In total there are 64 signals that can be used, but usually people only use two signals, namely:

SIGTERM (15) – asks the program to stop working and gives it time to save all progress. If no special signal is specified when entering the kill command, then this signal will be used.

SIGKILL (9) – forces the program to stop working immediately. Unsaved progress will be lost.

Apart from signals, you also have to know the process identification number (PID) of a program that you want to stop (kill). If you don’t know the PID, you can run the command ps ux.

After knowing the signal you want to use and the program PID, enter this syntax: kill [signal option] PID.

25. ping 

The ping command functions to check the connectivity status to the server. For example, by adding ping google.com, the basic Linux command will check whether you are connected to Google or not and also measure the response time.

26. wget 

This basic Linux command is very useful – you can even download files from the internet with the help of the wget command. You just need to type wget followed by the download link.

27. uname 

uname, an acronym for Unix Name, is a basic Linux operating system command that will print complete information about the Linux system, for example the machine name, operating system, kernel, etc.

28. top 

As the terminal equivalent of the Task Manager in Windows, the top command will display a list of ongoing processes and how much CPU space each process uses.

Monitoring system resource usage is highly recommended, especially when you have to find out which processes need to be killed because they are using too many resources.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 comment