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,492 results
sudo ifconfig eth0 hw ether 00:01:02:03:04:05
2009-06-04 09:02:35
User: momitov
Functions: ifconfig sudo
6

eth0 = the name of the interface

00:01:02:03:04:05 = the new mac adresse

the same thing for wireless card $ sudo iwconfig eth1 hw ether 00:01:02:03:04:05

recode UTF8..UTF-16LE linux-utf8-file.txt
2009-06-04 08:53:51
User: greppo
0

Convert file from the UTF8 encoding used on Linux (has no "EF BB BF" byte order mark at the start) to the UTF-16 encoding used on Windows (has an "FF FE" byte order mark at the start).

Thanks to commenter: previous iconv command was the obsolete way to do it.

if [ -z $(echo $var | grep [0-9]) ]; then echo "NON NUMERIC"; fi
2009-06-04 07:41:26
User: AnusJenkins
Functions: echo grep
2

use to execute a block of code only if $var is numeric

lshw -html > hardware.html
2009-06-04 07:14:03
User: flart
27

After the command is done, open the html file in a browser

find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"
2009-06-03 22:08:48
User: vincentp
Functions: find grep
11

Finds all corrupted jpeg files in current directory and its subdirectories. Displays the error or warning found.

The jpeginfo is part of the jpeginfo package in debian.

Should you wish to only get corrupted filenames, use cut to extract them :

find ./ -name *jpg -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR" | cut -d " " -f 1
awk '/match/{print NR}' file
sed -n -e '1,/match/p'
URL=http://svn.example.org/project; diff -u <(TZ=UTC svn -q log -r1:HEAD $URL | grep \|) <(TZ=UTC svn log -q $URL | grep \| | sort -k3 -t \|)
2009-06-03 14:26:55
User: sunny256
Functions: diff grep sort
Tags: bash svn
2

Lists revisions in a Subversion repository with a timestamp that doesn't follow the revision numbering order. If everything is OK, nothing is displayed.

while (( $i != 0 )) { smbstatus; sleep 5; clear }
2009-06-03 13:26:30
Functions: clear sleep
Tags: unix samba zsh
-4

See smbstatus Output within a 5 second interval (for monitoring smb access)

find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f
2009-06-03 09:47:08
User: mohan43u
Functions: cut file find grep sed tail xargs
Tags: tail
5

Works in Ubuntu, I hope it will work on all Linux machines. For Unixes, tail should be capable of handling more than one file with '-f' option.

This command line simply take log files which are text files, and not ending with a number, and it will continuously monitor those files.

Putting one alias in .profile will be more useful.

for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r
2009-06-03 08:25:00
User: brunost
Functions: echo head perl sort
14

Print out list of all branches with last commit date to the branch, including relative time since commit and color coding.

tail -f FILE | perl -pe 's/KEYWORD/\e[1;31;43m$&\e[0m/g'
2009-06-02 21:31:54
User: tuxifier
Functions: perl tail
17

tail with coloured output with the help of perl - need more colours? here is a colour table:

http://www.tuxify.de/?p=23

for i in `du --max-depth=1 $HOME | sort -n -r | awk '{print $1 ":" $2}'`; do size=`echo $i | awk -F: '{print $1}'`; dir=`echo $i | awk -F: '{print $NF}'`; size2=$(($size/1024)); echo "$size2 MB used by $dir"; done | head -n 10
nslookup -q=txt -class=CHAOS version.bind NS.PHX5.NEARLYFREESPEECH.NET
find /var/logs -name * | xargs tar -jcpf logs_`date +%Y-%m-%e`.tar.bz2
find ~/Desktop/ \( -regex '.*/\..*' \) -print -exec rm -Rf {} \;
cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css
2009-06-02 15:51:51
User: lrvick
Functions: awk cat
0

Ever compress a file for the web by replacing all newline characters with nothing so it makes one nice big blob?

It is a great idea, however what about when you want to edit that file? ...Serious pain in the butt.

I ran into this today in that my only copy of a CSS file was "compressed" with no newlines.

I whipped this up and it converted back into nice human readable CSS :-)

It could be nicer, but it does the job.

resolveip -s www.freshmeat.net
lynx -source http://www.commandlinefu.com/commands/random | sed 's/<[^>]*>//g' | head -1037 | tail -10 | sed -e 's/^[ \t]*//' | sed '/^$/d' | head -2
date -d '1 day ago'; date -d '11 hour ago'; date -d '2 hour ago - 3 minute'; date -d '16 hour'
2009-06-01 10:41:56
User: LrdShaper
Functions: date
5

With this command you can get a previous or future date or time. Where can you use this? How about finding all files modified or created in the last 5 mins?

touch -t `echo $(date -d "5 minute ago" "+%G%m%d%H%M.%S")` me && find . -type f -newer me

List all directories created since last week?

touch -t `echo $(date -d "1 week ago" "+%G%m%d%H%M.%S")` me && find . -type d -cnewer me

I'm sure you can think of more ways to use it. Requires coreutils package.

postsuper -d ALL
while [ i != 0 ]; do sleep 1 | dialog --clear --gauge "Quality: " 0 0 $(cat /proc/net/wireless | grep $WIRELESSINTERFACE | awk '{print $3}' | tr -d "."); done
2009-05-31 16:09:23
User: ncaio
Functions: awk cat grep sleep tr
1

The variable WIRELESSINTERFACE indicates your wireless interface

pdfinfo Virtualization_A_Beginner_Guide.pdf | awk /Pages/
mkdir -p /cdrom/unnamed_cdrom ; mount -F hsfs -o ro `ls -al /dev/sr* |awk '{print "/dev/" $11}'` /cdrom/unnamed_cdrom
2009-05-31 08:42:20
User: felix001
Functions: awk mkdir mount
-2

This will allow you to mount a CD-ROM on Solaris SPARC 9 or lower. This will not work on Solaris 10 due to void and the volume management daemons.

www.fir3net.com

net rpc shutdown -I ipAddressOfWindowsPC -U username%password
2009-05-31 07:18:01
User: LrdShaper
Functions: shutdown
Tags: Linux windows
102

This will issue a shutdown command to the Windows machine. username must be an administrator on the Windows machine. Requires samba-common package installed. Other relevant commands are:

net rpc shutdown -r : reboot the Windows machine

net rpc abortshutdown : abort shutdown of the Windows machine

Type:

net rpc

to show all relevant commands