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

All commands from sorted by
Terminal - All commands - 11,587 results
stat -c '%n %U:%G-%a' *
2014-05-03 04:56:23
User: snipertyler
Functions: stat
Tags: permissions
3

#Alias

alias perm="stat -c '%n %U:%G-%a'"

#Function

perm() { for ll in $@; do stat -c "%n %U:%G-%a" "$ll"; done; }

netstat -pnut -W | column -t -s $'\t'
2014-05-03 00:48:53
User: Nadiar
Functions: column netstat
2

This takes all of the tab spaces, and uses column to put them into the appropriately sized table.

find directory -type l -lname string
2014-05-02 14:44:24
User: gumption
Functions: find
Tags: find
1

Finds all symbolic links in the specified directory which match the specified string pattern.

I used this when upgrading from an Apple-supported version of Java 6 (1.6.0_65) to an Oracle-supported version (1.7.0_55) on Mac OS X 10.8.5 to find out which executables were pointing to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands (Apple version) vs. /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin (Oracle version). However, it appears the current JDK installation script already takes care of modifying the links.

find /some/directory/* -prune -type f -name *.log
2014-05-02 00:14:32
User: bigstupid
Functions: find
0

This find syntax seems a little easier to remember for me when I have to use -prune on AIX's find. It works with gnu find, too.

Add whatever other find options after -prune

psql -X -A -t -c "SELECT version();"
2014-05-01 18:10:20
User: malathion
0

Without using a pipe.

-X ignores the user's .psqlrc configuration file

-A sets un-aligned table output mode

-t prints rows only (no headers or footers)

xset dpms force off
2014-05-01 14:16:27
User: GusPS
2

To turn off monitor:

xset dpms force off

To turn on, simply press a key, or move mouse/mousepad.

10,30,50 * * * * ping -c1 -w3 www.test.com >/dev/null
10,30,50 * * * * ping -q -c1 -w3 www.test.com | grep '1 received' - || mail -ne -s'Host 192.168.0.14 not reachable' test@gmail.com
git rm $(git ls-files --deleted)
2014-05-01 06:21:56
User: jaapie
Functions: rm
Tags: git
1

You'll probably want to pass in the -rf options if you have to delete a directory or something.

for i in $(cat vulns.txt); do echo $i; rpm -qa ?changelog | grep -i $i; done
2014-04-30 16:11:14
User: sonny108
Functions: cat echo grep rpm
0

Found it online and could be very useful

pgrep 'sleep' | while read pid; do pstree -sa -H$pid $pid ; done
csvcount() { for dir in $@; do echo -e "$(find $dir -name '*.csv' | wc -l)\t$dir"; done }
ifconfig |grep HWaddr |cut -d ' ' -f 1,11 |grep eth0 |cut -d ' ' -f 2|xargs | awk -F':' '{ print $1$2$3$4$5$6 }'
2014-04-25 18:43:47
User: simplewall
Functions: awk cut grep ifconfig xargs
0

Many tasks need mac id check. above command exactly do the same

ps -efa | grep httpd | grep -v grep | awk '{ print $2 }' |xargs
ffmpeg -i file.ext -acodec copy -vn out.ext
2014-04-25 14:24:57
User: snipertyler
Tags: ffmpeg
3

This removes the video and subsequent file size and directly copies the audio.

export PORT=11211; ss -an4 | grep -E "ESTAB.*$PORT" | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr
tar -xvpf file.tar.gz
2014-04-25 10:23:03
User: shajeen
Functions: tar
1

-x, --extract, --get

extract files from an archive

-p, --preserve-permissions, --same-permissions

extract information about file permissions (default for superuser)

-f, --file=ARCHIVE

use archive file or device ARCHIVE

-v, --verbose

verbosely list files processed

psql -h <SERVER NAME HERE> -t -c 'SELECT version();' |head -1
rtfm() { help $@ || man $@ || xdg-open "http://www.google.com/search?q=$@"; }
2014-04-25 04:17:03
User: KlfJoat
Functions: man
1

Same as the other rtfm's, but using the more correct xdg-open instead of $BROWSER.

I can't find a way to open info only if the term exists, so it stays out of my version.

echo 16384 > /proc/sys/net/ipv4/neigh/default/gc_thresh1; echo 32768 > /proc/sys/net/ipv4/neigh/default/gc_thresh2; echo 65535 > /proc/sys/net/ipv4/neigh/default/gc_thresh3; echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
2014-04-25 00:18:58
User: andregyn62
Functions: echo
1

This command solve the problem ping: sendmsg: No buffer space available to.

sudo add-apt-repository ppa:PPA_TO_ADD
2014-04-24 20:02:39
User: KlfJoat
Functions: sudo
0

There is no longer a need to add PGP keys for Ubuntu Launchpad PPA's.

The add-apt-repository command creates a new file for the PPA in /etc/sources.list.d/ then adds the PPA's keys to the apt keyring automatically. No muss, no fuss.

strings * |grep -v "Apple" |grep http |uniq |sed "s/<[^>]\+>//g"
for i in `grep -ri "?\|?\|?\|?\|?" * --col | cut -d: -f1 |sort -u `;do sed -i "s/?/\&aacute;/g" $i; sed -i "s/?/\&eacute;/g" $i; sed -i "s/?/\&iacute;/g" $i; sed -i "s/?/\&oacute;/g" $i; sed -i "s/?/\&uacute;/g" $i; echo "HTMLizing file [$i]";done
2014-04-24 11:43:36
User: linuxninja
Functions: cut echo sed sort
0

If we've many files containing (?, ?, ?, ?, ? ) characters instead of ?, ?,... etc,...

we can ue this simple command line running a sed command inside a for loop searching for files containing that characters.

Hope u like it! Enjoy! ;)

openssl rand -hex 6 | sed 's/\(..\)/:\1/g; s/^.\(.\)[0-3]/\12/; s/^.\(.\)[4-7]/\16/; s/^.\(.\)[89ab]/\1a/; s/^.\(.\)[cdef]/\1e/'
2014-04-23 21:43:38
User: phil_m
Functions: sed
Tags: Network bash mac
0

The sed script ensures that the "random" MAC address is unicast (bit 0 of first byte == 0) and local (bit 1 of first byte == 1)

for file in /usr/bin/*; do pacman -Qo "$file" &> /dev/null || echo "$file"; done
2014-04-22 21:57:08
User: malathion
Functions: echo file
0

In this example I am returning all the files in /usr/bin that weren't put there by pacman, so that they can be moved to /usr/local/bin where they (most likely) belong.