What are the basic and most useful Linux commands you need every day to speed-up your execution?
In this tutorial, I am listing some of the important Linux commands that you will find very useful in your daily work routine.
One of the best things about Linux is that you will find many useful commands. Keeping those commands handy, you feel like doing a lot of things in just a few clicks.
If you get habitat using these useful Linux commands, gradually, your productivity will start increasing.
Without any ado, let’s see.
Note: I will keep this list updated with more of such useful commands as I come across.
Table of Contents
How to sort the files and directory by Time?
The basic command to list all the files and directories inside the current directory path.
$ ls
You can also use the -l option with ls command to get more detail about each file and directory,
$ ls -l
Sample output:
Here,
You can read more about Linux file permission.
In the above output image, you can see that the directories listed are not sorted.
If you want to sort the files by their modification time, you need to run the following command.
$ ls -lrt
Here,
There are many options are available with the “ls” command to use. Refer Linux ls command tool to explore other options.
How to change the Current directory temporarily to execute the command?
Do you want to execute the command in a temporary directory in your bash?
Here is a simple command you can use to change the current directory temporarily and then execute your command.
We all the command to change the directory.
cd <your_directory_path>
After this command, your current directory will be changed permanently. You can check the current directory using pwd
command.
Now, instead of changing directory permanently you can club cd
command with the command you want to execute.
Syntax:
(cd <your_directory_path> && <your_command_to_execute>)
Don’t forget to enclose the commands inside the opening and closing bracket (parenthesis).
Rather than changing your directory, it executes the command in the directory you have mentioned.
Example:
Let check the current directory first.
$ pwd
/home/ani
Change the current directory temporarily and execute the command.
$ (cd /tmp && ls)
It will list out all the files in the /tmp directory.
$ pwd
/home/ani
You can see that the current directory is not changed.
Where you can use this command?
This command is very useful if you writing any script and you want to execute certain commands in a specific directory. You don’t need to change the current directory path.
How to change the permission for all the files in directory and subdirectories?
Sometimes, while running the application you get permission denied issue. There can be multiple scripts in your project directory for which you don’t have permission to execute. Going to each script and giving permission is not convenient. Rather, you can set the permission for all the files in the project directory using a single command.
You can use a simple chmod
command with the R
attribute.
Go to the desired directory and run the following command.
chmod -R 777 *
Here,
777
is numeric mode value to set read, write and execute permissions for all the files in the current directory and subdirectories. (You should give the permission-based on your requirement.)*
is used to apply the changes to all the files.You can learn more about how to calculate file permission values using the chmod calculator.
You can use the free command to check the total, available, cache and free memory in Ubuntu (Linux).
Command:
free -h
The option ‘-h’ is used to print all the memory metrics in a human-readable format.
There are multiple options you can use with the free command.
What are the useful Linux commands you use every day? Please mention in the comment, we will add it to this list.
Keep Wrestling and Start Learning Linux!