Filed Under (bash) by Amandine on 08-02-2010
I often need to execute a loop x times, and I’m just too lazy to write a i++ style algorithm… the command seq is made for me :)
Easy to use, just does what I need from it, here’s a extract from the man page :
NAME
seq - print a sequence of numbers
SYNOPSIS
seq [OPTION]... LAST
seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST
So…
$ seq 10
1
2
3
4
5
6
7
8
9
10
$ seq 10 2 20
10
12
14
16
18
20
$ for i in `seq 5`; do echo 'hello!'; done;
hello!
hello!
hello!
hello!
hello!
Great ! :p
Filed Under (bash) by Amandine on 23-09-2009
Today I learnt a new command :D
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 :
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 :
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