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 X from sorted by
Terminal - Commands tagged X - 19 results
xvfb-run --server-num=1 rdesktop -u name -p pass -g 1024x768 192.168.0.1
2013-09-19 08:53:00
User: sucotronic
Tags: X remote
1

You can use it to connect to remote windows machine and start some scritps that need user login

alias 2edit='xsel -b;n=pipe$RANDOM;xdotool exec --terminator -- mousepad $n -- search --sync --onlyvisible --name $n key --window %1 ctrl+v'
2013-08-11 06:18:31
User: ichbins
Functions: alias exec
1

bash output is inserted into the clipboard, then mousepad is started and the clipboard content is pasted. xsel and xdotool needs to be installed. Instead of the mousepad any other editor can be used. I've successfully tested the Sublime Text Editor and it opens a new tab for each new paste. Check Sample output for a usage example. This command is originated from here - http://goo.gl/0q9UT4

startx &! exit
startx -- -fullscreen -noresize -unixkill
ssh -XfC -c blowfish user@host Xephyr dpms -fullscreen -query localhost :5
2012-11-01 18:59:57
User: hute37
Functions: ssh
Tags: ssh X Xephyr xdmcp
-1

ssh compresion -C option ...

on slow connection VNC performs better but in local LAN native secure X protocol is an option

xrandr -s 0
2011-07-24 07:38:01
User: h3xx
2

