15 Basic Linux Commands Every User Should Know๐Ÿ”‘

best linux commands

0 Comment

10 mins Read

best linux commands
Get your SSD VPS

Get your SSD VPS

Starting from $4.95/month.

Check it Out

Linux operating system seems to be too complicated to use, command lines might remind you of a programming process that needs expertise or talent to know what to do.

I should say that donโ€™t worry. We want to start with 15 basic Linux commands for beginners to easily become familiar with this popular open-source interface.

 

Before getting to the list of the 15 commands every Linux user should know, you may want to get a perspective on the importance of commands in most distros. Thatโ€™s why the first section deals with some basic definitions and explanations.ย 

There is also a 16th command I think should be here, or maybe the 0th command because itโ€™s probably even more important than the others: apt. Itโ€™s basically used to install and remove packages in many Linux distros, including Debian and Ubuntu. If your OS comes with a GUI, you can just replace most of these 15 commands by clicking on a few screens. What you canโ€™t change, however, is that most packages need to be installed from the terminal, and to that, you need apt. Does your Linux not have a GUI desktop? Not a problem: just take a look at my guide on how to install GUI on Ubuntu Server, and youโ€™ll also see how important apt is!

Linux Hosting Simplified Linux Hosting Simplified

Want a better way to host your websites and web apps? Developing something new? Simply donโ€™t like Windows? Thatโ€™s why we have Linux VPS.

Get your Linux VPS

The Most Basic Linux Commands You Should Know

Most people imagine Linux as a complicated operating system that is used by programmers. But it is not as difficult as in their thoughts. As you get more familiar with this open-source operating system and its distributions, you will find out Linux commands as an easy-to-use interface for helping users in managing, troubleshooting, or even optimizing the OS and its applications.

As you may know, this command-line interface (CLI) is a text-based user interface (UI) in your device that can run nearly all required tasks (A typically black box with white text that is also known as a command-line processor or command-line interpreter).

One of the most popular types of command-line interface for Linux is bash (Bourne Again Shell) shell that supports all the commands of the original Bourne Shell, as well as many others. It was written as a free and open-source replacement for the Bourne shell that includes features such as command-line editing, command history, and command substitution syntax from the Korn shell (KSH), and C shell (CSH). It can also support brace expansion that is used for generating text strings.

Also Read: Install Linux bash on Windows 10!

Having the open nature of bash, most Linux distributions, all releases of Appleโ€™s macOS, Windows Subsystem for Linux, and Solaris Operating system use that as a default user shell. To open the bash shell in Linux, just launch a terminal from your desktopโ€™s application menu and start shell scripting. (Remember that, depending on how your system administrator has set things up, you can change your default shell). When a terminal opens, it will present a prompt to write the code.

โœ…Now, itโ€™s time to learn some Linux codes. In the following, a list of some Linux basic commands with examples will be presented that every Linux user should know:

Note 1: the typical syntax of a command can be something like this:

command [-argument] [ - - long-argument] file

Note 2: commands, files, and directory names in a Linux shell are case sensitive, meaning that PWD will print the current working directory but PWD will return the following error:

Bash: PWD: command not found

Note 3: file extension doesnโ€™t matter which means in Linux CLI, the file type will automatically determine.

Note 4: the

/

(forward-slash) is a special character used for directory separating?

Note 5: nearly all Linux commands support the argument to help you during the journey with the Command-line interface.

- - help

Note 6: the sign is a prompt that shows us that the shell is waiting for input and comes before every syntax in this article.

$

Also Read: Find OS version with Command Line

1- ls command

If you wish to list files or directories within the file system of Linux OS, then the ls command (short for List) is the solution. Using this command, you have a variety of options such as the following table:

