Advance

10 useful Linux Command Line Tricks For Newbies

10 useful Linux command Line tricks for Newbies

Tutorial 10 useful Linux command Line tricks for Newbies. A Linux system administrator needs to know some Linux tricks. Have a look at Eldernode services and buy your own Linux VPS. You should have realized that how beauty, flexibility, and usability are the Linux terminal, and to be honest a day doesn’t pass without using. So let’s review some useful tricks and tips for Linux newcomers to ease their transition to Linux or simply help them learn something new.

10 useful Linux Command Line Tricks For Newbies

In this tutorial, we will show you some useful tricks on how to use the Linux terminal like a pro with a minimum amount of skills. All you need is a Linux terminal and some free time to test these 10 useful Linux command Line tricks for Newbies.

Recommended Article: How to Install Samba on Linux/Windows

1- How To Find The right command

You are aware that execute the right command can be vital for your system. However, in Linux, there are so many different command lines that they are often hard to remember. So how do you search for the right command you need? The answer is apropos. All you need to run is:

apropos <description>

Where you should change the “description” with the actual description of the command you are looking for. Have a look at this example:

apropos "list directory"    dir (1) - list directory contents  ls (1) - list directory contents  ntfsls (8) - list directory contents on an NTFS filesystem  vdir (1) - list directory contents

Note: On the left, you can see the commands and on the right their description.

 

2- How To Execute The Previous Command

You will need to execute the same command over and over again many times. While you can repeatedly press the Up key on your keyboard, you can use the history command instead. To list all commands you entered since you launched the terminal:

history        1  fdisk -l      2  apt-get install gnome-paint      3  hostname tecmint.com      4  hostnamectl tecmint.com      5  man hostnamectl       6  hostnamectl --set-hostname tecmint.com      7  hostnamectl -set-hostname tecmint.com      8  hostnamectl set-hostname tecmint.com      9  mount -t "ntfs" -o     10  fdisk -l     11  mount -t ntfs-3g /dev/sda5 /mnt     12  mount -t rw ntfs-3g /dev/sda5 /mnt     13  mount -t -rw ntfs-3g /dev/sda5 /mnt     14  mount -t ntfs-3g /dev/sda5 /mnt     15  mount man     16  man mount     17  mount -t -o ntfs-3g /dev/sda5 /mnt     18  mount -o ntfs-3g /dev/sda5 /mnt     19  mount -ro ntfs-3g /dev/sda5 /mnt     20  cd /mnt     ...

After receiving a list of all commands that you have run, on each line, you have a number indicating the row in which you have entered the command. You can recall that command by using:

!  

Where # should be changed with the actual number of the command. So let’s verify the example below for better understanding:

!501    

3- How To Use midnight Commander

In this step, we explain how to use the midnight command, if you are not used to using commands such as cdcpmvrm. It is easy to use the visual shell in which you can also use the mouse.

By the F1 – F12 keys, you can easily perform different tasks. Simply check the legend at the bottom. To select a file or folder click the “Insert” button.

Then, the midnight command is called “mc“. To install mc on your system simply run:

sudo apt-get install mc        [On Debian based systems]
yum install mc                 [On Fedora based systems]

And you can Open mc by simply typing:

mc

Next, use the TAB button to switch between windows – left and right. you have a LibreOffice file that I will move to the “Software” folder.

Press the F6 button on your keyboard to move the file to the new directory. MC will now ask you for confirmation.

Point: You will move the file to the new destination directory when you confirm it

 

4- How To Shutdown Computer At Specific Time

As you guess, sometimes you will need to shut down your computer some hours after your work hours have ended. You can configure your computer to shut down at a specific time by using:

sudo shutdown 21:00

In case you need to tell your computer to shut down at the specific time you have provided, you can also tell the system to shut down after a specific amount of minutes:

sudo shutdown +15

Point: That way the system will shut down in 15 minutes.

 

5- How To Show Information About Known Users

To use a simple command to list your Linux system users and some basic information about them:

lslogins

Output

