Saturday, August 13, 2011

Linux Commands - uniq,tee and who


This is another sequel to my previous posts regarding the Linux commands. In this post, I want to explain the uniq, tee and who commands.

Uniq

This  command is used to handle the duplicates in the file content. Suppose I have a file a.text.

$ cat a.text 
Condemned
Condemned
Underworld
Underworld
Vantage point
Toy Story
Toy Story 2

Now use uniq command to display the uniq lines only.

$ uniq a.text 
Condemned
Underworld
Vantage point
Toy Story
Toy Story 2

If we want see only the lines that are not duplicated, use -u flag.

$ uniq -u a.text 
Vantage point
Toy Story
Toy Story 2

If we want to avoid the non duplicated lines, that is opposite to the previous one, use -d flag.

$ uniq -d a.text 
Condemned
Underworld

If want to set a counter on each lines that denotes how much times each line is displayed, use the -c flag.

$ uniq -c a.text 
      2 Condemned
      2 Underworld
      1 Vantage point
      1 Toy Story
      1 Toy Story 2

Tee

tee is normally used to split the output of a program so that it can be seen on the display and also be saved in a file. The command can also be used to capture intermediate output before the data is altered by another command or program.

Run the following command to get a directory listing on your terminal, while also redirecting the output to a file named b.text.

$ ls -al | tee b.text

Who

If you want to know which users are currently logged in to your Linux system, which console they're using, and the date and time they logged in, use the who command.

$ who
ajay     tty7         2011-08-12 13:45 (:0)
ajay     pts/0        2011-08-12 13:46 (:0.0)

In the output shown here, the term tty stands for teletype. In the olden days of computing, a terminal was just a keyboard with an attached printer, so you read everything off the teletype.

If you've logged in with multiple virtual consoles and changed your identity on any of them, you may have some trouble figuring out who you are--or at least what user is logged in to the console you're using. If you find yourself in such an identity crisis, try this related command,

$ whoami
ajay

Thanks

AJAY

Linux Commands - cat,tac,head and tail

In this post, I want to show some file displaying commands that are very useful.

Cat

cat command is used to display the contents of a file in the terminal.

$ cat a.text 
Hi friends, I'm Ajay.
Here I'm posting about my MCA main project.

Tac

tac is same as cat, but shows the content of the file in reverse order.

$ tac a.text 
Here I'm posting about my MCA main project.
Hi friends, I'm Ajay.

Head

head is another file content display command, but having some advanced controls.

$ head a.text 

It will display first 10 lines of a file.

$ head -1 a.text 

It will display first line of the file.

Tail

The tail is opposite to the head command. 

$ tail a.text

It shows the last 10 lines of the file. If you want to see the last line of the file, type,

$ tail -1 a.text

So in our example file head and tail works as follows,

$ head -1 a.text 
Hi friends, I'm Ajay.

$ tail -1 a.text 
Here I'm posting about my MCA main project.

We can also save the output to another file using '>'

$ tail -1 a.text > b.text

Thanks

AJAY

Friday, August 12, 2011

Setting background in Terminal


I have showed you hoe to change the default start up of terminal by customizing the .bashrc file. In this post I want to show you how to change the font,background etc of the terminal.
We can set them without the use of Linux commands. Open your terminal and select Edit->Profiles. There you have an option to set the new profile name. After giving a proper name you can edit the profile as you want.

You can change the font under General tab. You can also edit the cursor type. In Title and Command tab, you can edit the default title name 'Terminal' to whatever you like. On the Colors tab you can edit the foreground and background colors.

Now click on the Background tab. Here you can set an image in your system as your terminal background. Also set the transparency level. Select your customized profile by selecting Terminal->Change Profile in the menu bar. Now your terminal have entirely different look!!! Look at my customized terminal.


Thanks

AJAY