20 Basic Commands in Linux - Linux Simplified

In this post, we’ll explore 20 basic Linux commands everyone should know.

1. whoami

Displays the currently logged-in user.


2. pwd

pwd stands for Print Working Directory. It displays the current directory the user’s in.


3. ls

ls is used to List files and directories. This is one of the most fundamental and frequently used commands in the Linux terminal. When used without any options, it shows the contents of the current directory the user’s in.

Here are the options for the ls.

  • -l Long, detailed list of all information.

  • -a Lists all files, including hidden files (those starting with a .).

  • -h List files with human readable file sizes.

  • -r Reverse order lists files with the oldest date first.


4. tree

This command outputs a tree-like view of the specified directory and its content (files, subdirectories). It makes it easier to look up the content inside a directory.


5. cd

The Change Directory command is used for navigating between directories.

cd .. Moves up a directory

cd - Returns to the previous directory

cd Goes to the user’s home directory


6. mkdir

mkdir stands for Make Directory. This command is used for creating directories.

Creating multiple directories at once.


7. cp

cp stands for Copy. This commands is used for copying files and directories.

In this example, I want to copy the linux.txt file into the Documents directory.

So here’s cp command for that.

Verifying inside the Documents directory.

Note using cp with -r allows you to copy a directory with its content.


8. mv

mv stands for Move. This command is used for moving and renaming the files and directories.

Here I moved the linux.txt file from the current directory (/home/dewnuwan/Documents) into the Music directory (/home/dewnuwan/Music).

Verifying inside the Music directory.

While there’s a rename command in Linux, it’s only being used for batch operations. So most of the time we just use mv to rename the files and directories.


9. rm

rm stands for Remove. This is used for removing files from a directory. You need write access for the folder. Here are the most used options for this command.

-r Remove the directory with its subdirectories (alternative to rmdir).

-i Prompt a confirmation message before deleting

-f Force delete (without a confirmation dialogue)

Forceful Recursion

The most common and dangerous combination of options is rm -rf. This command will delete everything in the directory and its subdirectories without any confirmation. So use it carefully.

Here * stands for all in the current directory.


10. rmdir

This is to remove a specified empty directory. Use the option -p to force the deletion.


11. cat

cat is used for viewing content inside of a file. (text files, scripts..etc)


12. echo

echo is useful when we want to get an output of a line of text. This is very useful when creating shell scripts.

Similarly, it can also be used with > , to overwrite a text input to a file.

We can also use echo to append a line of text to a file with ».


13. touch

touch is useful for creating new files. Simply enter the file name with the extension.

Here I created a simple Python script called scripting.py using touch and added a code using echo.


14. grep

grep stands for Global Regular Expression Print. It is used for searching speicifc string or a pattern within a file OR filtering out the results from a command output.

Here I listed the content inside / directory. And I want to see only the results including "“lib”.

so I will filter the ls -l command by using what we called pipe. which redirects the output of the ls -l command through the grep command.

Note that now it’s only showing the results that include the “lib” in their name.


15. locate

This is another simple but very important command. Very useful when it comes to finding the path of a specific file/directory by going through the whole system at once.

Note that locate uses a local database to locate anything. And that database is only updated once per day. So we’ll have to use updatedb command once before using locate sometimes with new files/directories.


16. find

find is the top searching utility command that we can use to find anything we want within a specific directory. Unlike the locate command, find looks for files in real time, so there’s no need to wait for the database to be refreshed.

-name Search files using name

-type Search items using its type (For files use f, for directories use d)


17. sudo

sudo stands for Super User Do. It allows a regular non-root user (who is in the sudo group) to execute commands as the superuser (administrator). Once entered you need to enter the user’s password. This is a regular command you’ll be using in a Linux system.


18. history

history allows us to view the previously entered commands history in the terminal. This is very handy when it comes to troubleshooting.


19. man

man stands for Manual. This is used to figure out what a certain command is doing. Basically allows us to read the manual written by the devs. Simply adds man before a command name.

This example shows the manual for the rmdir command.


20. nano

nano is an easy-to-use simple text editor that comes preinstalled with many Linux distros.

Okay, so this concludes the second post in this Linux Simplified blog series. Let’s talk about user and group management in Linux in the next post!

0
Subscribe to my newsletter

Read articles from Dewnuwan Jayaweera directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dewnuwan Jayaweera
Dewnuwan Jayaweera