All commands (14,187)


  • 0
    seg() { for b in $(echo $1); do for x in $(seq 10); do echo $b.$x; done; done }
    Waldirio · 2009-10-20 18:14:25 3

  • 0
    seg() { echo -e "$1" | while read LINE; do for b in $(seq 10); do echo $LINE.$b; done; done; }
    Waldirio · 2009-10-20 17:45:43 3
  • This is a bit hacky, but if you're setting up a bunch of new LUNs, it can save a bunch of time. Also check out sfdisk. The fdisk will fail if, for example, a partition table already exists.


    -1
    echo -e "n\np\n1\n\n\nt\n8e\nw" | fdisk /dev/sdX
    sud0er · 2009-10-20 16:21:54 5

  • -12
    teste.txt < cut -d : -f 1,5 /etc/passwd | tr : \\t | tr a-z A-Z | cat teste.txt
    osvaldofilho · 2009-10-20 14:53:38 8
  • When you press "cmd+n" in TextMate, you can have "HTML" language as default document format... You can also define other languages too. You need to know the UUID of your language bundle.


    -1
    defaults write com.macromates.textmate OakDefaultLanguage 17994EC8-6B1D-11D9-AC3A-000D93589AF6
    vigo · 2009-10-20 07:10:34 4

  • 2
    ssh user@server 'dd if=sda.img' | dd of=/dev/sda
    newrain7803 · 2009-10-20 06:52:26 3

  • 12
    dd if=/dev/sda | ssh user@server 'dd of=sda.img'
    newrain7803 · 2009-10-20 06:47:01 7
  • See: http://imgur.com/JgjK2.png for example. Do some serious benchmarking from the commandline. This will write to a file with the time it took to compress n bytes to the file (increasing by 1). Run: gnuplot -persist <(echo "plot 'lzma' with lines, 'gzip' with lines, 'bzip2' with lines") To see it in graph form.


    3
    for a in bzip2 lzma gzip;do echo -n>$a;for b in $(seq 0 256);do dd if=/dev/zero of=$b.zero bs=$b count=1;c=$(date +%s%N);$a $b.zero;d=$(date +%s%N);total=$(echo $d-$c|bc);echo $total>>$a;rm $b.zero *.bz2 *.lzma *.gz;done;done
    matthewbauer · 2009-10-20 01:00:51 5
  • This is a quick and easy way of encrypting files in a datastream, without ever really creating an output file from gpg. Useful with cron also, when file(s) have to be sent based on a set schedule.


    3
    cat private-file | gpg2 --encrypt --armor --recipient "Disposable Key" | mailx -s "Email Subject" user@email.com
    slashdot · 2009-10-19 20:38:37 4
  • Use the hold space to preserve lines until data is needed.


    -3
    sed -ne '/^Package: \(.*\)/{s//\1/;h;};/^Installed-Size: \(.*\)/{s//\1/;G;s/\n/ /;p;}' /var/lib/dpkg/status | sort -rn
    arcege · 2009-10-19 19:01:17 24
  • I don't know if it's better but works fine :)


    -5
    awk '{if (NR == 3) print}' <file>
    yooreck · 2009-10-19 15:58:09 5
  • List packages and their disk usage in decreasing order. This uses the "Installed-Size" from the package metadata. It may differ from the actual used space, because e.g. data files (think of databases) or log files may take additional space. Show Sample Output


    0
    perl -ne '$pkg=$1 if m/^Package: (.*)/; print "$1\t$pkg\n" if m/^Installed-Size: (.*)/;' < /var/lib/dpkg/status | sort -rn | less
    hfs · 2009-10-19 12:55:59 7
  • Copying only wmv and mpg files recursively from to


    1
    rsync -rvtW --progress --include='*.wmv' --include='*.mpg' --exclude='*.*' <sourcedir> <destdir>
    MauricioVieira · 2009-10-19 10:38:11 4
  • I use it for embedding images in CSS for Stylish, the Firefox addon. Thought it might be useful to others.


    1
    uuencode -m $1 /dev/stdout | sed '1d' | sed '$d' | tr -d '\n' | xclip -selection clipboard
    caliburning · 2009-10-19 09:03:09 4
  • I often need to extract a function from a bash script and this command will do it. Show Sample Output


    8
    sed -n '/^function h\(\)/,/^}/p' script.sh
    haivu · 2009-10-19 07:55:35 33

  • 4
    geoip(){curl -s "http://www.geody.com/geoip.php?ip=${1}" | sed '/^IP:/!d;s/<[^>][^>]*>//g' ;}
    twfcc · 2009-10-19 05:48:07 17
  • This time I added a print to reemaining energy, every minute, time stamped. The example shown here is complete and point to large discrepancies as time passes, converging to accuracy near the end. Show Sample Output


    1
    echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt'
    m33600 · 2009-10-19 05:28:15 4
  • Sample command to obtain a list of geographic localization for established connections, extracted from netstat. Need geoiplookup command ( part of geoip package under CentOS) Show Sample Output


    3
    for i in $(netstat --inet -n|grep ESTA|awk '{print $5}'|cut -d: -f1);do geoiplookup $i;done
    servermanaged · 2009-10-18 20:41:47 4
  • Fully recharge your computer battery and start this script. It will create or clean the file named battery.txt, print a start on it and every minute it will append a time stamp to it. Batteries last few hours, and each hour will have 60 lines of time stamping. Really good for assuring the system was tested in real life with no surprises. The last time stamp inside the battery.txt file is of interest. It is the time the computer went off, as the battery was dead! Turn on your computer after that, on AC power of course, and open battery.txt. Read the first and last time stamps and now you really know if you can trust your computer sensors. If you want a simple line of text inside the battery.txt file, use this: watch -n 60 'date > battery.txt' The time of death will be printed inside Show Sample Output


    0
    echo start > battery.txt; watch -n 60 'date >> battery.txt'
    m33600 · 2009-10-18 07:00:26 4
  • Scrape the National Weather Service Show Sample Output


    4
    weather() { lynx -dump "http://mobile.weather.gov/port_zh.php?inputstring=$*" | sed 's/^ *//;/ror has occ/q;2h;/__/!{x;s/\n.*//;x;H;d};x;s/\n/ -- /;q';}
    zude · 2009-10-17 23:47:47 3
  • printf treats first char after single ' as numeric equivalent


    1
    ord() { printf "%d\n" "'$1"; }
    zude · 2009-10-17 22:02:52 3

  • 2
    for file in *.iso; do mkdir `basename $file | awk -F. '{print $1}'`; sudo mount -t iso9660 -o loop $file `basename $file | awk -F. '{print $1}'`; done
    jaymzcd · 2009-10-17 20:07:31 4

  • 1
    time dd if=/dev/zero of=TEST bs=4k count=512000
    flojb · 2009-10-17 17:50:53 39
  • create iso image from directory . Usefull for virtualised machine To create CD ISO image of directories that contain long file name or non-8.3 format (particularly if you want to burn the CD image for use in Windows system), use the -J option switch that generates Joliet directory records in addition to regular iso9660 file names. For example, to create CD image of Vista SP1 directory: mkisofs -o VitaSP1.iso -J VistaSP1 Show Sample Output


    8
    mkisofs -o XYZ.iso XYZ/
    eastwind · 2009-10-17 16:28:47 53
  • the shortest command for character 'a' i know Show Sample Output


    1
    echo -n a | od -d | sed -n "s/^.* //gp"
    stf42 · 2009-10-17 15:46:00 7
  • ‹ First  < 435 436 437 438 439 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Happy Days
