简体   繁体   English

Cmder别名到现有循环

[英]Cmder alias to existing loop

I have a loop that basically recursively removes folders by foldername: 我有一个循环,该循环基本上以文件夹名称递归地删除文件夹:

for /d /r . %d in (node_modules) do @if exist "%d" rm -rf "%d" 

This works fine, if i run it by itself inside cmder, it will loop from the current set directory and then remove any instance it finds. 如果我自己在cmder中运行它,它将很好地运行,它将从当前设置的目录中循环,然后删除找到的任何实例。

I figured seeing as it's a one liner I could easily add it as an alias to cmder by doing: 我发现这是一个衬里,因此我可以轻松地将其作为cmder的别名添加,方法是:

cnode=for /d /r . %d in (node_modules) do @if exist "%d" rm -rf "%d" 

cnode == (clean node), it's just something easy to remember, however when I run the command it doesn't actually do anything at all. cnode ==(干净节点),这很容易记住,但是当我运行命令时,它实际上什么也没做。

Any ideas? 有任何想法吗?

find ./node_modules -name 'foo' -type d -exec rm -rf {} \\;

or find in node_modules any directory named 'foo' and run rm -rf on it 或在node_modules中找到任何名为“ foo”的目录并在其上运行rm -rf

it can wildcard too: 它也可以通配:

find ./node_modules -name 'foo*' -type d -exec rm -rf {} \\;

if you want it to be an alias you have to make it a function. 如果要使其成为别名,则必须使其具有功能。 create a file aliases and make it: 创建文件aliases并使其:

#!/bin/bash function remove_dir () { find ./node_modules -name "'$1*'" -type d -exec rm -rf {} \\; }

and what someone else said, you're doing batch on windows, if you can use bash, i've given it to you 还有其他人说的,您正在Windows上进行批处理,如果可以使用bash,我已将其提供给您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM