My top 20 linux favourite commands

Filed Under (Sysadmin) by Amandine on 12-02-2010

Here’s my linux favourite commands, by type :

Scripting
1. egrep : aaah… if I had to keep only one, this would be the one I’d choose… can’t spend 10 minutes without using it.
2. sed : because I always need to replace something by something else 10 times on each line in huge files
3. xargs : helps me avoid the for loop, shorter to write, easier to remember and understand when you find it in history
4. awk : for me the most difficult one to use, but I so know that it can do just what I want that I always take the time.

System
5. kill : ha ha, makes me feel I’m powerful
6. ps fauxww : makes me think I can watch everything that’s happening in real time. Like watching 10 movies at the same time.
7. aptitude : I like his way of telling me everything of what he’s doing… so chatty !
8. dstat : this one is really good : tells me a lot of things and with colors, I think he just knows what I’m looking for each time I call him.

Network
9. ssh : is it necessary to say something about it? without him I’d be nothing.
10. telnet : I like the raw output, no interpretation, he’s stupid and this is sometimes really appreciable
11. host : simple tool for so great usefulness, even the basic usage is perfect
12. nmap : I looove knowing everything about hosts I can’t access…
13. tcpdump : really useful when you really dont understand what’s happening.
14. netstat : nmap from the inside. Feels like a treasure hunt sometimes.
15. mtr : seems just easy and fast, but also gives a lot of interesting information.

Tools
16. vim : makes me save so much time
17. screen : How did they live before screen? And I use only a small amount of its potential…

Storage
18. fdisk : boring in the begenning, fun once you know it by heart
19. sfdisk : really handy to mirror a disk partitionning scheme
20. mdadm : I love mdadm. Just love it, don’t know why.

Time

Filed Under (Tips) by Amandine on 23-09-2009

Today I struggled with the time command.

I wanted to use it in a bash script, so I checked the man page, where I found interesting stuff :

$ man time
time - run programs and summarize system resource usage

SYNOPSIS
time   [ -apqvV ] [ -f FORMAT ] [ -o FILE ]
[ --append ] [ --verbose ] [ --quiet ] [ --portability ]
[ --format=FORMAT ] [ --output=FILE ] [ --version ]
[ --help ] COMMAND [ ARGS ]

[...]
OPTIONS
-o FILE, --output=FILE
-f FORMAT, --format FORMAT
--quiet
[...]

Ok great. So I wrote my command like this :

$ time -f %E  wget -q --timeout=60 --connect-timeout=60 -O - 'http://my-url' >>/dev/null
-su: -f: command not found

hm. Maybe I did something wrong. Let’s try the man page’s example to understand how things work :

$ time -f "%E real,%U user,%S sys" ls -Fs
-su: -f: command not found

wtf??! The example given didn’t work either !
And then

$ time --help
-su: --help: command not found

ok… so, searching a little bit further helped me find the explanation :

Your shell (apparently bash) provides a builtin time function. If you want to use time binary, call it by absolute path (/usr/bin/time)

let’s try :

$ /usr/bin/time -f %E  wget -q --timeout=60 --connect-timeout=60 -O - 'http://my-url' >>/dev/null
0:00.20

Finally! It was just a silly thing…

Just remember, when using the bash time, get the time in minutes/seconds:

$ TIMEFORMAT=$'%0lR'
$ time wget -q --timeout=60 --connect-timeout=60 -O - 'http://my-url' >>/dev/null
0m2s

and in seconds only :

$ TIMEFORMAT=$'%0R'
$ time wget -q --timeout=60 --connect-timeout=60 -O - 'http://my-url' >>/dev/null
2

:D

Xargs

Filed Under (bash) by Amandine on 23-09-2009

Today I learnt a new command :D

$ xargs

Ok I’m a little bit lying : I knew it before but I was using it only to put several lines into one unique line, like this :

$ ls |xargs

Now, thanks to the new guy in front of me (the colorblind one), I will be able to replace a lot of “for” and ` ` by xargs :D

Some interesting uses of xargs :

$ ls | xargs -n 8

Display the content af the current directory in 8 colums

$ find /path -type f -print0 | xargs -0 rm

Seems to be more efficient than “find /path -exec rm {} \;”, because xargs splits this list into sublists and calls rm once for every sublist, while find calls rm once for every single file.

$ xargs -i ssh {} uptime < ./server.list

to get uptime of each server in server.list