UID USER PWD-LOCK PWD-DENY LAST-LOGIN GECOS  0 root 0 0 Apr29/11:35 root  1 bin 0 1 bin  2 daemon 0 1 daemon  3 adm 0 1 adm  4 lp 0 1 lp  5 sync 0 1 sync  6 shutdown 0 1 Jul19/10:04 shutdown  7 halt 0 1 halt  8 mail 0 1 mail  10 uucp 0 1 uucp  11 operator 0 1 operator  12 games 0 1 games  13 gopher 0 1 gopher  14 ftp 0 1 FTP User  23 squid 0 1  25 named 0 1 Named  27 mysql 0 1 MySQL Server  47 mailnull 0 1  48 apache 0 1 Apache  ...

 

6- How To Search For Files

Searching for files can sometimes be not as easy as you think. A good example for searching for files is:

find /home/user -type f

You can use the following command to search for all files located in /home/user. The find command is an extremely powerful one and you can pass more options to it to make your search even more detailed.

Also if you want to search for files larger than a given size, you can use:

find . -type f -size 10M

Since the above command will search from the current directory for all files that are larger than 10 MB, make sure not to run the command from the root directory of your Linux system as this may cause high I/O on your machine.

One of the most frequently used combinations that you can use find with is “exec” option, which basically allows you to run some actions on the results of the find command.

For example, let’s say that you want to find all files in a directory and change their permissions. This can be easily done with:

find /home/user/files/ -type f -exec chmod 644 {} \;

By typing the above command, it will search for all files in the specified directory recursively and will execute chmod command on the found files.

7- How To Build Directory Trees With One Command

Also, you can create new directories by using the mkdir command. So if you want to create a new folder you will run something like this:

mkdir new_folder

Any time you need to create 5 subfolders within that folder, Run mkdir 5 times in a row is not a good solution. Instead, you can use -p option like that:

mkdir -p new_folder/{folder_1,folder_2,folder_3,folder_4,folder_5}  

And finally, in the end, you should have 5 folders located in new_folder:

ls new_folder/    folder_1 folder_2 folder_3 folder_4 folder_5      

8- How To Copy File Into Multiple Directories

File copying is usually performed with the cp command. Copying a file usually looks like this:

cp /path-to-file/my_file.txt /path-to-new-directory/  

And when you need to copy that file in multiple directories:

cp /home/user/my_file.txt /home/user/1  cp /home/user/my_file.txt /home/user/2  cp /home/user/my_file.txt /home/user/3

 

If it is a bit absurd, instead you can solve the problem with a simple one-line command:

echo /home/user/1/ /home/user/2/ /home/user/3/ | xargs -n 1  cp /home/user/my_file.txt

 

9- How To Deleting Larger Files

You would face files that can grow extremely large, where a single log file went over 250 GB large due to poor administrating skills. Removing the file with rm utility might not be sufficient in such cases due to the fact that there is an extremely large amount of data that needs to be removed. The operation will be a “heavy” one and should be avoided. Instead, you can go with a really simple solution:

> /path-to-file/huge_file.log  

Where you will need to change the path and the file names with the exact ones to match your case. The above command will simply write an empty output to the file. In simpler words, it will empty the file without causing high I/O on your system.

 

10- How To Run the Same Command On Multiple Linux Servers

In order to ask in our LinuxSay forum, how to execute a single command to multiple Linux boxes at once using SSH. And have machines IP addresses looking like this:

10.0.0.1  10.0.0.2  10.0.0.3  10.0.0.4  10.0.0.5

Here is a simple solution to this issue. Collect the IP addresses of the servers in one file called list.txt one under other just as shown above. Then you can run:

for in $i(cat list.txt); do ssh [email protected]$i 'bash command'; done  

What you need in the above example is to change “user” with the actual user with which you will be logging and “bash command” with the actual bash command you wish to execute. The method is better working when you are using passwordless authentication with an SSH key to your machines as that way you will not need to enter the password for your user over and over again.

Note: You may need to pass some additional parameters to the SSH command depending on your Linux boxes setup.

Recommended Article: 10 useful Linux Command Line Tricks For Newbies

 

Conclusion

In this article, you learned 10 useful Linux command Line tricks for Newbies. The above examples are really simple ones and I hope they have helped you to find some of the beauty of Linux and how you can easily perform different operations that can take much more time on other operating systems. Also, you can read more on How to Find Out Which Process Listening On A Particular Port.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave Your Comment

Your email address will not be published.

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+18054214518

7 days a week, 24 hours a day