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 windows from sorted by
Terminal - Commands tagged windows - 68 results
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 manuel@contoso.com
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
0

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/.*=//'

making

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
0

-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
-8

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 username@server
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
0

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 ]"
cls && ipconfig | findstr -R "[ IPv4 | adapter ]"
cls && ipconfig | find "IPv4"
2013-12-03 13:08:01
User: dizzi90
Functions: find
1

May be useful to get user's ip address over the phone, as users struggle to read through a long ipconfig result.

wget "us.download.nvidia.com$(wget -qO- "$(wget -qO- "nvidia.com/Download/processFind.aspx?psid=95&pfid=695&osid=19&lid=1&lang=en-us"|awk '/driverResults.aspx/ {print $4}'|cut -d "'" -f2|head -n 1)"|awk '/url=/ {print $2}'|cut -d '=' -f3|cut -d '&' -f1)"
2013-11-21 03:04:59
User: lowjax
Functions: awk cut head wget
1

Download latest NVIDIA Geforce x64 Windows7-8 driver from Nvidia's website. Pulls the latest download version (which includes beta). This is the "English" version. The following command includes a 'sed' line to replace "english" with "international" if needed. You can also replace the starting subdomain with "eu." "uk." and others. Enjoy this one liner! 1 character under the max :)

wget "us.download.nvidia.com$(wget -qO- "$(wget -qO- "nvidia.com/Download/processFind.aspx?psid=95&pfid=695&osid=19&lid=1&lang=en-us" | awk '/driverResults.aspx/ {print $4}' | cut -d "'" -f2 | head -n 1)" | awk '/url=/ {print $2}' | sed -e "s/english/international/" | cut -d '=' -f3 | cut -d '&' -f1)"
net group groupname username /add /domain
icacls directory_or_file /grant user_or_group:(oi)(ci)(m,dc)
icacls directory_or_file /remove:g group_or_user