Skip to main content
Share Your Experience: Take the 2024 Developer Survey
139 votes

Delete all files from a folder and its sub folders

Short and sweet PowerShell. Not sure what the lowest version of PS it will work with. Remove-Item c:\Tmp\* -Recurse -Force
Evan Nadeau's user avatar
  • 1,531
97 votes
Accepted

dd is producing a 32 MB random file instead of 1 GB

bs, the buffer size, means the size of a single read() call done by dd. (For example, both bs=1M count=1 and bs=1k count=1k will result in a 1 MiB file, but the first version will do it in a single ...
grawity_u1686's user avatar
82 votes
Accepted

Why is my if statement always false?

An if statement does not evaluate whether the command inside its condition ran successfully. It will only check the value (in your case the return of your command) and cast it to a bool. Copy-Item ...
SimonS's user avatar
  • 9,379
61 votes
Accepted

How to make windows explorer preview scripts and other text files

The answer came from this link this link as music2myear mentioned but the accepted answer in that link did not work for me. What worked for me was 2nd answer in the thread. Member user255627 points ...
Peter Moore's user avatar
  • 1,298
57 votes

How to execute a command whenever a file changes?

For those who can't install inotify-tools like me, this should be useful: watch -d -t -g ls -lR This command will exit when the output changes, ls -lR will list every file and directory with its ...
Sebastian's user avatar
  • 681
43 votes
Accepted

Is it possible to restart a computer in response to an email notification?

You want a device called a "Remote Power Switch", one that we have used at my workplace to remotely restart cable modems is the UIS-322b below: You can set it up with an IP address, and then log in ...
LawrenceC's user avatar
  • 74.1k
34 votes

How to execute a command in screen and detach?

In order to start new session in background with name 'sleepy' screen -S sleepy -dm sleep 60 In order to kill 'sleepy' session screen -S sleepy -X quit
Michal Zmuda's user avatar
33 votes

Is it possible to restart a computer in response to an email notification?

Can I setup a program, event, or a script that will tell the machines to reboot? It depends on what you mean by: they freeze or "stall" If the remote machine has hung in a way that requires a "...
DavidPostill's user avatar
  • 158k
29 votes
Accepted

Scripting connecting/disconnecting a paired Bluetooth device

I wrote C++ code to do it using Win32 Bluetooth API's BluetoothSetServiceState, but it's actually enough to use Bluetooth Command Line Tools. As it turns out, once all services in use by a device ...
MarcinJ's user avatar
  • 801
29 votes
Accepted

Is there a general purpose scripting language that I can expect to find on (almost) all Windows installations?

You don't need a general-purpose language if you can ship a compiled program – you're already writing a program in the first place; use the same method to write an Updater.exe alongside the main App....
grawity_u1686's user avatar
23 votes

Linux Bash Script, Single Command But Multiple Lines?

You can use this in bash PARAMS=( -cvpzf /share/Recovery/Snapshots/$HOSTNAME_$DATE.tar.gz --exclude=`enter code here`/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt ...
Axel Heider's user avatar
22 votes

How to manually stop a Python script that runs continuously on linux

Try this simple line, It will terminate all script.py: pkill -9 -f script.py
trex's user avatar
  • 375
22 votes

dd is producing a 32 MB random file instead of 1 GB

dd may read less than ibs (note: bs specifies both ibs and obs), unless iflag=fullblock is specified. 0+1 records in indicates that 0 full blocks and 1 partial block was read. However any full or ...
Kamil Maciorowski's user avatar
19 votes

How can I run an application with command line arguments in Mac OS

The open command has an optional --args argument that's value will be passed on to the opened application as arguments. For example: open /Applications/TextEdit.app --args example.txt
ecnepsnai's user avatar
  • 736
19 votes

Windows command prompt freezing randomly

Disable the QuickEdit Mode and\or Insert option from the cmd properties. Problem solved
malanve's user avatar
  • 191
17 votes

How to launch a command on network connection/disconnection?

It seems that Start only if the following network connection is available is broken after Windows 10 anniversary update. Use this custom trigger instead: <QueryList> <Query Id="0" Path="...
krrr's user avatar
  • 270
16 votes

Is it possible to restart a computer in response to an email notification?

If you have actual servers, they likely have a remote management feature that can be connected to even if the machine's main OS is completely frozen. Generally, you use SSH to connect to the ...
Ben N's user avatar
  • 41.1k
13 votes

Linux Bash Script, Single Command But Multiple Lines?

The same command, but with comments for each line, would be: tar -cvpzf /share/Recovery/Snapshots/$(hostname)_$(date +%Y%m%d).tar.gz `#first comment` \ --exclude=/proc `#second comment` \ --...
Alter Lagos's user avatar
13 votes

Is it possible to restart a computer in response to an email notification?

Use Outlook. Link at the bottom of the answer has information that helped with this answer. Kudos to GuidingTech.com Create a .bat file first. shutdown.exe /r /t 00 Save as Restart.bat Make sure ...
NetworkKingPin's user avatar
13 votes
Accepted

Batch command/script to do commands from .txt file?

I'm trying to find a command or a script that can run commands from a .txt file The simplest solutions are always the best. Use the following command: cmd < command.txt Or: type command....
DavidPostill's user avatar
  • 158k
13 votes

Downloading Google Chrome using Powershell

With winget: winget install -e --id Google.Chrome It is a Windows package manager from Microsoft and part of the App Installer https://apps.microsoft.com/detail/9NBLGGH4NNS1 Install via Install-...
cachius's user avatar
  • 396
12 votes
Accepted

Using sed command for a specific line

Just add the line number before: sed '<line number>s/<search pattern>/<replacement string>/. $ sed '1s/state0/XXXX/' file id311 vmName1 XXXX id312 vmName2 state0 id313 ...
fedorqui's user avatar
  • 1,967
11 votes

OpenVPN --up script - "could not execute external program"

Just to make it clear: I forgot the "!" (exclamation mark). That's explain everything. #!/bin/bash
exetico's user avatar
  • 323
10 votes

Scripting connecting/disconnecting a paired Bluetooth device

win 10 shortcuts https://www.windowscentral.com/best-windows-10-keyboard-shortcuts win-key + K opens the sidebar menu and instantly searches for bluetooth devices. then click on your already paired ...
BaBis fLou's user avatar
10 votes

read in Bash and ZSH

The options for the read command are significantly different between bash and zsh. In this case, the problem is that -n has completely different meanings between the two: in bash, it says how many ...
Gordon Davisson's user avatar
9 votes

Bash: create anonymous fifo

While @DavidAnderson's answer covers all the bases and offers some nice safeguards, the most important thing it reveals is that getting your hands on an anonymous pipe is as easy as <(:), as long ...
clacke's user avatar
  • 308
9 votes

How to execute a command in screen and detach?

screen -dmS screen_session_name bash -c 'echo "doing stuff"; exec bash'
tkjef's user avatar
  • 191

Only top scored, non community-wiki answers of a minimum length are eligible