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.
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
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.
-h: does not display any header input
-s: No JCPU and PCPU
-f: Delete field
-V: (capital letters) – Shows versions.
Display users who are currently connected to the system.
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)
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.
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
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.
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
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%)
Used to copy files.
cp -p fileA fileB
Used to rename the file or move the file completely to another path.
mv -i fileA fileB
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.
This command displays the current directory.
Sort the lines of text files in ascending order. Arrange with -r options in descending order.
sort fileA.txt sort -r fileA.txt
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.
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
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
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
This command is used to compress files.
tar -cvf archive-name.tar /home
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
This command is used to search for files, texts, and directories.
find / -name tecmint /var/spool/mail/tecmint /home/tecmint /root/home/tecmint
This command is used to delete files.
Using the -i option allows you to get confirmation before deleting the file.
rm -i test.txt rm: remove regular file `test.txt'?
Used to build directories.
25 of the most useful Linux commands were taught in this article.