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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands tagged windows from sorted by
Terminal - Commands tagged windows - 74 results
sajb {$ip="";$old=0;while(1){$up=test-connection -quiet -count 1 $ip;if($up-ne$old){$s=(date -u %s).split('.')[0]+' '+(date -f s).replace('T',' ')+' '+$ip+' '+$(if($up){'Up'}else{'Down'});echo $s|out-file -a $home\ping.txt;$old=$up}sleep 10}}

IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type


Uses sajb to start a PowerShell background job that pings an IP host every 10 seconds.

Any changes in the host's Up/Down state is time-stamped and logged to a file.

Date/time stamps are logged in two formats: Unix and human-readable.

A while(1) loop repeats the test every 10 seconds by using the sleep command.

See the Sample Output for more detail.

I use this command to log Up/Down events of my Motorola SB6141 cable modem (

To end the logging, close the PowerShell window or use the "exit" command.

while(1){while((date -f ss)%10-gt0){sleep -m 300} echo "$(date -u %s) $((curl|%{$_ -replace '\D+\n',''})">>modemlog.txt;sleep 1;echo .}
2015-12-24 02:12:10
User: omap7777
Functions: date echo sleep

IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type


Create a log file of your Motorola Surfboard SB6141 downstream signal strengths.

Uses the built-in curl to request signal strength data from your SB6141 cable modem.

HTML page has the signal strength numbers for the 8 downstreams.

Some HTML/DOM processing parses out the 8 values from the above page.

The eight extracted signal strengths are then logged to a file.

A small while-loop watches the clock & repeats the process every 10 seconds.

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

dsquery computer DC=example,DC=com -limit 150 | find /c /v ""
net user user_name new_password /domain
Set-Mailbox -Identity John -DeliverToMailboxAndForward $false -ForwardingSMTPAddress [email protected]
Add-ADPermission "username_mailbox" -User "Domain\User" -Extendedrights "Send As"
Add-MailboxPermission -Identity "username_of_mailbox_owner" -User username_control_to -AccessRights Fullaccess -InheritanceType all
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.

dsquery group -samid "group_name" | dsmod group "cn=group_name",dc=example,dc=com" -addmbr
dsadd group cn=group_name,dc=example,dc=com -secgrp yes -scope g -samid group_name
2014-03-06 15:25:17
Functions: yes
Tags: windows group cmd

-secgrp no for distribution

-scope u for distribution

icacls directory_or_file /grant user_or_group:(OI)(CI)rx /t / l /q
wmic product | findstr /I "name_of_app"
sc query service_name
dsquery group -samid "Group_SAM_Account_Name" | dsget group -members -expand
Enable-DistributionGroup Name-of-Dist-Group
2014-01-07 18:49:07

To disable the requirement for the sender to be authenticated:

Set-DistributionGroup -Identity Name-of-Dist-Group -RequireSenderAuthenticationEnabled $false

To disable the group:

disable-DistributionGroup Name-of-Dist-Group

dsquery computer -name COMPUTERNAME -inactive 4
putty -L 631:localhost:631 [email protected]
net user USERNAME /domain
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
FOR %I IN (*.mp4) DO \Tools\ffmpeg\bin\ffmpeg.exe -i "%I" "%~nI.mpeg"
cls && ipconfig | findstr -R "[ IPv4 | adapter ]"