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 by zed from sorted by
Terminal - Commands by zed - 11 results
p=~/.config/chromium/zed; cp -r ~/.config/chromium/Default $p && echo "chromium-browser --user-data-dir=$p" && chromium-browser --user-data-dir=$p;
2010-11-08 02:45:29
User: zed
Functions: cp echo
-1

Change the value of p to match the path where you wish to create the profile.

To run it again in the future, use the parameter --user-data-dir (which gets echoed to you when run):

chromium-browser --user-data-dir=/path/to/your/

Quick Functions:

# create a new chromium profile

new-chromium-profile() { p=~/.config/chromium/$1; cp -r ~/.config/chromium/Default $p && echo "chromium-browser --user-data-dir=$p" && chromium-browser --user-data-dir=$p; }

# runs a chromium profile

run-chromium-profile() { chromium-browser --user-data-dir=~/.config/chromium/$1; }

for i in $(seq 0 5 100); do echo $i; sleep 1; done | zenity --progress --title "Installing Foobar" --text "Pleae wait until process has finished."
2010-10-08 04:08:33
User: zed
Functions: echo seq sleep
3

Create a progress dialog with custom title and text using zenity.

for i in $(seq 0 5 100); do echo $i; sleep 1; done | dialog --gauge "Install..." 6 40
2010-10-08 04:08:17
User: zed
Functions: echo seq sleep
3

using seq inside a subshell instead of a bash sequence to create increments.

makepasswd --char=32
2010-09-29 06:01:32
User: zed
-1

A more robust password creation utility

# Create passwords in batch

makepasswd --char=32 --count=10

# To learn more about the options you can use

man makepasswd
gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$(find ~/Wallpapers -type f | shuf -n1)"
2010-09-21 04:01:55
User: zed
2

Changes your desktop background image in gnome. Update the directory to wherever you keep your wallpapers. I like to create a sub-directory in my Wallpaper folder called "cycle" that I use to define the wallpapers I wish to loop in cron. ex:

gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$(find ~/Wallpapers/cycle -type f | shuf -n1)"
scrot -ucd4 -e 'eog $f'
2010-09-15 03:31:06
User: zed
6

Take a screenshot of the focused window with a 4 second countdown

# shorten by adding to your .bashrc: alias sss='scrot -ucd4 && eog $(ls -tr | tail -n1)'

echo -e "\nalias sss='scrot -ucd4 && eog $(ls -tr | tail -n1)'" >> ~/.bashrc

-d 4 second delay

-c display countdown

-u focused window

man scrot for more flags

url=http://www.youtube.com/watch?v=V5bYDhZBFLA; youtube-dl -b $url; mplayer $(ls ${url##*=}*| tail -n1) -ss 00:57 -endpos 10 -vo gif89a:fps=5:output=output.gif -vf scale=400:300 -nosound
2010-07-18 02:11:39
User: zed
Functions: ls tail
12

requires "youtube-dl" -- sure you can do this with wget and some more obscurity but why waste your time when this great tool is available?

the guts consist of mplayer converting a video to a gif -- study this command and read the man page for more information

mplayer video.flv -ss 00:23 -endpos 6 -vo gif89a:fps=5:output=output.gif -vf scale=400:300 -nosound

generates a 6 second gif starting at 23 seconds of play time at 5 fps and a scale of 400x300

start time (-ss)/end time (-endpos) formats: 00:00:00.000

end time should be relative to start time, not absolute. i.e. -endpos 5 == seconds after 0:42 = 0:47 end point

play with fps and scale for lower gif sizes

the subshell is a solution for the -b flag on youtube-dl which downloads the best quality video, sometimes, which can be various video formats $(ls ${url##*=}*| tail -n1)

while read l; do echo ${l%% *}; done < three-column-list.txt > only-first-column.txt
2010-07-09 03:42:56
User: zed
Functions: echo read
1

The above is an example of grabbing only the first column. You can define the start and end points specifically by chacater position using the following command:

while read l; do echo ${l:10:40}; done < three-column-list.txt > column-c10-c40.txt

Of course, it doesn't have to be a column, or extraction, it can be replacement

while read l; do echo ${l/foo/bar}; done < list-with-foo.txt > list-with-bar.txt

Read more about parameter expansion here:

http://wiki.bash-hackers.org/syntax/pe

Think of this as an alternative to awk or sed for file operations

for f in t1.bmp t2.jpg t3.tga; do echo ${f%.*}.png; done
2010-07-09 00:38:53
User: zed
Functions: echo
7

The above is just a prove of concept based around the nested bash substitution. This could be useful in situations where you're in a directory with many filetypes but you only want to convert a few.

for f in *.bmp *.jpg *.tga; do convert $f ${f%.*}.png; done

or you can use ls | egrep to get more specific... but be warned, files with spaces will cause a ruckus with expansion but the bash for loop uses a space delimited list.

for f in $(ls | egrep "bmp$|jpg$|tga$"); do convert $f ${f%.*}.png; done

I'm guessing some people will still prefer doing it the sed way but I thought the concept of this one was pretty neat. It will help me remember bash substitutions a little better :-P

fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)
2010-07-08 02:57:52
User: zed
Functions: ls
7

You need to have fortune and cowsay installed. It uses a subshell to list cow files in you cow directory (this folder is default for debian based systems, others might use another folder).

you can add it to your .bashrc file to have it great you with something interesting every time you start a new session.

sleep 6s && notify-send -t 10000 -u critical "remember to think" &
2010-07-01 02:17:24
User: zed
Functions: sleep
5

This will be seen through your system's visual notification system, notify-osd, notification-daemon, etc.

---

sleep accepts s,m,h,d and floats (date; sleep .25m; date)

---

notify-send (-t is in milliseconds && -u low / normal / critical)

man notify-send for more information

---

notification-daemon can use b/i/u/a HTML