Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using paste from sorted by
Terminal - Commands using paste - 28 results
ps -U nms -o pid,nlwp,cmd:500 | sort -n -k2) && (ps h -U nms -o nlwp | paste -sd+ | bc)
(ps -U nms -o pid,nlwp,cmd:500 | sort -n -k2) && (ps -U nms -o nlwp | tail -n +2 | paste -sd+ | bc)
2014-09-30 18:25:56
User: cmullican
Functions: paste ps sort tail
0

I occasionally need to see if a machine is hitting ulimit for threads, and what process is responsible. This gives me the total number, sorted low to high so the worst offender is at the end, then gives me the total number of threads, for convenience.

find -type f -exec ffprobe -i "{}" -show_entries format=duration -v quiet -of csv="p=0" \; | paste -sd+ | bc
2014-08-29 23:45:09
User: Hype
Functions: find paste
0

Recursive. Ignores non-media files. Requires ffprobe, paste, and bc.

ps -eo pmem,comm | grep chrome | cut -d " " -f 2 | paste -sd+ | bc
2014-01-03 15:33:16
User: Darkstar
Functions: cut grep paste ps
0

This command will show the sum total of memory used in gigabytes by a program that spawns multiple instances of itself. Replace chrome with whatever program's memory usage you are investigating. This command is rather useless on software that only spawns a single instance of itself.

cat file | paste -s -d'%' - | sed 's/\(^\|$\)/"/g;s/%/","/g'
ls | paste --delimiters='*' - ./zzz | awk ' BEGIN{FS="*";} { system("mv " $1 " \"" $2 "\"") }'
2013-05-13 15:44:07
User: skilowatt
Functions: awk ls paste
0

Rename all files in current directory by names from text file 'zzz'

pacman -Qi | grep 'Name\|Size\|Description' | cut -d: -f2 | paste - - - | awk -F'\t' '{ print $2, "\t", $1, "\t", $3 }' | sort -rn
2012-11-20 03:40:55
Functions: awk cut grep paste sort
0

This, like the other commands listed here, displays installed arch packages. Unlike the other ones this also displays the short description so you can see what that package does without having to go to google. It also shows the largest packages on top. You can optionally pipe this through head to display an arbitrary number of the largest packages installed (e.g. ... | head -30 # for the largest 30 packages installed)

paste -sd, <<< $'line1\nline2'
2012-11-13 01:26:05
User: kodango
Functions: paste
Tags: paste
0

A more simple way to join lines with paste command than sed.

export PATH= $(echo $PATH | tr ':' '\n' | awk '!/matching string/' | paste -sd:)
paste <(seq 7 | shuf | tr 1-7 A-G) <(seq 7 | shuf) | while read i j; do play -qn synth 1 pluck $i synth 1 pluck mix $2; done
paste <(banner hello,\ ) <(banner world)
2011-11-21 06:38:16
User: kev
Functions: banner paste
Tags: banner
-4

# # ####### # # ####### # # ####### ###### # ######

# # # # # # # # # # # # # # # # #

# # # # # # # # # # # # # # # # #

####### ##### # # # # ### # # # # # ###### # # #

# # # # # # # ### # # # # # # # # # #

# # # # # # # # # # # # # # # # # #

# # ####### ####### ####### ####### # ## ## ####### # # ####### ######

paste(){ curl -s -S --data-urlencode "txt=$($*)" "http://pastehtml.com/upload/create?input_type=txt&result=address";echo;}
for IP in `cat ip.txt|awk -F: '{print $1}'`; do geoiplookup -f /usr/local/share/GeoIP/GeoIP.dat $IP|awk -F, '{print $2}'>>out.txt; done; paste -d ":" ip.txt out.txt>zoom.txt
2011-08-05 09:26:17
User: woben2
Functions: awk paste
Tags: geoip
-1

take a list of IP:PORT and output IP:PORT:COUNTRY

paste <(cut -f1 log.txt) <(cut -f2- log.txt | shuf)
pacman -Qi $(pacman -Qq)|grep 'Name\|Size'| cut -d: -f2 | paste - - | column -t | sort -nk2
paste -sd'+' file|bc -l
find . -type f -printf %s\\n | paste -sd+ | bc
2011-02-10 09:44:36
User: rubenmoran
Functions: find paste
0

Computes total size of files in a directory. This value is different "du -b" because doesn't includes directory sizes.

seq 1 2 99999999 | sed 's!^!4/!' | paste -sd-+ | bc -l
2011-02-09 23:36:07
User: flatcap
Functions: bc paste sed seq
Tags: sed seq bc paste math
0

Calculate pi from the infinite series 4/1 - 4/3 + 4/5 - 4/7 + ...

This expansion was formulated by Gottfried Leibniz: http://en.wikipedia.org/wiki/Leibniz_formula_for_pi

I helped rubenmoran create the sum of a sequence of numbers and he replied with a command for the sequence: 1 + 2 -3 + 4 ...

This set me thinking. Transcendental numbers!

seq provides the odd numbers 1, 3, 5

sed turns them into 4/1 4/3 4/5

paste inserts - and +

bc -l does the calculation

Note: 100 million iterations takes quite a while. 1 billion and I run out of memory.

seq 1000 | paste -sd+- | bc
seq 10 | paste -sd* | bc
seq 100000 | paste -sd+ | bc
ls > ls; paste ls ls > ren; nano ren; sed 's/^/mv /' ren|bash; rm ren ls
2011-02-08 17:07:13
User: romulusnr
Functions: ls paste rm sed
-2

Instead of tedious manual mv commands and tabbing, this routine creates a file listing all the filenames in the PWD twice, edit the second instance on each line to the new name, then save the file, the routine does the rest. Feel free to replace nano with your holy war editor of choice.

You will get a lot of "mv: 'x' and 'x' are the same file" warnings, these could be cleaned up but the routine works.

paste <(pacman -Q | awk '{ print $1; }' | xargs pacman -Qi | grep 'Size' | awk '{ print $4$5; }') <(pacman -Q | awk '{print $1; }') | sort -n | column -t
paste --serial file1 file2 file3
objdump -d ./PROGRAM|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'