Ten little-known Linux commands - [3]

22. ^foo^bar command

Run the last modified command in an instance. Suppose I need to run a command'ls-l'to list in detail the contents of the'Desktop' directory. Unexpectedly, you hit'lls-l'. So you need to retype the entire command or use the navigation key to edit the previous command. This is painful when your orders are long.

avi@localhost:~/Desktop$ lls -l 
bash: lls: command not found

avi@localhost:~/Desktop$ ^lls^ls 

ls -l 
total 7489440 

drwxr-xr-x 2 avi  avi       36864 Nov 13  2012 101MSDCF 
-rw-r--r-- 1 avi  avi      206833 Nov  5 15:27 1.jpg 
-rw-r--r-- 1 avi  avi      158951 Nov  5 15:27 2.jpg 
-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc

Note: In the above substitution, we use "typo (replaced) original_command (original command)". Warning! This command can be very dangerous! If you consciously or unintentionally mistyped system commands or any risky commands like rm-rf!

23. > file.txt command

This command refreshes the contents of the file without deleting it and then creates the same file. This command is very useful when we need to output repeatedly or log on the same file.

I have a'test.txt'file with a lot of text on my'Desktop'.

avi@localhost:~/Desktop$ cat test.txt 

Linux 
GNU 
Debian 
Fedora 
kali 
ubuntu 
git 
Linus 
Torvalds


avi@localhost:~/Desktop$ > test.txt 
avi@localhost:~/Desktop$ cat test.txt

Note: Again, this command can be dangerous! Never try to refresh the contents of a system file or a log file. If you do this, you may encounter serious problems!

24. at command

'at'command and cron command Similarity can also be used to schedule a task or to execute commands at a specific time.

avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" | at 14:012

or

avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" | at 2:12 PM

Example output

-rw-r--r-- 1 avi  avi      220492 Nov  1 13:49 Screenshot-1.png 
-rw-r--r-- 1 root root        358 Oct 17 10:11 sources.list 
-rw-r--r-- 1 avi  avi  4695982080 Oct 10 20:29 squeeze.iso 
..
..
-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc 
-rw-r--r-- 1 avi  avi       96206 Nov  5 12:56 Untitled 1.odt 
-rw-r--r-- 1 avi  avi        9405 Nov 12 23:22 Untitled.png

Note: echo "ls-l" means to output these commands (ls-l in this case) to a standard terminal. You can replace'ls-l'with commands you need or choose.

> Redirected output

/ dev/pts/0: This is the output device and/or file, which is output to the specified place, where output is at the terminal (/dev/pts/0).

For me, my tty is at / dev/pts/0. You can check your tty with the tty command.

avi@localhost:~/Desktop$ tty 

/dev/pts/0

Note:'at'will be executed as soon as the system time matches a specific time.

25. du-h-max-depth=1 command

The following command outputs the size of the subdirectory of the current directory in a human-readable form.

avi@localhost:/home/avi/Desktop# du -h --max-depth=1 

38M     ./test 
1.1G    ./shivji 
42M     ./drupal 
6.9G    ./101MSDCF 
16G .

Note: The above command is Check system utilization It's very useful.

26. expr command

'expr'is not such a little-known command. This command is very useful when calculating simple arithmetic in the terminal.

avi@localhost:/home/avi/Desktop# expr 2 + 3 
5

avi@localhost:/home/avi/Desktop# expr 6 – 3 
3

avi@localhost:/home/avi/Desktop# expr 12 / 3 
4

avi@localhost:/home/avi/Desktop# expr 2 \* 9 
18

27. look command

Look up the words from the English dictionary on the terminal to avoid confusion. For example, I can't remember whether to spell carrier or carier.

avi@localhost:/home/avi/Documents# look car

Cara 
Cara's 
...
... 
carps 
carpus 
carpus's 
carrel 
carrel's 
carrels 
carriage 
carriage's 
carriages 
carriageway 
carriageway's 
carried 
carrier 
carrier's 
carriers 
carries 
...
... 
caryatids

The command above shows all the words in the dictionary that begin with'car'. I got what I wanted.

28. yes command

Another command is not often used on a regular basis, but is very useful in scripting languages and system management.

This command will continue to output the given string until interrupted by your interrupt command.

avi@localhost:~/Desktop$ yes "Tecmint is one of the best site dedicated to Linux, how to" 

Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
...
...
...
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to

29. factor command

factor is actually a command derived from mathematics. This command outputs the factors of all given numbers.

avi@localhost:~/Desktop$ factor 22 
22: 2 11

avi@localhost:~/Desktop$ factor 21 
21: 3 7

avi@localhost:~/Desktop$ factor 11 
11: 11

30. ping -i 60 -a IP_address

We all use the ping command to detect whether the server is connected. I usually ping google to check if I'm connected to the Internet.

Sometimes it's annoying when you wait or keep staring at your terminal waiting for a command response or a connection to the server.

How about a voice once the server is connected?

avi@localhost:~/Desktop$ ping -i 60 -a www.google.com 

PING www.google.com (74.125.200.103) 56(84) bytes of data. 
64 bytes from www.google.com (74.125.200.103): icmp_req=1 ttl=44 time=105 ms 
64 bytes from 74.125.200.103: icmp_req=2 ttl=44 time=281 ms

Note that when you find that the command does not return sound. Make sure that your system is not silent. Sounds are enabled in'sound preferences'and that'Enable window and window sound' is checked.

31. tac command

This command is interesting. It will output the contents of the text file in reverse order. That's from the last line to the first line.

In the home directory, there is a 35.txt file in my Documents directory. use cat command Check content.

avi@localhost:~/Documents$ cat 35.txt

Example output

Linux is built with certain powerful tools, which are unavailable in windows.
One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it's Linux Counterpart.
Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.

 

Now invert the file content with the tac command.

avi@localhost:~/Documents$ tac 35.txt 

Example output

Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.

One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it's Linux Counterpart.

Linux is built with certain powerful tools, which are unavailable in windows.

 

It's over now.

Tags: Linux Google Windows shell

Posted on Wed, 11 Sep 2019 23:22:43 -0700 by elhama