Less Popular But Useful Linux Commands

By | 20/06/2013

Linux fold command

The fold command fits a bulky paragraphed text file into the specified width. As for example, we have following text file named “thefile”

MyLinuxBook is a blog dedicated to Linux. Here, we present our views/research/knowledge in terms of easy to comprehend articles and tutorials.

We wrap the above textfile into a text with width = 50.

$ fold -10 thefile

And this is what I get on the standard output

MyLinuxBoo
k is a blo
g dedicate
d to Linux
. Here, we
 present o
ur views/r
esearch/kn
owledge in
 terms of 
easy to co
mprehend a
rticles an
d tutorial
s.

The newly formatted wrapped text can also be re-directed to another file as

$ fold -50 thefile > newfile

Know more about ‘fold’ command and its options through its <ahref=http://linux.die.net/man/1/fold>man page .

Linux tac command

In the literal sense, the ‘tac’ command comes as a reverse of ‘cat’. As its name suggests, it reverses the contents of a file line by line and concatenates all the text in case of multiple input files. Hence, the last line of the input text file will become the first line of the output. The output is directed to the standard output which can be re-directed to a file if the linux user feels like. To see how that works, lets have a lined text input file- colors, which looks as

1 Violet
2 Indigo
3 Blue
4 Green
5 Yellow
6 Orange
7 Red

To reverse the content of the file colors, we do

$ tac colors

And we get the output as

7 Red
6 Orange
5 Yellow
4 Green
3 Blue
2 Indigo
1 Violet

Redirect it to another file as

$ tac colors >revcolors

Linux w command

I find this ‘w’ command as pretty intriguing. It tells the users who have currently logged onto a system and what are they doing. By what they are doing, we imply the process the user is running at the moment. Trying it out, I run

$ w

I get following output on my system,

14:33:47 up 1 day, 12:36, 3 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
himanshu pts/0 :1014.0 Sat02 1.00s 1.28s 60.08s gnome-terminal
rupali pts/1 :1015.0 Sat08 5:41m 2.69s 1:05 gnome-terminal
rupali pts/2 :1015.0 08:23 6:03m 2.16s 1:05 gnome-terminal

Its not that difficult to understand the w command output is telling us that three users have currently logged into the system. Each of the column can be described as:

  • USER : The user name
  • TTY : The controlling terminal
  • FROM : Remote machine address
  • LOGIN@ : The time user logged in at
  • IDLE : The Idle time
  • JCPU : The time used by all processes attached to TTY
  • PCPU : The time used by current process attached to TTY
  • WHAT : The current process of this user

Running the w command without any option gives the most detailed output.

Linux htop command

The htop linux utility is very similar in functionality to the ‘top’ linux command. However, htop is just with certain better user interactivity and presentation adding the mouse support. Therefore, with htop, we can interactively monitor running processes in a system. The htop utility doesn’t come bundled along with the ubuntu, and has to be installed explicitly.

$ sudo apt-get install htop

After installing, running it is pretty simple

$ htop

One gets a screen which looks as follows:

htop

 

 

 

 

 

 

 

 

 

 

It is a dynamic snapshot of the running processes and keeps on changing as the runtime dynamics changes. It has the processor and memory statuses. Very interesting feature is one can navigate through the processes in the displayed list, select one and kill it by pressing F9 without the need to run an extra command. Similarly other modifications can be done in the same screen to any selected process. More detailed knowledge about htop usability can be found here .

Linux write command

A very common setup with the multi-user support is, lot of people working on the same linux machine through various available remotely working options. However all these users of the linux system may be working on a relevant project or team, or even if not related, they belong to the same working place. Hence, quite plausible, they may need to communicate at any point of time. With the Linux write utility, the linux users have a feasible and most convenient way to communicate to each other. I can send a message to any other logged user to my linux machine. Moreover, I can send messages to any user in the same network, even on a different host machine. The syntax looks like

write person

Here person is the username if it is on the same host machine and username@hostname in case the user belongs to a different host machine is needed to identify in case one user is logged in more than one time. At the moment, lets just see how sending messages work among the users of the same machine. In our example case, let me see who all are logged in to my system through

$ w -s

I see following three users logged in including me (I am rupali)

$ w -s
16:07:53 up 1 day, 14:10, 3 users, load average: 0.00, 0.01, 0.05
USER TTY FROM IDLE WHAT
rupali pts/0 :1014.0 0.00s w -s
ubuntu pts/1 :1015.0 7:15m gnome-terminal
himanshu pts/2 :1015.0 7:37m gnome-terminal

Now, let me send a message to himanshu as

$ write himanshu

Once I press enter, the command prompt allows me to write messages which will be passed on to the recipient user.

Hello Himanshu,
Are you running a high memory process? 
Also can you please free some memory from the data drive?
Thanks.

This is what Himanshu sees at his terminal.

$
Message from rupali@home-OptiPlex-745 on pts/0 at 16:21 ...
Hello Himanshu,
Are you running a high memory process? 
Also can you please free some memory from the data drive?
Thanks
EOF

Explore more about write utility from here.

Linux wall command

The wall command is used to broadcast a message to all the users of the system. However, to receive this broadcasted message, the users need to set their mesg permission to yes. The usage is pretty straightforward, which can be easily grasped through the following example

$ wall 
This is an announcement to save your work as admin is doing a reset.

Note, once your message is complete, end it by the key combination ‘CTRL + D’. This is how all other users receive the broadcasted message

Broadcast Message from rupali@home-OptiPlex-745 
(/dev/pts/0) at 16:40 ... 
This is an announcement to save your work as admin is doing a reset.

Linux espeak command

The espeak command is an amazing command which lets the system speak a message for you. Try out following and the linux will speak it out for you.

$ espeak “Linux is fun”.

Leave a Reply

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