Advance

Useful Linux Commands

Useful Linux Commands
1
(1)

The terminal environment is the Linux command line. If you are currently in a graphical environment, the easiest way to bring the terminal is to use the Ctr + Alt + T keys, which are supported in all distributions. There are other ways, such as using the Ctr + Alt + F6 keys (use the Ctrl + Alt + F7 keys to exit) that bring you to the main command line environment. In this article, we are going to explain 25 practical commands of useful Linux commands. Stay with us.

25 Useful Linux Commands

In this article, we are going to review some useful and frequently used Linux or Unix instructions for Linux system administrators that are used in their daily lives. These are not all commands, but a complete list of commands to refer to if needed. Let’s start uniformly with how we can use these commands with examples.

Recommended Article: Install WordPress with LEMP on Ubuntu 18.04

1. Uptime

The uptime command indicates when the system is turned on and the number of users currently logged in, as well as the average load for 1.5 and 15 minutes.

uptime  08:16:26 up 22 min, 1 user, load average: 0.00, 0.03, 0.22

2. W

This command indicates which users are currently logged in. Also shows username, TTY name, remote host, login time, idle time, JCPU, PCPU, command and process.

Options :

-h: does not display any header input

-s: No JCPU and PCPU

-f: Delete field

-V: (capital letters) – Shows versions.

3. Users

Display users who are currently connected to the system.

users  tecmint

4. WHO

The WHO command simply displays the username, date, time and host information. Is the WHO command similar to the w command? Unlike the w command, the WHO command does not print the user’s work.

who  tecmint pts/0 2012-09-18 07:59 (192.168.50.1)

5. WHOAMI

The Whoami command prints the current user name. You can also use the “who am i” command to display the current user. If you are logged in as root, use the sudo command to open the “whoami” root as the current user.

If you want to know the exact login user, use the “Who am I” command.

whoami  tecmint

6. LS

LS command displays a list of files in human readable format.

ls -l  total 114  dr-xr-xr-x. 2 root root 4096 Sep 18 08:46 bin  dr-xr-xr-x. 5 root root 1024 Sep 8 15:49 boot    

7. Crontab

The to-do list is printed for the current user with the crontab command and the -l option.

crontab -l  00 10 * * * /bin/ls >/ls.txt

Edit your crontab with the -e option. In the following example, open the program tasks in the vi editor. Make the necessary changes and exit the editor, which saves the settings automatically.

crontab -e

8. LESS

The less command displays the print of the files as a page and exits the window with the ‘q’ key.

less install.log  Installing setup-2.8.14-10.el6.noarch  warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY  Installing filesystem-2.4.30-2.1.el6.i686  Installing ca-certificates-2010.63-3.el6.noarch  Installing xml-common-0.6.3-32.el6.noarch  Installing tzdata-2010l-1.el6.noarch  Installing iso-codes-3.16-2.el6.noarch

9. MORE

This command works the same as the less command.

more install.log  Installing setup-2.8.14-10.el6.noarch  warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY  Installing filesystem-2.4.30-2.1.el6.i686  Installing ca-certificates-2010.63-3.el6.noarch  Installing xml-common-0.6.3-32.el6.noarch  Installing tzdata-2010l-1.el6.noarch  Installing iso-codes-3.16-2.el6.noarch  --More--(10%)

10. CP

Used to copy files.

cp -p fileA fileB

11. MV

Used to rename the file or move the file completely to another path.

mv -i fileA fileB

12. CAT

This command is for printing a file in STDOUT.

cat fileA fileB

If the file is large and has many pages, you can use the LESS and MORE commands described above for printing.

cat install.log | less  cat install.log | more

13. CD (Change Directory)

With this command you can move between directories.

cd /fileA

14. PWD

This command displays the current directory.

pwd  /root

15. Sort

Sort the lines of text files in ascending order. Arrange with -r options in descending order.

sort fileA.txt  sort -r fileA.txt

16. VI

It is one of the most popular text editors in Linux.

vi -R /etc/shadows

17. SSH (Secure Shell)

The SSH command is used to log in to the remote host. For example, the following command ssh connects to the remote host (192.168.50.2) using the user as narad.

ssh [email protected]

18. FTP and SFTP

The ftp or sftp command is used to connect to the ftp remote host. ftp (file transfer protocol) and sftp (secure file transfer protocol). For example, the following commands connect to the host FTP (192.168.50.2).

ftp 192.168.50.2  sftp 192.168.50.2

Placing multiple files on the remote host is done with the mput command. Also, by entering the mget command, several files are downloaded from the remote host.

ftp > mput *.txt  ftp > mget *.txt

19. Service

The Service command executes scripts located in the /etc/init.d/ directory. There are two ways to start each service. For example, we start the httpd service with the service command.

service httpd start  OR  /etc/init.d/httpd start

20. Free

Displays empty and occupied memory space and SWAP.

free              total          used        free   shared     buffers     cached  Mem:      1030800        735944      294856        0       51648     547696  -/+ buffers/cache:       136600      894200  Swap:      2064376            0     2064376

21. Command

This command is used to compress files.

tar -cvf archive-name.tar /home

22. Grep

grep is a search for a given string in a file or output of a command. We can use the -i option to ignore case sensitivity.

grep tecmint /etc/passwd  tecmint:x:500:500::/home/tecmint:/bin/bash

23. Find

This command is used to search for files, texts, and directories.

find / -name tecmint  /var/spool/mail/tecmint  /home/tecmint  /root/home/tecmint

24. RM

This command is used to delete files.

rm filename

Using the -i option allows you to get confirmation before deleting the file.

rm -i test.txt  rm: remove regular file `test.txt'?

25. mkdir

Used to build directories.

mkdir directoryname    
Recommended Article: Setting Up Time Synchronization On Debian 10

Conclusion

25 of the most useful Linux commands were taught in this article.

How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

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

10 thoughts on “Useful Linux Commands

    1. Use the lvextend command (lvextend -L +100M /dev/, in this example we are extending the size by 100MB.
      – resize2fs/dev/

      – check the size of partition using df -h command.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

+8595670151

7 days a week, 24 hours a day