paulwong

一次删除前5个以外的其他文件夹的SHELL

子文件夹按字母排倒序,只保留前5个,其他的删除。
find path/to/folder/ -mindepth 1 -maxdepth 1 -type d | head -n -5 | xargs rm -rf

-find: the unix command for finding files / directories / links etc.
-/path/to/base/dir: the directory to start your search in.
-mindepth 1 -maxdepth 1 only search the first sub folder
-type d: only find directories
-head -n -5: Filter out all lines except the last 5
-xargs rm -rf: remove each given folder.

posted on 2020-07-27 11:35 paulwong 阅读(355) 评论(0)  编辑  收藏 所属分类: LINUX


只有注册用户登录后才能发表评论。


网站导航: