Sunday, December 20, 2009

commands #1

i thought it would be nice if i put some commands that i have come across and have liked

1] cat and tac
you might have known by now, cat displays the file content.
tac ?
it displays in reverse

say a "file" has
a
b
c

then cat file prints
a
b
c

while tac file prints
c
b
a

2] uniq
it deletes the multiple entries. this is just a glimpse into this command. suppose you have a list of entries and you sort it. there can be more than one entry for the same value and you want to delete such multiple entries

echo filename|sort -n|uniq #sort -n sorts by name

3] rename
this is by far a very useful command. go for it. i just want to give a small trailer.
say, you are near your final assignment and you have notes [ya, digital notes] from all your friends. but you want to organize all these files into one directory with the name of person who gave you the files in the front

suppose i have you 7 files, logic1.pdf, logic2.pdf ..logic7.pdf
then you want it as
punj_logic1.pdf....punj_logic7.pdf
then in the directory which has only these files, the command is

rename 's/^/punj_/' *
^ means to append punj_ in the front
s means to substitute
it has numerous applications. just have a try

2 comments:

AvK said...

hmm!

!! - Repeat previous command with sudo

^aa^bb -> changes aa to bb and executes the previous command

Two very useful commands .

AvK said...

my mistake ..

!!- Runs previous command
and
sudo !! - Runs previous command as sudo !

Sry!