AFAIR this is the wording ;)

du command without showing other mounted file systems

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Visit wikileaks.com
Who needs a DNS server

resume other user's screen session via su, without pty error
Normally, if you su to another user from root and try to resume that other user's screen session, you will get an error like "Cannot open your terminal '/dev/pts/0' - please check." This is because the other user doesn't have permission for root's pty. You can get around this by running a "script" session as the new user, before trying to resume the screen session. Note you will have to execute each of the three commands separately, not all on the same line as shown here. Credit: I found this at http://www.hjackson.org/blog/archives/2008/11/29/cannot-open-your-terminal-dev-pts-please-check.

Download SSL server certificate with opsnessl
Useful when we need to create new certificate for site when current one is near expiry. This downloaded cert can be used to provide organisational data directly to new cert. using below command. e.g. openssl x509 -x509toreq -in /tmp/example.com.cert -out example.com.csr -signkey example.com-key.pem

ssh to machine behind shared NAT
Useful to get network access to a machine behind shared IP NAT. Assumes you have an accessible jump host and physical console or drac/ilo/lom etc access to run the command. Run the command on the host behind NAT then ssh connect to your jump host on port 2222. That connection to the jump host will be forwarded to the hidden machine. Note: Some older versions of ssh do not acknowledge the bind address (0.0.0.0 in the example) and will only listen on the loopback address.

Get your external IP address without curl
Curl is not installed by default on many common distros anymore. wget always is :) $ wget -qO- ifconfig.me/ip

Null a file with sudo

power off system in X hours form the current time, here X=2


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: