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 cygwin from sorted by
Terminal - Commands tagged cygwin - 18 results
cygstart --hide -wa runas powershell -WindowStyle Hidden -Command '"&{wevtutil el | foreach{wevtutil cl $_}}"'
2015-02-15 22:56:20
User: lowjax

Efficiently clear all Windows Event log entries from within a Cygwin terminal. Uses "cygstart" to launch a hidden "PowerShell" session passing a Powershell command to loop through and clear all Windows Event Log entries. Very useful for troubleshooting and debugging. The command should in theory elevate you session if needed.

One liner is based on the PowerShell command:

wevtutil el | foreach { wevtutil cl $_ }
sc query state= all | awk '/SERVICE_NAME/{printf"%s:",$2;getline;gsub(/DISP.*:\ /,"");printf"%s\n",$0}' | column -ts\:
2015-02-15 22:35:10
User: lowjax
Functions: awk column

Outputs Windows Services service name and display name using "sc query", pipes the output to "awk" for processing, then "column" for formatting.

List All Services:

sc query state= all | awk '/SERVICE_NAME/{printf"%s:",$2;getline;gsub(/DISP.*:\ /,"");printf"%s\n",$0}' | column -ts\:

List Started Services:

sc query | awk '/SERVICE_NAME/{printf"%s:",$2;getline;gsub(/DISP.*:\ /,"");printf"%s\n",$0}' | column -ts\:

List Stopped Services:

sc query state= inactive| awk '/SERVICE_NAME/{printf"%s:",$2;getline;gsub(/DISP.*:\ /,"");printf"%s\n",$0}' | column -ts\:
rsync -ahhmz --progress --stats [[user@]host:]/source/path/ [[user@]host:]/destination/path/
2014-11-13 18:52:45
User: juangmorales
Functions: rsync

