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 using type from sorted by
Terminal - Commands using type - 20 results
for %%f in (*.json) do type %%f >> aggregate.json
type -t $1
2012-01-10 21:57:29
User: bbbco
Functions: type
Tags: type
1

Prints a string indicating whether a command is an alias, keyword, function, builtin, or file. I have used this in my BASH scripts to allow an external parameter to define which function to run, and ensure that it is a valid function that can indeed be run.

man <command> then type h
2011-10-16 09:49:56
User: stanix
Functions: man type
-5

Read all chapters up to 'Jumping', improve your effectiveness of wirking in terminal.

Most useful are the Moving and Searching commands

whichpath() { local -A path; local c p; for c; do p=$(type -P "$c"); p=${p%/*}; path[${p:-/}]=1; done; local IFS=:; printf '%s\n' "${!path[*]}"; }
2011-09-16 15:55:15
User: RanyAlbeg
Functions: printf type
0

I find it useful when I want to add another crontab entry and I need to specify the appropriate PATH.

I give ''whichpath'' a list of programs that I use inside my script and it gives me the PATH I need to use for this script.

''whichpath'' uses associative array, therefore you should have Bash v4 in order to run it.

See sample output.

man () { if [[ $(type ${1}) =~ "is a shell builtin" ]]; then; /usr/bin/man -P "/usr/bin/less -iRs --pattern=\"^ *${1}\"" bash; else; /usr/bin/man ${1}; return; fi; }
2011-08-25 20:27:16
Functions: man type
0

ulimit [-SHacdflmnpstuv [limit]]

Provides control over the resources available to the shell and to processes started by it, on systems that allow such control. The -H

and -S options specify that the hard or soft limit is set for the given resource. A hard limit cannot be increased once it is set; a

soft limit may be increased up to the value of the hard limit. If neither -H nor -S is specified, both the soft and hard limits are set.

# jumps straight to the definition of ulimit in the bash man page.

type {command} >/dev/null
2011-06-22 15:30:57
User: h3nr1x
Functions: type
2

Usefull to detect if a commad that your script relies upon is properly installed in your box, you can use it as a function

function is_program_installed() {

type "$1" >/dev/null

}

Invoke it and check the execution code

is_program_installed "dialog"

if [ ! $? -eq 0 ]; then

echo "dialog is not installed"

exit 1

fi

ls -l $(type -path -all java)
2011-05-12 17:25:39
User: evandrix
Functions: ls type
1

The output will likely point to '/etc/alternatives/java'.

So find out where that points by issuing ls -l like this:

ls -l /etc/alternatives/java

type <function name>
2011-04-09 15:33:40
User: fossilet
Functions: type
5

Bash builtin type also indents the function.

type () { if [ "$1" = "-c" ]; then shift; for f in "$@"; do ff=$(builtin type -p "$f"); readlink -f "$ff"; done; else builtin type $typeopts "$@"; fi; }
2011-04-07 18:57:51
User: splante
Functions: readlink type
0

The "type" builtin command is handy to find out what executable will be used if you issue a command. But on some distros, particularly when using /etc/alternatives, certain executables get buried under layers and layers of symbolic links and it becomes hard to find which one.

If you put the above command in your .bashrc, it adds a "-c" option to the type command that will weed through the symbolic links and prints the actual file that will be executed.

type -a python
goclf() { type "$1" | sed '1d' | tr -d "\n" | tr -s '[:space:]'; echo }
2010-06-26 21:44:17
User: meathive
Functions: echo sed tr type
5

This command will format your alias or function to a single line, trimming duplicate white space and newlines and inserting delimiter semi-colons, so it continues to work on a single line.

find . type f -exec echo http://exg.com/{} \; > file
2010-03-02 14:18:01
Functions: echo find type
-2

find all files in cur dir add to url and append to file

sleep 3 && xdotool type --delay 0ms texthere
2010-02-18 11:44:18
User: drinkcat
Functions: sleep type
Tags: Linux
5

Just after you type enter, you have 3 seconds to switch window, then "texthere" will be "typed" in the X11 application that has focus. Very useful to beat your score at games such as "How fast can you type A-Z".

type <command>
type <filename>
2009-09-14 09:37:23
User: danam
Functions: type
4

Also searches for aliases and shell builtins

echo "-------------" >> nicinfo.txt; echo "computer name x" >> nicinfo.txt; ifconfig | grep status >> nicinfo.txt; ifconfig | grep inet >> nicinfo.txt; ifconfig | grep ether >> nicinfo.txt; hostinfo | grep type >> nicinfo.txt;
type -all command
type "C:\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat"
type C:\WINNT\system32\inetsrv\MetaBase.xml | find "DEBUG"
type C:\WINNT\system32\inetsrv\MetaBase.xml | find "400" | find "CustomError"