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.

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

All commands from sorted by
Terminal - All commands - 12,340 results
unzip /surce/file.zip -d /dest/
bg; jobs; fg
2015-10-14 17:33:25
User: djangofan
Functions: bg
1

./script.sh

# suspend process

{ctrl-Z}

# background process

bg

# list all backgrounded jobs

jobs

# bring it back to foreground

fg

ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script -f \"$L\"";}
2015-10-14 13:14:29
User: flatcap
Functions: ssh
3

A wrapper around ssh to automatically provide logging and session handling.

This function runs ssh, which runs screen, which runs script.

.

The logs and the screen session are stored on the server.

This means you can leave a session running and re-attach to it later, or from another machine.

.

.

Requirements:

* Log sessions on a remote server

* Transparent - nothing extra to type

* No installation - nothing to copy to the server beforehand

.

Features:

* Function wrapper delegating to ssh

- so nothing to remember

- uses .ssh/config as expected

- passes your command line option to ssh

* Self-contained: no scripts to install on the server

* Uses screen(1), so is:

- detachable

- re-attachable

- shareable

* Records session using script(1)

* Configurable log file location, which may contain variables or whitespace

L="$HOME" # local variable

L="\$HOME" # server variable

L="some space"

.

Limitations:

* Log dir/file may not contain '~' (which would require eval on the server)

.

.

The sessions are named by the local user connecting to the server.

Therefore if you detach and re-run the same command you will reconnect to your original session.

If you want to connect/share another's session simply run:

USER=bob ssh [email protected]

.

The command above is stripped down to an absolute minimum.

A fully expanded and annotated version is available as a Gist (git pastebin):

https://gist.github.com/flatcap/3c42326abeb1197ee714

.

If you want to add timing info to script, change the command to:

ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script --timing=\"$L-timing\" -f \"$L\"";}
cat *.jpg | ffmpeg -f image2pipe -r 1 -vcodec mjpeg -i - -vcodec libx264 out.mp4
wget -O - http://list.iblocklist.com/\?list\=ydxerpxkpcfqjaybcssw\&fileformat\=p2p\&archiveformat\=gz | gunzip > ~/ipfilter.p2p
2015-10-11 13:04:08
User: lordtoran
Functions: gunzip wget
2

Downloads Bluetack's level 1 IP blocklist in .p2p format, suitable for various Bittorrent clients.

adb shell screencap -p | sed 's/\r$//' > FILENAME.PNG
alias m='screen -S $$ -m script'
2015-10-01 18:07:18
Functions: alias
Tags: screen script
1

A quick alias I use right before logging into a server so that I have a log of the transactions as well as the ability to re-connect from another computer. Useful for when your boss says "what commands did you run again on that server?" and you had already closed the terminal ;)

I wrapped it in a script now, with more features, but this is the heart of it.

Never leave home without it.

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
sudo aa-complain /etc/apparmor.d/usr.bin.chromium-browser
2015-09-30 18:56:28
User: lordtoran
Functions: sudo
0

If AppArmor is installed with all profiles enforced, Chromium may refuse to start, printing a "failed to launch zygote process" error on stderr.

This command switches the Chromium profile from enforce to complain mode, effectively un-sandboxing the browser, but depending on the system setup it may be a smaller deal than a nonfunctional application.

NSPR_LOG_MODULES=nsHostResolver:5 NSPR_LOG_FILE=/tmp/log.txt /Applications/Firefox.app/Contents/MacOS/firefox
NSPR_LOG_MODULES=nsHostResolver:5 NSPR_LOG_FILE=/tmp/log.txt firefox
dnstop -l 3 enp1s0f0
./mpv_identify.sh * | egrep '^video_aspect=1\.[67]'
2015-09-29 05:47:07
User: Tatsh
Functions: egrep
0

Checks if the aspect ratio is approximately 1.6 (16:10) or ~1.77777778 (16:9).

Requires mpv_identify from mpv project https://github.com/mpv-player/mpv/blob/master/TOOLS/mpv_identify.sh (this replaces mplayer -identify, or midentify)

pkill imwheel && imwheel &
sudo sh -c "aptitude update; aptitude -DrVWZ full-upgrade; aptitude autoclean; exit"
2015-09-28 23:48:05
User: lordtoran
Functions: sh sudo
2

This has been my "sysupgrade" alias since ca. 2006, first used on Debian Sid, then Sabayon, and it still does its duty on Mint nowadays without breaking stuff.

pkill plasma-desktop && plasma-desktop
2015-09-28 23:36:24
User: lordtoran
0

This can help with serious GUI lockups in KDE. It will only restart Plasma + widgets, not your session, so all your programs will stay running.

sudo sh -c "rm /usr/share/mime/packages/kde.xml && update-mime-database /usr/share/mime"
wallpaper -w 800 -x 16384 -a 1.7 -b 1.85 *
2015-09-28 23:18:39
User: lordtoran
0

List images between 800 and 16384 pixels wide that can be displayed sized and trimmed on a widescreen display.

Requires the "wallpaper" utility.

echo "BTC rate is" $(wget https://api.bitcoinaverage.com/ticker/global/EUR/ -q -O - | jq ".last") "?"
2015-09-28 23:03:59
User: lordtoran
Functions: echo wget
Tags: wget bitcoin jq btc
0

Returns the global weighted BTC rate in EUR. Requires the "jq" JSON parser.

ps h -o %a 21679
2015-09-27 11:00:07
User: BeniBela
Functions: ps
Tags: Linux ps
3

Show the command line for a PID with ps

tr '\0' ' ' </proc/21679/cmdline ; echo
xargs -0a /proc/27288/cmdline echo
2015-09-25 17:35:11
User: dennisw
Functions: xargs
Tags: Linux /proc
7

If you cat the file, all the parts of the command line are bunched up. If you use tr to convert the nulls to spaces, you're still left without a newline unless you add another step. This command does everything for you.

xidel --quiet 'http://www.ebay.com/sch/Beds-Bed-Frames-/175758/i.html?_from=R40&_sac=1&_sop=15&_nkw=bed' -e 'css(".lvresult")[not(matches(., "Pickup only|BUILDING PLANS \(ONLY\)|PARTS LIST"))]/css(".lvtitle")/(.||": "[email protected])' -f 'css("a.gspr.next")'
2015-09-24 12:11:13
User: BeniBela
0

The ebay URL is the search query copied from the browser (here searching for bed stuff). The regex is for crap that should not be shown. Important is "Pickup only", which filters away all the things that cannot be shipped (a filter that cannot be done on Ebay's webpage).

It will output the title and url for all matching items, for all pages of the search result.

It also works for the German Ebay.

curl -q -s http://www.hasthelhcdestroyedtheearth.com/ | sed -En '/span/s/.*>(.*)<.*/\1/p'
2015-09-23 23:26:30
User: Tatsh
Functions: sed
0

Use -q as first argument (as described in `man curl`) to ignore curlrc to ensure the output is always the same regardless of user's configuration.

while true; do (echo -n $(date +"%F %T"):\ ; xwininfo -id $(xprop -root|grep "ACTIVE_WINDOW("|cut -d\ -f 5) | grep "Window id" | cut -d\" -f 2 ) >> logfile; sleep 60; done
2015-09-23 23:00:14
User: BeniBela
Functions: cut date echo grep sleep
1

This logs the titles of the active windows, thus you can monitor what you have done during which times. (it is not hard to also log the executable name, but then it is gets too long)