Functionally the same as the Microsoft Robocopy (https://en.wikipedia.org/wiki/Robocopy) command below but with the benefits of compression and optionally specifying a user.

robocopy /e [//host]/source/path [//host]/destination/path


-a: archive mode - rescursive, copy symlinks as symlinks, preserve permissions, preserve modification times, preserve group, preserve owner, preserve device files and special files

-hh: Numbers in human-readable K=1024 format. Single "h" will produce human-readable K=1000 format

-m: don't copy empty directories

-z: use compression (if both source and destination are local it's faster to omit this)

--progress: Shows progress during the transfer and implies --verbose (verbose output)

--stats: Summary after the transfer stops

wmic OS get OSArchitecture /value | grep -Eo '[^=]*$'
2014-03-15 02:04:08
User: lowjax
Functions: get grep

Using "wmic get * /value" within any Cygwin shell will return lots of Win/Dos newline junk ie "^M$" at the end of found value line, two lines ("$" Unix newline) above, and three below. This makes storing and or evaluating wmic queries as variables a pain. The method i suggest strips the mentioned junk, only returns the value after "OSArchitecture=", and includes only one Unix style newline. Other methods using sed|awk|cut can only handle the output of wmic cleanly when piped or using multiple sed statements.

wmic OS get OSArchitecture /value | sed 's/\r//g;s/^M$//;/^$/d;s/.*=//'


wmic OS get OSArchitecture /value | grep -Eo '[^=]*$'

a much cleaner and slightly less costly alternative.

finfo() { [[ -f "$(cygpath "$@")" ]] || { echo "bad-file";return 1;}; echo "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")"|sed 's/\\/\\\\/g')"\" get /value)"|sed 's/\r//g;s/^M$//;/^$/d'|awk -F"=" '{print $1"=""\033[1m"$2"\033[0m"}';}
2013-12-30 07:47:41
User: lowjax
Functions: awk echo return sed

Pass the files path to finfo(), can be unix path, dos path, relative or absolute. The file is converted into an absolute nix path, then checked to see if it is in-fact a regular/existing file. Then converted into an absolute windows path and sent to "wmic". Then magic, you have windows file details right in the terminal. Uses: cygwin, cygpath, sed, and awk. Needs Windows WMI "wmic.exe" to be operational. The output is corrected for easy...

finfo notepad.exe finfo "C:\windows\system32\notepad.exe" finfo /cygdrive/c/Windows/System32/notepad.exe finfo "/cygdrive/c/Program Files/notepad.exe" finfo ../notepad.exe
dd bs=1M if=/dev/scd0 of=./filename.iso OR readom -v dev='D:' f='./filename.iso' speed=2 retries=8
2013-10-23 15:53:27
User: scotharkins
Functions: dd

This example is taken from Cygwin running on Win7Ent-64. Device names will vary by platform.

Both commands resulted in identical files per the output of md5sum, and ran in the same time down to the second (2m45s), less than 100ms apart. I timed the commands with 'time', which added before 'dd' or 'readom' gives execution times after the command completes. See 'man time' for more info...it can be found on any Unix or Linux newer than 1973. Yeah, that means everywhere.

readom is supposed to guarantee good reads, and does support flags for bypassing bad blocks where dd will either fail or hang.

readom's verbosity gave more interesting output than dd.

On Cygwin, my attempt with 'readom' from the first answer actually ended up reading my hard drive. Both attempts got to 5GB before I killed them, seeing as that is past any CD or standard DVD.


'bs=1M' says "read 1MB into RAM from source, then write that 1MB to output. I also tested 10MB, which shaved the time down to 2m42s.

'if=/dev/scd0' selects Cygwin's representation of the first CD-ROM drive.

'of=./filename.iso' simply means "create filename.iso in the current directory."


'-v' says "be a little noisy (verbose)." The man page implies more verbosity with more 'v's, e.g. -vvv.

dev='D:' in Cygwin explicitly specifies the D-drive. I tried other entries, like '/dev/scd0' and '2,0', but both read from my hard drive instead of the CD-ROM. I imagine my LUN-foo (2,0) was off for my system, but on Cygwin 'D:' sort of "cut to the chase" and did the job.

f='./filename.iso' specifies the output file.

speed=2 simply sets the speed at which the CD is read. I also tried 4, which ran the exact same 2m45s.

retries=8 simply means try reading a block up to 8 times before giving up. This is useful for damaged media (scratches, glue lines, etc.), allowing you to automatically "get everything that can be copied" so you at least have most of the data.

open() { explorer /e, $(cygpath -wap "${1:-$PWD}"); }
2013-08-08 14:49:15
User: applemcg

use the shell default positional parameter syntax ${X:-default} in lieu of testing.

google() { gg="https://www.google.com/search?q="; ff="firefox"; if [[ $1 ]]; then "$ff" -new-tab "$gg"$(echo ${1//[^a-zA-Z0-9]/+}); else echo 'Usage: google "[seach term]"'; fi }
2013-08-01 22:21:53
User: lowjax
Functions: echo

Usage: google "[search string]"

Example: google "something im searching for"

This will launch firefox and execute a google search in a new tab with the provided search string.

You must provide the path to your Firefox binary if using cygwin to $ff or create an alias like follows:

alias firefox='/cygdrive/c/Program Files (x86)/Mozilla Firefox/firefox.exe'

Most Linux flavors with Firefox installed will use just ff="firefox" and even OSX.

open(){ if [[ -n "$1" ]];then explorer /e, $(cygpath -mal "$PWD/$1");else explorer /e, $(cygpath -mal "$PWD");fi }
2013-07-31 01:15:14
User: lowjax

This alternative either opens the current working directory by just issuing the open function in the commandline. Or you can specify what directory you would like to open.

Example: open /cygdrive/c/Windows

Usage: open [path]

When no option is specified it will open the current working directory

wmr - | pv -s $SIZEOFMEM | ssh -p 40004 -c arcfour,blowfish-cbc -C root@savelocation.com "cat - > /forensics/T430-8gb-RAM1.dd"
2013-05-31 00:04:19
User: bhbmaster
Functions: ssh

wmr - | pv -s $SIZEOFMEM | ssh -p 40004 -c arcfour,blowfish-cbc -C root@savelocation.com "cat - > /forensics/T430-8gb-RAM1.dd"

Run above command from Windows Cygwin:

On Windows: Install Cygwin, and copy WMR (windows memory reader 1.0) memory diagnostic into cygwin\bin folder, also install cygwins netcat and ssh (openssh). I recommend installing apt-cyg and running "

On Linux: Have an SSH Server


WINDOWS: # wmr - | ssh root@savelocation.com "cat - > /tmp/FileToSave.dd"

For more details on how to extract information from memory dump:

apt-get install foremost

foremost -t all -T -i /forensics/T430-8gb-RAM1.dd

For more information:


while (true); do date --utc; done | uniq -c
startx -- -fullscreen -noresize -unixkill
google "search terms" #see description for more details
2011-07-04 09:37:39
User: husmanahmed
Functions: more

Inspired by: http://www.commandlinefu.com/commands/view/8744/search-google-on-os-x

#!/bin/bash if [ -n "$1" ] then firefox 'http://www.google.com/search?q="'$1'"' else firefox 'http://www.google.com' fi

Ive aliased this script as 'google' on my system and I can type 'google "search terms"' to open firefox with my search terms. My first post here, if there are any improvements to be made please let me know in the comments.

wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;" | while read FUNFACT; do notify-send -t $((1000+300*`echo -n $FUNFACT | wc -w`)) -i gtk-dialog-info "RandomFunFact" "$FUNFACT"; done
2010-04-02 09:43:32
User: mtron
Functions: grep read sed wc wget

extension to tali713's random fact generator. It takes the output & sends it to notify-osd. Display time is proportional to the lengh of the fact.

wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;"
2010-03-30 23:49:30
User: tali713
Functions: grep sed wget

Though without infinite time and knowledge of how the site will be designed in the future this may stop working, it still will serve as a simple straight forward starting point.

This uses the observation that the only item marked as strong on the page is the single logical line that includes the italicized fact.

If future revisions of the page show failure, or intermittent failure, one may simply alter the above to read.

wget randomfunfacts.com -O - 2>/dev/null | tee lastfact | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;"

The file lastfact, can then be examined whenever the command fails.

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.

lynx -dump randomfunfacts.com | grep -A 3 U | sed 1D
2009-05-05 07:52:10
User: xizdaqrian
Functions: grep sed

This is a working version, though probably clumsy, of the script submitted by felix001. This works on ubuntu and CygWin. This would be great as a bash function, defined in .bashrc. Additionally it would work as a script put in the path.