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 tagged terminal from sorted by
Terminal - Commands tagged terminal - 44 results
curl ifconfig.me
2014-11-02 21:57:52
User: adria
0

http://ifconfig.me is a web site which shows your public iP address.

If you want use your own code, you can use PHP code such as:

function getip()

{

return "".$_SERVER["REMOTE_ADDR"];

}

echo getip();

?>

Then, you'll get your IP by 'curl yourfile.php'.

echo $(wget http://ipecho.net/plain -q -O -)
2014-10-25 20:25:05
User: KonKar
Functions: echo wget
0

Easiest way to get the external IP address.

cat /etc/named.conf | grep -Po '(?<=(named/)).*(?=\.db)'
2014-10-25 20:16:17
User: KonKar
Functions: cat grep
0

Allows you to have a list of the domains on the server.

sudo pip install rainbowstream && rainbowstream -iot
2014-08-20 06:45:16
User: DTVD
Functions: install sudo
0

Rainbow Stream is a smart and nice Twitter client on terminal.

Almost everything you can do with a GUI application can be done, even viewing an image.

- Tab-autocomplete, history browsing

- Beautiful built-in themes and custom configuration support

- Tweet's images directly on your terminal.

apt-get update && apt-get dist-upgrade -y --show-progress && apt-get autoremove -y && apt-get check && apt-get autoclean -y
0

# AllInOne: Update what packages are available, upgrade to new versions, remove unneeded packages

# (some are no longer needed, replaced by the ones from ap upgrade), check for dependencies

# and clean local cached packages (saved on disk but not installed?,some are needed? [this only cleans unneeded unlike ap clean]).

# aliases (copy into ~/.bashrc file):

alias a='alias'

a ap='apt-get'

a r='ap autoremove -y'

a up='ap update'

a u='up && ap upgrade -y --show-progress && r && ap check && ap autoclean'

# && means "and run if the previous succeeded", you can change it to ; to "run even if previous failed".

I'm not sure if ap check should be before or after ap upgrade -y, you can also change the alias names.

# To expand aliases in bash use ctrl alt e or see this ow.ly/zBKHs

# For more useful aliases go to ow.ly/zBMOx

bashrc-reload() { builtin unalias -a; builtin unset -f $(builtin declare -F | sed 's/^.*declare[[:blank:]]\+-f[[:blank:]]\+//'); . ~/.bashrc; }
2014-03-02 14:24:18
User: Xk2c
Functions: sed unalias unset
2

Simply sourcing .bashrc does not function correctly when you edit it and change an alias for a function or the other way round with the *same name*.

I therefor use this function. Prior to re-sourcing .bashrc it unsets all aliases and functions.

color () { local color=39; local bold=0; case $1 in green) color=32;; cyan) color=36;; blue) color=34;; gray) color=37;; darkgrey) color=30;; red) color=31;; esac; if [[ "$2" == "bold" ]]; then bold=1; fi; echo -en "\033[${bold};${color}m"; }
printTextInColorRed () { echo -e '\033[01;31m\033[K'"$@"'\033[m\033[K' ;} ## print text/string in color red
2013-08-28 10:06:59
User: totti
Functions: echo
1

eg:

printTextInColorRed foo bar

foo bar [in red color]

find . -empty -type d -print0 | xargs -0 rmdir -p
2013-07-01 02:44:57
User: rafar
Functions: find rmdir xargs
0

It starts in the current working directory.

It removes the empty directory and its ancestors (unless the ancestor contains other elements than the empty directory itself).

It will print a failure message for every directory that isn't empty.

This command handles correctly directory names containing single or double quotes, spaces or newlines.

If you do not want only to remove all the ancestors, just use:

find . -empty -type d -print0 | xargs -0 rmdir
tb send xmpp:user.name@gmail.com
2013-04-08 00:29:43
-1

After installing Termbeamer (see termbeamer.com) you can use it to share a terminal session with one or more others even from behind a firewall or NAT.

<ENTER>~.
2012-12-19 17:53:50
User: slafs
1

When your ssh session hanged (probably due to some network issues) you can "kill" it by hitting those 3 keys instead of closing the entire terminal.

newgrp -
2012-10-01 10:23:56
User: dendoes
Functions: newgrp
2

Changes your group to the default group, has the same effect as sourcing your profile/rc file (in any shell) or logging out and back in again.

. ~/.bashrc
source ~/.bashrc
2012-10-01 08:30:19
User: knoppix5
4

Any changes to BASH shell made in .bashrc will be active in the current terminal window from the moment you execute this command, ie. aliases, prompt settings etc. No need to restart terminal.

(In BASH 'source' simile to 'eval' lets you generally execute any bunch of commands stacked in a text file).

tput setf 4
2011-11-22 11:42:48
User: Dhinesh
Functions: tput
Tags: terminal
0

This will change your terminal foreground colour.Depending on the system, tput uses the terminfo or termcap database, as well as looking into the environment for the terminal type.

You can use "setb" to set terminal background colour

mkfifo foo; script -f foo
2011-09-08 02:51:44
User: realist
Functions: mkfifo script
17

One person does `mkfifo foo; script -f foo' and another can supervise real-time what is being done using `cat foo'.

defaults write com.apple.terminal FocusFollowsMouse -string YES
2011-07-26 02:15:04
User: ratonovitch
Functions: write
0

In Mac OS X, by default, you have to click the mouse on a Terminal window before you can type in it. You can change this behavior to mimic the X11 behavior of focusing on the window on mouseover.

open -a Finder <path>
%1 &!
2011-01-14 02:26:24
User: Dema
2

Continue a current job in the background and detach it from current terminal

<ctrl+z> bg
<ctrl+z> %1 &
2010-10-25 17:43:38
User: joem86
-1

Often times you run a command in the terminal and you don't realize it's going to take forever. You can open a new terminal, but you lose the local history of the suspended one. You can stop the running command using , but that may produce undesirable side-effects. suspends the job, and (assuming you have no other jobs running in the background) %1 resumes it. Appending & tells it to run in the background.

You now have a job running concurrently with your terminal. Note this will still print any output to the same terminal you're working on.

Tested on zsh and bash.

( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done; )
7

This is super fast and an easy way to test your terminal for 256 color support. Unlike alot of info about changing colors in the terminal, this uses the ncurses termcap/terminfo database to determine the escape codes used to generate the colors for a specific TERM. That means you can switch your terminal and then run this to check the real output.

tset xterm-256color

at any rate that is some super lean code!

Here it is in function form to stick in your .bash_profile

aa_256 ()

{

( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;

for i in {0..256};

do

o=00$i;

echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;

done )

}

From my bash_profile: http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html