仅在KSH中删除一级目录上的文件(Remove File on One Level of Directories only in KSH)

编程入门 行业动态 更新时间:2024-10-10 10:23:05
仅在KSH中删除一级目录上的文件(Remove File on One Level of Directories only in KSH)

我有一个rm命令清除特定目录中的所有文件。

#!/usr/bin/ksh cd /asd/ded/ses/ddd/rty/leg/ rm *.sas7bdat rm p_bt*

不幸的是它清除了这个目录下的所有文件,但是现在我只想在“父目录”中清除它,即“/ asd / ded / ses / ddd / rty / leg /”而不是“/ asd / ded / ses /” ddd / rty / leg / 21_11“这是它里面的子目录。

我知道在bash中可以使用rm级别。 KSH是否会改变,如果是,那么如何改变。

I have a rm command which clears all the files in a particular directory.

#!/usr/bin/ksh cd /asd/ded/ses/ddd/rty/leg/ rm *.sas7bdat rm p_bt*

Unfortunately it clears all the files under this directory, but now I just want it to clear in "parent directory" i.e. "/asd/ded/ses/ddd/rty/leg/" and not in "/asd/ded/ses/ddd/rty/leg/21_11" which is the child directory inside it.

I know level rm is possible in bash. Does it change for KSH and if yes then how.

最满意答案

孤寂的灵魂,

切普纳是对的。 ksh中“rm”的默认设置是仅删除当前目录中的文件。 您可以通过添加'-r'选项从下层目录中删除文件(递归)。

如果您正在观察不同的行为,则可能在配置文件中的某处设置了别名设置。 尝试输入'whence rm'以查看是否存在导致意外行为的别名。

例子。

>pwd /tmp >touch abc.txt >mkdir ced >touch ced/abc.txt >rm abc.txt (will remove abc.txt in /tmp, but leave the file in directory ced. >whence rm rm -f

LonelySoul,

Chepner is correct. The default for 'rm' in ksh is to only remove the files in the current directory. You can remove files from the lower directories (recursively) by adding the '-r' option.

If you are observing different behavior, you may have an alias setup somewhere in your profile. Try entering 'whence rm' to see if there is an alias that is causing you unexpected behavior.

Examples.

>pwd /tmp >touch abc.txt >mkdir ced >touch ced/abc.txt >rm abc.txt (will remove abc.txt in /tmp, but leave the file in directory ced. >whence rm rm -f

更多推荐

本文发布于:2023-08-07 12:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464167.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   目录   KSH   Remove   Directories

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!