In Unix, how do you remove everything in the current directory and below it?

前端 未结 10 1960
庸人自扰
庸人自扰 2021-01-29 21:57

I know this will delete everything in a subdirectory and below it:

rm -rf 

But how do you delete everything in the current d

10条回答
  •  盖世英雄少女心
    2021-01-29 22:28

    What I always do is type

    rm -rf *
    

    and then hit ESC-*, and bash will expand the * to an explicit list of files and directories in the current working directory.

    The benefits are:

    • I can review the list of files to delete before hitting ENTER.
    • The command history will not contain "rm -rf *" with the wildcard intact, which might then be accidentally reused in the wrong place at the wrong time. Instead, the command history will have the actual file names in there.
    • It has also become handy once or twice to answer "wait a second... which files did I just delete?". The file names are visible in the terminal scrollback buffer or the command history.

    In fact, I like this so much that I've made it the default behavior for TAB with this line in .bashrc:

    bind TAB:insert-completions
    

提交回复
热议问题