rm -rf equivalent on Windows batch script - linux

I want to delete multiple folders & files at once and the command should not broke even if some directories or files aren't preset. Also I use wildcards(*) to combine folder & file names.
I have the following command to delete folders in Ubuntu
rm -rf dist pkitree srktable cst_sign* cst_encrypt* *.log out
However when I try to do accompany the same in Windows batch like,
rd /s /q dist pkitree srktable cst_sign* cst_encrypt* *.log out 2> NUL
I still get error status and the wildcards are not recognised. Can someone help me achieving this behaviour in Windows as well?

You can try :
powershell -Command "Remove-Item -Recurse dist, *.log"

Related

How do I delete node_modules folder quickly?

When I want to delete a node_modules folder it takes ages when I delete it using Windows Explorer. How do I delete faster?
I use to have the same issue, taking hours to achieve the deletion until I found this workaround:
Select the node_modules folder. Do this with the file explorer.
Open Powershell as admin: press Alt+F, then S, then A.
Wait and accept to open Powershell as admin
Paste this command and press Enter: del /f/q/s *.* > nul.
WARNING
Please be sure to be in the folder node_modules. I mean, that the terminal path ends with ...\node_modules.
In the above command, we use the /f switch to force the deletion of read-only files. The /q switch enables quiet mode. The /s switch executes the command for all files in any folder inside the folder you’re trying to remove. Using *.* tells the del command to delete every file and > nul disables the console output improving performance and speed.
Wait for the process to take action.
Now go up one level in the directory with cd...
Finally use this command to delete the node_modules folder rmdir /q/s node_modules
In the above command, we use the /q switch to enable quiet mode, the /s switch to run the command on all the folders, and node_modules is the variable you need to specify to delete the folder you want.
If you get an error with Powershell try other terminals as administrator like Windows Terminal, Command Prompt (cmd) or third party terminals like ConEmu. I made this steps with Cmder and all the deletion was done in just 5 minutes. Off course this duration is variable according to the size of the folder.
References:
pureinfotech.com
ConEmu
Cmder
From you project folder use following command to delete it:
rd .\node_modules\ /s /q

Is there a way to delete all node_module without opening the every single project from local drive?

I have multiple project that uses node_modules which i didn't touched in month.
If i can remove node_module only that can save my 5 to 8 GB storage.
I found Command line tool to delete folder with a specified name recursively in Windows
But that shows delete file in specific folder like
D:\Project\Doing\prject1\
D:\Project\Complete\Project1\
FOR /d /r . %d IN (project1) DO #IF EXIST "%d" rd /s /q "%d"
But i don't want to search every directory to look for node_module instead i want to delete all the node_module folder from my PC (all
the drive) how can i do that?
If I need the node_modules back I can simply run npm install so clearing space is good idea for me.
I found the solution here that worked like a charm.
find . -name "node_modules" -exec rm -rf '{}' +
To list all your node_modules use this command in a command prom:
FOR /d /r . %d in (node_modules) DO #IF EXIST "%d" echo %d"
And for deleting you can do:
FOR /d /r . %d in (node_modules) DO #IF EXIST "%d" rm -rf "%d"
This will not work in powershell only cmd

Deleting all files in the src folder

I'm doing the react tutorial and I'm having trouble with step 3.
I put the lines in the tutorial
cd my-app
rm -f src/*
into my node.js command prompt and got "'rm' is not recognized as an internal or external command, operable program or batch file."
How can I work around this problem?
This doesn't go in your node.js prompt. It's an OS command. If you are using linux, OSX, or ubuntu-on-windows, you should type it in your terminal.
If you are using windows, you can use rmdir \S \Q src
If you are in linux or Mac OS you should do
cd my-app && rm -f src/*
This will remove all the files in src and will keep the folders its files.
If you want to remove everything from src then use:
cd my-app && rm -rf src/*

Delete all node_modules subfolders

I'm doing a HDD upgrade, and while trying to backup my NodeJS projects i realize that all node_modules subfolders have over 1 milion files.
So i'm looking for a way to remove all the node_modules subfolders and all their contents.
The projects are located in :
C:/Node/App1/node_modules/..
C:/Node/App2/node_modules/..
C:/Node/App3/node_modules/..
etc..
My OS is Windows 10, but i can try either Windows or Linux commands because i'm using cmder, and it accepts both types of commands.
For Linux:
cd Node
find . -maxdepth 2 -name node_modules -type d -exec rm -rf {} +
I tested this command in various situations and it seems to work fine.
for /d /r . %d in (node_modules) do #if exist "%d" rd /s/q "%d"
I'm not sure how it works, it's an adapted solution from Here, if you need more details.

how to recursively delete directory starting with "xxxxx"?

I need to delete Directories that are starting with particular String "user"and i need to delete all the sub-folders in the Directory too.
I used removedirectory which deletes directory only when it is empty.
Normally I would open a command window then cd to the directory you want to delete,
Enter the command: "del /S /F *.* *" to delete all files and subdirectories.
Backup to the parent directory: cd ..
Remove the directory: rmdir "user*"
Use "del/?" to see all the options for del.
If you have to do this in c++, you can use the "system()" call.
BTW: I did not test this just now, so no guarantee.

Resources