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.

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:



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!

Top Tags





Commands tagged windows from sorted by
Terminal - Commands tagged windows - 72 results
<command> >NUL 2>&1 || ( echo <Command> not found. Please install <command> or check PATH variable! & pause & exit )
2011-03-07 14:27:42
User: Marco
Functions: echo exit install
Tags: windows batch dos

This is a command to be used inside of MS-DOS batch files to check existence of commands as preconditions before actual batch processing can be started. If the command is found, batch script continues execution. If not, a message is printed on screen, script then waits for user pressing a key and exits.

An error message of the command itself is suppressed for clarity purpose.

wmic -U DOMAIN/user --password='password' //IP_HOST "select Caption,CSDVersion,CSName from Win32_OperatingSystem" | grep Windows
2010-09-20 14:23:37
User: dr_gogeta86
Functions: grep
Tags: windows wmic wmi

Get windows version with servicepack and hostname

setlocal enabledelayedexpansion
2010-08-10 12:26:43
User: Marco

Usually the MS-DOS cmd.exe processes in the whole FOR loop as one command and expands each var like %varname% in before (except the loop var of course).

This command enables expansion of other vars than only the loop var during the FOR loop. The syntax of the var to expand is then !varname! inside the FOR loop.

Use command


to end the setlocal command.

E.g. (only works from batch files, not from commandline directly):

@echo off

setlocal enabledelayedexpansion

FOR %%A IN (*) DO (

set file=%%A

echo !file!



FOR /F "tokens=3* delims=[]=," %A IN ('SET ARRAY[') DO ( echo %A -- %B )
2010-08-10 12:12:27
User: Marco
Functions: echo

Loops over array of a system var, splits its values and puts the values into %A, %B, %C, %D, and so on.

Create array before, like

set ARRAY[0]=test1,100


set ARRAY[1]=test2,200

Be sure to replace %A, %B, etc. with %%A, %%B, etc. when using this from inside of batch files.

FOR /F "tokens=3* delims=[]=" %A IN ('SET ARRAY[') DO ( echo %A )
2010-08-10 12:08:26
User: Marco
Functions: echo

This command loops over all indexes of the system variable array ARRAY[] and puts its content into %A.

Create this array before, e.g. by

set ARRAY[0]=test1


set ARRAY[1]=test2

For using inside of a batch file, write %%A instead of %A.

FOR /f %%g in ('echo %1 ^| iconv -f gbk -t utf-8') DO curl -x proxy:port -u user:pass -d status=%%g -d source="cURL" http://twitter.com/statuses/update.xml
2010-07-21 04:53:54
User: MeaCulpa
Functions: iconv

Aside from curl one will need iconv windows binary since windows lacks a native utf-8 cli interface. In my case I need a proxy in China and iconv to convert gbk status string into utf-8. GnuWin32 is a good choice with loads of coreutils natively ported to Windows

"FOR /f" is the solution to pass iconv output to curl.

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

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
sudo arp-scan -I eth0
FOR /L %i IN (1,1,254) DO ping -n 1 10.254.254.%i | FIND /i "Reply">> c:\ipaddresses.txt
2010-06-29 21:02:21
Functions: ping

documents all active ips on a subnet and saves to txt file.

net rpc -I ADDRESS -U USERNAME%PASSWORD service {stop|start} SVCNAME
2010-06-29 17:12:36
User: f0rk

Control (stop, start, restart) a Windows Service from a Linux machine which has the `net` command (provided by samba).

for /F %G in ('dir /b c:\Windows\system32\notepad.exe') do ( echo %G )
echo tmp%date:~4,2%-%date:~7,2%-%date:~10,4%_%time%
2010-05-25 03:34:12
User: Agnostos
Functions: echo
Tags: windows

Useful for if you want to create a log file every now and again or wish to record file names with date and time. You can't use the / for file names. so this replaces the / with a -

Windows only

rdesktop -a24 -uAdministrator -pPassword -r clipboard:CLIPBOARD -r disk:share=~/share -z -g 1280x900 -0 $@ &
2010-03-08 11:51:58
User: tomer

The above command will open a Remote Desktop connection from command line, authenticate using default username and password (great for virtual machines; in the exampe above it's administrator:password), create a shared folder between your machine and the other machine and configure resolution to best fit your desktop (I don't like full screen because it make the desktop panels to disappear). The command will run in the background, and expect to receive parameters. You should enter hostname or IP address as a parameter to the command, and can also override the defaults parameters with your own.

echo "message" | smbclient -M NAME_OF_THE_COMPUTER
2010-02-28 21:10:46
User: mvrilo
Functions: echo

It will only work if the service NETSEND in the Windows machine is enabled.

for /f "delims==" %a in (' dir "%USERPROFILE%\*.sqlite" /s/b ') do echo vacuum;|"sqlite3.exe" "%a"
2010-01-18 20:56:00
User: vutcovici
Functions: dir echo

This command defragment the SQLite databases found in the home folder of the current Windows user.

This is usefull to speed up Firefox startup.

The executable sqlite3.exe must be located in PATH or in the current folder.

In a script use:

for /f "delims==" %%a in (' dir "%USERPROFILE%\*.sqlite" /s/b ') do echo vacuum;|"sqlite3.exe" "%%a"
sudo nmap -F -O | grep "Running: " > /tmp/os; echo "$(cat /tmp/os | grep Linux | wc -l) Linux device(s)"; echo "$(cat /tmp/os | grep Windows | wc -l) Window(s) devices"
2010-01-10 03:09:56
User: matthewbauer
Functions: echo grep sudo

Shows how many Windows and Linux devices are on your network.

May add support for others, but that's all that are on my network right now.

for /L %%x in (1,1,16) do mkdir %%x & curl -R -e http://www.kirtu.com -o %%x/#1.jpg http://www.kirtu.com/toon/content/sb%x/english/sb%x_en_[001-070].jpg
2009-12-08 15:01:16
User: MyTechieself
Functions: mkdir

Bulk downloads the comic strip JPG files for the adult cartoon Savitabhabhi, storing each set in it's own folder. Requires manual removal of "non-image" files that maybe created because each series may differ in length. The command can be easily adapted for UNIX flavours. You need to have cURL in your path.

for /F "DELIMS=""" %i in ('dsquery group -name SourceGroupName ^| dsget group -members') do dsquery group -name TargetGroupName | dsmod group -addmbr %i
2009-09-25 16:32:33
User: miketheman

Interacting with Active Directory to add users from one group to another group.

This prevents from having to deal with long DNs and copying, pasting problems. It executes once per returned object.

cat /dev/clipboard; $(somecommand) > /dev/clipboard
2009-07-10 18:48:21
User: sud0er
Functions: cat
Tags: windows cygwin

I spent a bunch of time yesterday looking for the xsel package in Cygwin- turns out you can use the /dev/clipboard device to do the same thing.

net rpc shutdown -I ipAddressOfWindowsPC -U username%password
2009-05-31 07:18:01
User: LrdShaper
Functions: shutdown
Tags: Linux windows

This will issue a shutdown command to the Windows machine. username must be an administrator on the Windows machine. Requires samba-common package installed. Other relevant commands are:

net rpc shutdown -r : reboot the Windows machine

net rpc abortshutdown : abort shutdown of the Windows machine


net rpc

to show all relevant commands

wrestool -x --output . -t14 /path/to/your-file.exe
xprop | awk '/PID/ {print $3}' | xargs ps h -o pid,cmd
2009-02-16 07:55:19
User: jackhab
Functions: awk ps xargs

This command is useful when you want to know what process is responsible for a certain GUI application and what command you need to issue to launch it in terminal.