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.


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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,407 results
iptables -P INPUT ACCEPT; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT; for table in `cat /proc/net/ip_tables_names`; do iptables -t $table -F; iptables -t $table -Z; iptables -t $table -X; done
2011-12-15 18:19:34
User: dash
Functions: iptables
Tags: Linux iptables
0

If you changed the default policy on any chain other than filter table chain's, this won't be enough.

tr -s ' '
2012-06-26 19:34:18
User: ankush108
Functions: tr
Tags: tr
0

Convert long list of ' ' to a single space. Compress space and other characters.

curl -s http://boards.4chan.org/---/res/nnnnnn | grep -o -i 'File: <a href="//images.4chan.org\/[a-z]*\/src\/[0-9]*\.[a-z]\{3\}' | sed -r 's/File: <a href="\/\///' |xargs wget
history | tail -100 | grep cmd
2013-04-22 03:49:43
User: datamining
Functions: grep tail
0

this also can find the old command you used before

for i in * ; do mv $i $[j++].mp3 ; done
2013-07-01 08:14:59
User: yangfeng724
Functions: mv
0

This command will replace spaces in filename with number

info foo |less
2013-09-12 16:49:08
Functions: info
Tags: less info
0

This command is similar to the above, but is much simpler to remember. Sure, it's isn't as precise as the parent command, but most people aren't going to remember those --flags anyways unless you stick it into your .bashrc on every single system that you manage.

cvlc /path/to/file.avi -V caca
2014-06-13 16:10:36
User: tyzbit
Tags: video vlc
0

Use this command to watch video files on the terminal using VLC.

prerequisite: VLC and cvlc

sudo apt-get install vlc cvlc

if [[ $(expr $(date +%s) - $(stat -c %X /var/lib/apt/periodic/update-success-stamp)) -gt 86400 ]]; then sudo apt-get update fi
2015-05-12 14:45:11
User: gargolito
Functions: date expr stat sudo
0

I have this in my .bash_aliases and call it before running apt-get install or apt-get upgrade

Example:

alias apt-install='apt-update; apt-get install'

alias apt-upgrade='apt-update; apt-get upgrade'

function apt-update () {

if [[ $(expr $(date +%s) - $(stat -c %X /var/lib/apt/periodic/update-success-stamp)) -gt 86400 ]]; then

sudo apt-get update

else

echo apt is up to date

fi

}

cd ~/.minetest/mods && git clone --recursive https://github.com/$1/$2.git
2015-09-30 19:24:59
User: lordtoran
Functions: cd
0

Where $1 = author and $2 = mod name

You need to be running a daily build of Minetest (for example from the 'minetestdevs/daily-builds' PPA), or some bleeding edge mods will not work or crash the game.

Update a mod by entering its subdirectory under ~/.minetest/mods and doing

git pull && git submodule update --recursive --remote --init
while(1){while((date -f ss)%10-gt0){sleep -m 300} echo "$(date -u %s) $((curl 192.168.100.1/cmSignalData.htm).parsedhtml.body.childnodes.item(1).firstchild.firstchild.childnodes.item(5).outertext|%{$_ -replace '\D+\n',''})">>modemlog.txt;sleep 1;echo .}
2015-12-24 02:12:10
User: omap7777
Functions: date echo sleep
0

IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type

powershell

Create a log file of your Motorola Surfboard SB6141 downstream signal strengths.

Uses the built-in curl to request signal strength data from your SB6141 cable modem.

HTML page 192.168.100.1/cmSignalData.htm has the signal strength numbers for the 8 downstreams.

Some HTML/DOM processing parses out the 8 values from the above page.

The eight extracted signal strengths are then logged to a file.

A small while-loop watches the clock & repeats the process every 10 seconds.

egrep '183\.([0-9]|(1[0-6]|2[0-3]))' -J /var/log/maillog*
2010-10-17 21:44:57
User: wazigster
Functions: egrep
0

Useful for grepping an IP range from the maillog. When for instance dealing with a spam-run from a specific IP range, or when errors occur from or to a specific IP-range.

In the example above the IP range 183.0.0.0/10 (183.0.0.0 - 183.63.255.255)

To grep the IP range 124.217.224.0/19 (124.217.224.0 - 124.217.255.255) from the maillog:

egrep '124\.217\.2(2[4-9]|[34][0-9]|5[0-5])' -J /var/log/maillog*

NOTE: the location of the maillog may vary based upon operating system and distribution.

awk '/^'$SEARCH'[ ]*$/{getline;if ($1 ~ /query/) {split($4,a,".");print a[2]}}' /etc/sybase/interfaces
2010-12-17 13:24:27
User: JohnGH
Functions: awk
0

Awk magic to replace:

cat /etc/sybase/interfaces | grep -A 1 -e "$SEARCH" | grep query | awk '{ print $4 }' | awk -F'.' '{print $2}'

( for((i=0;$i<100;i++))do echo volume $i 1; sleep 0.1s; done; )| mplayer -slave -quiet sample.mp3
2011-01-06 11:22:03
User: Juluan
Functions: echo sleep
0

Of course, a fifo is required for piloting the fade out of another song, but with a few bash function, we can mix music in bash like :

crossfadeIn > mplayerfifo1 & crossfadeOut > mplayerfifo2

loop 0 10 > mplayer fifo1

etc etc

ping -a IP-ADDRESS
2011-04-28 13:51:12
User: markussesser
Functions: ping
0

pcspkr have to be enabled!

modprobe pcspkr

xset b on

get_duration () { IFS=.: read -r _ h m s _ < <(ffmpeg -i "$1" 2>&1 | grep Duration);echo $(( h * 3600 + m * 60 + s )); }
inxi -F
stat /etc/my.cnf
# ping -c 1000 -i 0.001 <host>
rsync -arl --rsh=ssh --progress --exclude-from=/etc/localbin/exclude_files.txt /var/www/html/source/* <user>@<server>:/var/www/html/source/
echo 'Etc/UTC' | tee /etc/timezone; dpkg-reconfigure --frontend noninteractive tzdata
2013-04-22 06:14:55
User: donatello
Functions: echo tee
0

Replace the first part of the command above with the appropriate timezone string. Eg: 'Europe/London' or for UTC - 'Etc/UTC'. The appropriate string can be found from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

This is useful when your server is installed by a data centre (managed hardware, VPS, etc) and the timezone is not usually set to the one your prefer.

for y in {2009..2013}; do cal $y; done
fbcmd FSTATUS =all
perldoc -m Some::Module
wakeonlan 00:00:DE:AD:BE:EF
2014-06-13 16:16:33
User: tyzbit
0

Wakes up a computer on your LAN with a Wake-On-LAN packet. MAC Address must match the NIC MAC, computer must have WOL enabled in the BIOS.