删除除4个最新目录外的所有目录

eve*_*nti 4 bash shell

我想删除父目录中除4个最新目录外的所有目录.你会怎么在Bash中这样做?

Lei*_*ell 9

ls -atrd */ | head --lines=-4 | xargs rm -rf
Run Code Online (Sandbox Code Playgroud)

编辑:为ls添加'a'参数