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 by voyeg3r from sorted by
Terminal - Commands by voyeg3r - 22 results
kded --version | awk -F: 'NR == 2 {print $2}' | sed 's/\s\+//g'
2012-01-17 17:44:23
User: voyeg3r
Functions: awk sed
-2

kded --version return this

Qt: 3.3.8b

KDE: 3.5.10

KDE Daemon: $Id: kded.cpp 711061 2007-09-11 09:42:51Z tpatzig $

awk -F: ................. Awk Field separator

NR == 2 ................. Register Number, second line

{print $2} ............... second field

sed 's/\s\+//g' .......... remove one space or more \s\+ changing by nothing

export PS1="[\u@`hostname -I` \W]$ "
2011-10-25 18:22:55
User: voyeg3r
Functions: export
7

when working with many machines in a computer lab need to know the IP addr is very large, this is a simplistic solution to make things easier

imap <leader>r <C-r>=system('echo "$(($RANDOM % 100))"')<cr>
2010-10-24 00:37:44
User: voyeg3r
0

This mapping function is called RANDOM bash and enter a number between 1 and 100

tar zxvf package.tar.gz --strip 1
2010-05-18 21:01:23
User: voyeg3r
Functions: tar
-3

if I need get olnly script.sh from "folder/script.sh"

cat file | sed -n -r '/^100$|^[0-9]{1,2}$/p'
2010-05-15 19:15:56
User: voyeg3r
Functions: cat file sed
-1

-r to use extended regex

^ begin line

| alternative

get 100 or 0-9 one or two times

ping -c 2 `arp-scan 10.1.1.0/24 | awk '/00:1b:11:dc:a9:65/ {print $1}'`
2010-05-11 13:12:43
User: voyeg3r
Functions: awk ping
4

# first install arp-scan if not have it

arp-scan 10.1.1.0/24 .... show ip+mac in localnet

awk '/00:1b:11:dc:a9:65/ {print $1}' .... get ip associated with MAC

` backtick make do command substitution passing ip to command ping

:%sort
2010-04-04 18:54:14
User: voyeg3r
5

vim 7 or higher has internal sort, too 'sort n' for numbers

sed -i.backup '/patter/{n;s/foo/bar/g}' file
awk '/inet end/ {print $3}' <(ifconfig eth0)
awk 'NR==2 {print $1}' /proc/net/arp
free -m | awk '/Swap/ {print $4}'
2009-09-02 11:46:17
User: voyeg3r
Functions: awk free
-2

simple way to show free swap

awk '!a[$0]++' file
2009-08-23 15:28:43
User: voyeg3r
Functions: awk
9

This create an array 'a' with wole lines. only one occurrence of each line - Not Get lines ++ !

awk '!($0 in a) {a[$0];print}' file
file -i * | grep 'text/plain' | wc -l
2009-08-16 21:22:46
User: voyeg3r
Functions: file grep wc
0

get files without extensions, get ASCII and utf-8 as "text/plain"

:for i in range(1,255) | .put='192.168.0.'.i | endfor
:%s/^/\=line('.').' '
2009-08-16 17:48:03
User: voyeg3r
0

Use this command to insert line numbers in source files, .' ' control how spaces you insert after number.

find ~/project -mtime -1 -type f -print | tar jcvf myfiles.tar.bz2 -T -
2009-03-13 13:03:11
User: voyeg3r
Functions: find tar
0

create tar.bz2 package from files "-type f" modificated today "-mtime -1" in ~/project

rsync -avz -e ssh --files-from=<(find -mtime +30 -mtime -60) source dest
2009-03-13 12:58:28
User: voyeg3r
Functions: find rsync ssh
6

rsync from source to dest all between >30

[[ -d dir ]] || mkdir dir ; cd dir
2009-03-12 17:19:13
User: voyeg3r
Functions: cd dir mkdir
1

For use in scripts this command is very usefull

mkdir -p doc/{text/,img/{wallpaper/,photos/}}
2009-03-12 17:15:58
User: voyeg3r
Functions: mkdir
14

create tree of dir's in one command

alias path='echo $PATH | tr ":" "\n"'
2009-03-12 17:07:58
User: voyeg3r
Functions: alias tr
-1

change ":" in path for new line and associate word path to var $PATH

find . -maxdepth 1 -type f -print0 | xargs -0 -i cp ./{}{,.bak}
2009-03-12 16:02:13
User: voyeg3r
Functions: cp find xargs
-2

"." is current dir, maxdepth is the level, -print0 | xargs -0 fix spaces in names, -i interactive , ./ is the current dir {} actual name , and {,.bak} is the atual name + bak