10 Most Crucial Commands used in Linux

Linux is one of the most powerful and widely used operating system around. I know you might be unaware, but think of your smartwatch, Android phone, or smart TV. At the core is the Linux kernel which makes it possible for you to interact with them. Unlike 10 years ago, there has been a huge uptake of the Linux system by desktop users and users who are coming from a Windows environment. In this guide, you will learn about 10 of the most crucial commands used in Linux.

Linux distros such as Mint are easy to use and are recommended for beginners. In fact, Zorin OS looks much like a Windows 7 desktop. Some lightweight Linux flavours such as MX Linux make it possible for beginners to run Linux on old systems.  If you are looking forward to making a transition in Linux, you need to learn the very basic commands. These commands will help you to efficiently use your PC or troubleshoot and manage your Linux VPS. Without much further ado, let’s dive in.

1. List Files (ls)

When you are working on the command line, you would most probably want to know the files you have on your filesystem. This is especially important when trying to find your files on a VPS or hidden files on your PC. The ls command lists all the files and directories in the specified directory.

Syntax:

$ ls

10 crucial Linux commands ls command

To list the contents of a  different directory, simply specify the directory path.

$ ls /path/to/directory

 

2. Concatenate (cat)

It is essential to know the contents of a file when you are, especially, troubleshooting your system. But you do not necessarily need to open the files with an editor. Use the Linux cat command to view the contents of a file as shown.

Syntax

$ cat my_file

Linux cat command

OR

$ cat /path/to/file

The cat command can also be used to append contents of one file onto another. For example:

$ cat file1.txt >> file2.txt

Save content to another file using cat command

Finally, you can use the cat command to create a file and add contents into it. Consider the example below:

$ cat  > file3.txt

The above command creates a new file called “file3.txt” and gives you an edit window to type the content of the file. ONce you are done typing, press ctrl + d to save the changes and escape the editor.

3. Change Directory (cd)

Immediately you open your terminal, it will open in the home directory (~). This will, however, be different if you open it from the contextual menu in a specific directory by choosing “open in terminal”.

If you want to run a command in a different location, you should use cd to move to the desired working directory. It will help you avoid typing the file or directory path every time.

To change to a different directory, use the syntax:

$ cd /path/to/directory

To move one directory to a level up run

$ cd ..

 

4. Show your current location on the terminal (pwd)

If you want to know exactly where you are on the terminal, simply invoke the Linux pwd command which gives you the absolute path or the current working directory.

$ pwd

pwd command

5. Create a Directory (mkdir)

When you want to do personal stuff and you do not want to interfere with system files, you can create temporary directories you can use and delete later. Short for make directory, the mkdir command allows you to create directories in your Linux system. To create a directory in your present working directory, run:

$ mkdir folder_name

To create a directory in a different path invoke the command:

$ mkdir /path/to/directory

 

6. Remove an empty directory (rmdir)

The

rmdir

command does the complete opposite of

mkdir

command. Short for remove directory, the command deletes and empty directory. For example, the command shown deletes the directory called dir1.

$ rmdir dir1

 

7.Delete File or Directory (rm)

Once you are through with working on a custom file or directory, and you do not need it again, you should delete it to keep the filesystem clean and save your storage space. rm is a Linux command that helps you to delete files fast.

To delete a file use the syntax:

$ rm filename

To delete a directory alongside all its contents, execute:

$ rm -r  directory_name

The argument -r  is for recursively deleting folders and their contents.

8. Create an Empty File (touch)

Conventionally, touch is a simple command to create an empty file in a directory you specify. For example, to create a file in your current directory, run:

$ touch filename

Additionally, you can create multiple files in a single line as shown.

$ touch file1 file2 file3

The arguments -a, -d, and -m updates the access time, access and modification time, and modification time only respectively. -c checks if your file was created.

9. Copy Files and Directories (cp)

Sometimes, you might want to create a duplicate copy of a file or a directory. To do so on the terminal, use the cp command- short for copy. The command takes the following syntax.

$ cp /path/to/file  /path/to/destination

For example, to copy a file called file1.txt from the current directory to /opt/data/records directory, run the command:

$ cp file1.txt /opt/data/records

To copy a directory, use the -R flag for recursive copying. For example

$ cp -R /data/records/sales  /opt/data/records

10. Move and Rename Files (mv)

When you want to change the location of specific files, use the mv command.

$ mv file1.txt /opt/data

The above command completely moves the file from its present location to the

/opt/data

directory. The mv command can also be used to rename a file as shown:

$ mv file1.txt file2.txt

The file

file1.txt

is renamed to

file2.txt

.

 top command

The top command gives users an overview of how the system is running. You can get intimate details about the system such as the running processes, uptime, load average,  CPU and memory utilization among others. You can get more detailed information about the CPU performance using the cpuinfo command.

The top command really comes in handy when troubleshooting degraded system performance and getting to know the processes gobbling up most of the resources.

$ top

top command

Summing Up

When working on your Linux operating system, you will most likely be working on the command line. Sometimes, the terminal gives you quick and powerful methods to manage your system compared to the graphical methods. These 10 crucial Commands used in Linux will help you get started on your way up as you get to learn about other commands used for extensive system administration purposes. We hope this guide was beneficial and that you now have a decent grasp of the basic Linux commands.