This forces X back to its maximum resolution configured. To get a list, type `xrandr'.

setxkbmap it
chvt 7 ; sleep 2 ; DISPLAY=:0.0 import -window root screenshot.png
2010-08-20 17:28:49
User: camocrazed
Functions: chvt sleep
3

when using Gnome or KDE, you will have a hard time getting a screenshot of something like a login screen, or any other screen that occurs before the desktop environment is up and monitoring the printscreen key. (this probably applies for other DEs as well, but I haven't used them)

What this command is meant to do is take a screenshot of an X window using a command you can run from your virtual terminals (actual text terminals, not just an emulator) To do this:

Press CTRL+ALT+F1 to go to a virtual (text) terminal once your login window comes up

Login to the virtual terminal and enter the command (you'll have to type it in)

You should now have a file called screenshot.png in your home directory with your screenshot in it.

For those of you who are new to the virtual terminal thing, you can use CTRL+ALT+F7 to get back to your regular GUI

From http://www.gnome.org

alias onlyx='nohup startx & disown ; exit'
2010-07-26 12:44:13
User: elementa13
Functions: alias
Tags: X console tty
1

There are different ways to run X, I prefer to run it without xdm/gdm. The problem is you can't lock X because one can press Ctrl+Alt+F1, press Ctrl+Z and kill you X locking process. Of course you can disable Ctrl+Alt* or Ctrl+Alt+Backspace keys, but it's inconvinient if you really need to switch into console.

wmctrl -l -p | while read line; do ps -o cmd= "$(echo "$line" | awk '$0=$3')"; done > ~/.windows
2010-07-04 22:11:24
User: matthewbauer
Functions: ps read
4

This will save your open windows to a file (~/.windows).

To start those applications:

cat ~/.windows | while read line; do $line &; done

Should work on any EWMH/NetWM compatible X Window Manager.

If you use DWM or another Window Manager not using EWMH or NetWM try this:

xwininfo -root -children | grep '^ ' | grep -v children | grep -v '<unknown>' | sed -n 's/^ *\(0x[0-9a-f]*\) .*/\1/p' | uniq | while read line; do xprop -id $line _NET_WM_PID | sed -n 's/.* = \([0-9]*\)$/\1/p'; done | uniq -u | grep -v '^$' | while read line; do ps -o cmd= $line; done > ~/.windows
startx -- /usr/X11R6/bin/Xnest :5 -geometry 800x600
echo "I'm going to paste this into WINDERS XP" | xsel -i
2010-02-08 00:23:43
User: bartonski
Functions: echo
Tags: X xsel putty XMing
4

Set up X forwarding in PuTTY, with X display location set to :0.0

Launch PuTTY ssh session.

Launch Xming. Make sure that display is set to :0.0 (this is default).

echo "I'm going to paste this into WINDERS XP" | xsel -i

will insert the string into the windows cut and paste buffer.

Thanks to Dennis Williamson at stackoverflow.com for sharing...

xlaunch(){ T=/tmp/$$;sh -c "$@" >$T.1 2>$T.2;S=$?;[ $S -ne 0 ]&&{ echo -e "'$@' failed with error $S\nSTDERR:\n$(cat $T.2)\nSTDOUT:\n$(cat $T.1)\n"|xmessage -file -;};rm -f $T.1 $T.2;}
2009-12-31 06:59:56
User: bhepple
Functions: echo
Tags: X
1

When you run an X program from a terminal you can see any errors. But when it's run from another X program (eg from a menu item, from your fluxbox 'keys' file etc) it might just die and you see nothing (except perhaps in .xsession-errors). Instead, launch it via this command and you'll see the termination status, stderr and stdout.

eg: "xlaunch firefox" or "xlaunch 'echo stdout; echo stderr >&2; false'":

'echo stdout; echo stderr >&2; false' failed with error 1

STDERR:

stderr

STDOUT:

stdout

xvkbd -xsendevent -text $(date +%Y%m%d)
2009-12-23 12:01:07
User: sputnick
Functions: date
13

That works in all softs, CLI or GUI... I don't want to waste time to all the time typing the same stuff . So, I have that command in my window manager shortcuts ( meta+l ). All the window managers have editable shortcuts AFAIK. If not, or you don't want to use it that way, you can easily use the xbindkeys soft.

I you're using kde4, you can run :

systemsettings

then open "inputs actions" and create a new shortcut.

For Gnome take a look there : http://www.cyberciti.biz/faq/howto-create-keyboard-shortcuts-in-gnome/

A more advanced one, with strings and newlines :

xvkbd -xsendevent -text "---8<-----\nToday date is: $(date +%Y%m%d)\n---8<-----"

For complicated or long paste, you can feed xvkbd with a file :

xvkbd -xsendevent -file <file>

You can simulate ^C ( control+c ) too or others combinations of keys :

xvkbd -text "\C\Ac"

There's no man page nor help ( On my Archlinux distro ), but you can see online doc there : http://homepage3.nifty.com/tsato/xvkbd/

xinit -- :1
2009-07-31 23:42:28
User: flux
Tags: ssh X X11 xinit
3

This starts a very basic X session, with just a simple xterm. You can use this xterm to launch your preferred distant session.

ssh -X john@otherbox gnome-session

Try also startkde or fluxbox or xfce4-session.

To switch between your two X servers, use CTRL+ALT+F7 and CTRL+ALT+F8.

xvkbd -xsendevent -text "Hello world"
2009-03-20 18:58:05
User: Alanceil
15

This is a (last resort) way to automate applications that provide no other ways for automation, it would send 'Hello world' to the currently active window. See the manpage (and the -text and -window entries) for how to send special characters and target specific windows.

An example:

Using xwininfo, I get the id of my XPlanet background window:

alanceil@kvirasim:19:51:0:~> xwininfo

xwininfo: Please select the window about which you

would like information by clicking the

mouse in that window.

xwininfo: Window id: 0x3600001 "Xplanet 1.2.0"

Absolute upper-left X: 0

(..etc..)

Now I use xvkbd to tell it to close itself:

xvkbd -xsendevent -window 0x3600001 -text "Q"

Obviously, the best way is to put these commands in a shellscript - just make sure to include a short sleep (sleep .1 should suffice) after each xvkbd call, or some programs will become confused.

dpkg-reconfigure -phigh xserver-xorg
apt-cache dotty apache2 | dot -T png | display
2009-02-18 14:27:31
User: raphink
Functions: apt dot
7

Requires: imagemagick and graphviz

On Debian systems, displays a graph of package dependencies. Works also with other image formats, like svg :

apt-cache dotty bash | dot -T svg | display
ssh user@host cat /path/to/some/file | xclip
2009-02-18 10:56:38
User: raphink
Functions: cat ssh
Tags: X X11
18

Have you ever had to scp a file to your work machine in order to copy its contents to a mail? xclip can help you with that. It copies its stdin to the X11 buffer, so all you have to do is middle-click to paste the content of that looong file :)