Option Description
ls ~ It gives the contents of the home directory
ls ../ It gives the contents of the parent directory
ls โ€“version It checks the version of the ls command
ls -a list all files including hidden files starting with โ€˜.โ€™
ls โ€“color Colored list [=always/never/auto]
ls -d list directories โ€“ with โ€˜ */โ€™
ls -F Shows file types (โ€œ/โ€ = directory, โ€œ*โ€ = executable)
ls -li If the file is the first column, then this command prints the index number
ls -l list with long format (permissions, size, ownership, and modification date)
ls -laF list long format including hidden files
ls -lh list long format list with size displayed using human-readable file units (KB, MB, GB)
ls -ls list with long format with the file size (descending)
ls -r list in reverse order
ls -R list recursively directory tree
ls -s list file size
ls -S sort by file size
ls -t sort by modification time & date โ€“ it will open the last file you edited
ls -X sort by extension name

2- pwd command

As we mentioned,

$ pwd [option]

is one of the basic Linux commands cheat sheets. It can easily print out the current working directory starting from the root. This command has two flags:

Pwd โ€“L

Displays the current working directory logical path with the symbolic link name.

Pwd โ€“P

Displays the current working directory physical path without the symbolic link name.

Linux Hosting Simplified Linux Hosting Simplified

Want a better way to host your websites and web apps? Developing something new? Simply donโ€™t like Windows? Thatโ€™s why we have Linux VPS.

Get your Linux VPS

3- alias

This command lets you instruct a shortcut, or an abbreviation to reference a command (or set of commands) to avoid typing a long command several times. In fact, when you need to use a command over and over, the alias command will be useful. It can save your time by creating a unique command that can replace one string with another while executing the commands. This shortcut can be used multiple times. In this case, we create something called an alias for that command.

The syntax of this command is:

alias [-p] [name [=value] โ€ฆ]

Or, it can be something like this:

alias alias_name="command_to_run"

4- cd command

This command will change your current directory in Linux and other Unix-like operating systems. In other words, the cd (short for Change Directory) command is one of the most frequently used and one of the basic Linux commands that is used on the Linux terminal. The syntax for this command is:

cd [options] directory

Here is a few examples of using this command:

Assuming that the Downloads directory exists in your home directory. Using the following code, you can simply navigate to it:

cd Downloads

You can also navigate to it by using the absolute path:

cd /home/username/Downloads

As you can see (/) sign shows the absolute path to the directory. You can also navigate one or more levels up from the current directory. To do so, suppose you are currently in the

/home/username/Downloads

directory, to switch to the

/home/username

directory (one level up), you would type:

cd . ./

This command moves you one level up from the current directory.

/home

To move two levels up to the directory, you could run the following code:

cd . ./ . ./

You can also navigate to the previous working directory using a dash character as an argument to the cd command like the following:

cd -

Or navigate to the home directory by using a tilde (~), as shown below:

cd ~

For example, if you want to navigate from

/home/username/Downloads

directory to the

/home

directory, you would type:

cd ~/Downloads

Note: if the selected directory has a space in its name, you should use backslash (\) character to escape the space, as shown below:

cd Dir\beta\router\hosting
READ
Debian vs Ubuntu: Whatโ€™s the Right Linux Distro for You?

5-mv command

This command is used to move one or more files or directories from one place to another. Following is the syntax of this Linux basic command with a few examples:

mv [option] SOURCE DESTINATION

The SOURCE can be one or more directories or files, and the DESTINATION must be a single directory or file. To move a directory or file, you need to write permissions on both SOURCE and DESTINATION. Otherwise, you will receive a permission denied error.

If you want to just rename a file, type the following syntax:

mv [filename] [new_filename]

For example:

mv names.txt fullnames.txt

Similarly, if you want to move a file to a new location, use the following syntax:

mv [filename] [dest-dir]

For example:

mv fullnames.txt /home/routerhosting1/Downloads

You can force the mv command to prompt by using the โ€“i command-line option:

mv -i [filename] [new_filename]

This syntax leads to mv asking for user permission before overwriting an existing file.

Linux Hosting Simplified Linux Hosting Simplified

Want a better way to host your websites and web apps? Developing something new? Simply donโ€™t like Windows? Thatโ€™s why we have Linux VPS.

Get your Linux VPS

6- cat command

The cat (short for concatenate) command is one of the most frequently used and one of the basic Linux commands that allows users to create single or multiple files, concatenate files, view contents of files, and redirect outputs in files or terminals. The typical syntax of this command is something like this:

cat [option] [file] . . .

Example:

cat /123456/test/file01/123456/test/file02

The following table shows the main options for using the cat command:

option description
cat test Displays the contents of a file
cat test1 test2 Displays the contents of test1 and test2
cat test1; teat2; test3 Displays multiple files at once
cat -b adds line numbers to non-blank lines
cat -n filename Shows contents and adds line numbers to all lines
cat -s Squeezes blank lines to one line
cat -e Shows $ at the end of the line. Good for squeezing multiple lines in a single line
cat โ€“T test shows ^I instead of tabs
cat test1 teat2 test3 > test4 Redirecting multiple fileโ€™s contents in a single file
cat > test1 Will create a file named test1
cat test1 >> test2 Will append the contents of one file to the end of another file

7- cp command

The cp command stands for COPY. This command can copy a single or a group of files or directories. It requires at least two filenames in its argument. Syntax of this command can be something like the following:

cp [option] Source Destination
cp [option] Source Directory
cp [option] Source-1 Source-2 Source-3 Source-n Directory

The first and second syntax is used for copying the source file to the destination or directory. The third syntax is used for copying multiple files (sources) to the directory.

Example 1:

cp file file-backup

This code will copy a file named file.txt to file-backup.txt.

Example 2:

cp file1.txt dir file2.txt dir

This code will copy multiple files and directories at once. In this case, the destination must be a directory.

READ
CentOS vs Ubuntu 2022: Choose Your Destiny ๐Ÿ‘จโ€๐Ÿ’ป

8- mkdir command

This Linux command allows users to make new directories. With mkdir command, you can also set permissions, and create multiple folders at once. The syntax of this command for making a single directory is something like this:

mkdir [option] dir-name

Example:

mkdir test-dir

This command will create a new directory named test. If you wish to create multiple directories at once, use the following syntax:

mkdir {test1, test2, test3}

9- rmdir command

Another command of our provided Linux basic commands list is rmdir which allows you to remove empty directories from the filesystem in Linux. The syntax of this command is shown in the following:

rmdir [-p] [-v ว€ -verbose] [-ignore โ€“ fail โ€“ on โ€“ non โ€“ empty] directories โ€ฆ

Options:

In the

rmdir โ€“p

each of directories

Example:

rmdir mydir1 mydir2 mydir3

In this example, mydir1, mydir2, and mydir3 will be removed, if they are empty. If any of these directories are not empty, then an error message will be printed for that directory and other directories will not be removed.

Options:

  • rmdir โ€“p: Each of the directory arguments is treated as a pathname that will be removed, in this option. If they are empty, the last component will start.
  • rmdir โ€“v, -verbose: this option can display verbose information for each directory that is being processed.
  • rmdir -ignore โ€“ fail โ€“ on โ€“ non โ€“ empty: if a directory isnโ€™t empty, this option will not report an error message for occurred failure.
  • rmdir โ€“version: this option is used for displaying the version information and exit.

Also Read: How to delete a directory in Linux?

10- rm command

When you are going to remove directories and the contents within them, the rm command is the solution. But, if you only want to delete the directory, use rm โ€“r. The syntax is something like the following short-code:

rm [option] FILE

Example:

rm test.txt

This command will permanently remove the test.txt directory.

11- Touch command

The touch command is known as another Linux basic command that lets you create a new blank file.

Syntax: touch file_name

touch

Example: touch ย /Home /username/Documents/Me.txt

This command creates a single text file in the destination address (documents). If you want to create multiple files in a particular destination.

Syntax: touch File1_name File2_name File3_name

Options:

touch โ€“a: This command can change access time to a specific file. It is recommended toย  modify or update the last access times of a file

12- Locate command

Locate command acts as a search command in windows. It is the easiest way to search the files by names or even not know the exact name.

Syntax: locate [filename]

locate

Example:

Locate{ -i Book*note}ย 

This command finds files with the words โ€œbookโ€ and โ€œnote,โ€ whether uppercase or lowercase.

READ
List Running Services on Linux:(Ubuntu,Debian,CentOS)

13- df command

The Df command stands for โ€œDisk Free,โ€ which gives you the system detail as a report, such as the amount of disk, space, and usage.

To view the readable disk space summary, you can receive it in bytes, megabytes, and gigabyte format.

E.g.: MegaBytes:

df -m

Syntax:

  • df
  • df /dir
  • df [option] [/dev/DEVICE]

14- Kill command

Kill command helps you to collapse unresponsive programs; however, it is possible to terminate programs manually.

ย Syntax:

kill [signal option]
kill PID

Example:

There are two common signals with kill command that users most use:ย 

SIGKILL: This signal forces all programs to be terminated as soon as possible, and this sudden stop wonโ€™t save program changes

SIGTERM: This type of signal causes a program to stop running, but unlike SIGKILL, it lets the program save all of the changes.ย 

15- useradd, userdel command

Multi-users operating system(Linux) provides multiple user access simultaneously. Thus creating multiple users is necessary to interact with the system.

Useradd:ย This command creates a new user, and Passwd is used to set the password for this user account.

Syntax: useradd [OPTIONS] USERNAME

Example:

useradd JohnSmith

Userdl: deleting a user account means removing the user and its files. This command acts the same as creating a user with a little change.

Syntax: userdel UserName

Example:

userdel JohnSmith

Options:

userdel โ€“f: This option will force the user removalย 

userdel โ€“r: This command deletes a user with the home directory and its files plus the userโ€™s mail spool.

Example:

  • userdel -f Jack
  • userdel -r John
READ
Best Linux System Monitoring Tools in 2023 ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿ’ป

 

How to Practice Basic Linux Commands?

No matter you want to test /analyze your shell scripts online or want to practice basic Linux commands, you should first understand them well. To practice them, you can install Linux inside Windows using Windows Subsystem for Linux. You can also use online Linux terminals. Some websites provide you with online Linux terminals to run regular Linux commands in a web browser so that you can test them or practice them.

Conclusion

Linux includes a large number of commands but weโ€™ve chosen the most frequently needed commands for you. In this article, we explained some of the basic Linux commands with examples of coding. However, the steps may differ based on the distributions that youโ€™re using; you can use the help of the Linux, or even comment us to help you.

FAQ

What Is the Difference Between pwd and /bin/pwd?

The pwd is a built-in command in the shell while /bin/pwd is a tool that comes with your Linux distribution. To specify that you want to run the stand-alone program instead of the shell built-in command, use /bin/pwd.

How Do I Run Commands in Linux?

First, launch a terminal from your desktopโ€™s application menu. Then try to find the bash shell that is the default shell in most Linux distributions. Now, type a command and press enter to run it.

What Does CLI mean?

A Command Line Interface (CLI) is a text-based interface used for typing and running commands. Before the Mouse, it was the standard way to interact with a computer. Every CLI has a command prompt for accepting a command.

What Is the Use of Command-Line?

The best use of the command line is that it takes a lot of commands. This interface helps you to enter a command that can pass on to the operating system of your computer and run. Using the command line, you can also navigate through the files and folders of your device.

What Is a Linux Cheat Sheet?

There are hundreds of Linux commands that you may need to know. A Linux Cheat Sheet can help you to easily find and remember them. Such a sheet can show you commands related to the following information:

  • System information
  • Hardware information
  • Performance monitoring and statistics
  • User information and management
  • File and directory commands
  • Process management
  • File permissions
An SEO-Specialist who loves digital marketing and has a background in creating content. Matt loves teamwork and enjoys working with professional people. He always tries to bring more things to the team.

Comments

Latest Posts