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

Calculate N!
Same as the seq/bc solution but without bc.

set history file length
set how many commands to keep in history Default is 500 Saved in /home/$USER/.bash_history Add this to /home/$USER/.bashrc HISTFILESIZE=1000000000 HISTSIZE=1000000

Find default gateway

Batch file name renaming (copying or moving) w/ glob matching.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Upgrade all perl modules via CPAN

Happy Days
This never gets old

display typedefs, structs, unions and functions provided by a header file
will display typedefs, structs, unions and functions declared in 'stdio.h'(checkout _IO_FILE structure). It will be helpful if we want to know what a particular header file will offer to us. Command 'cpp' is GNU's C Preprocessor.

Google text-to-speech in mp3 format
Usage: t2s 'How are you?' Nice because it automatically names the mp3 file up to 15 characters Modified (uses bash manip instead of tr) t2s() { wget -q -U Mozilla -O $(cut -b 1-15

List the Sizes of Folders and Directories
I wanted an easy way to list out the sizes of directories and all of the contents of those directories recursively.


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: