How can I delete all files and subdirectories from current directory including current directory?
相关问题
- JQ: Select when attribute value exists in a bash a
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
- softlinks atime and mtime modification
相关文章
- How to replace file-access references for a module
- Check if directory exists on remote machine with s
- Reverse four length of letters with sed in unix
- Compile and build with single command line Java (L
- Why is file_get_contents faster than memcache_get?
- Transactionally writing files in Node.js
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
The
cd ..
is needed, otherwise it will fail since you can't remove the current directory.I think this would be possible under DOS / Windows CMD, but I can't quite find a way to pipe the data between commands. Someone else may know the fix for that?
operating system? on the *NIX-based stuff, you're looking for 'rm -rf directory/'
NOTE: the '-r' flag for 'recursive' can be dangerous!
You just can go back the target folder's parent folder, then use 'rm -rf yourFolder'. or you can use 'rm -rf *' to delete all files and subfolders from the current folder.
Under bash with GNU tools, I would do it like that (should be secure in most cases):
not under bash and without GNU tools, I would use:
why this more secure:
--
in cases our directory starts with a dash (non-bash:./
before the filename)pwd -P
not justpwd
in cases where we are not in a real directory but in a symlink pointing to it."
s around the argument in cases the directory contains spacessome random info (bash version):
cd ..
at the end can be omitted, but you would be in a non-existant directory otherwise...EDIT: As kmkaplan noted, the
--
thing is not necessary, aspwd
returns the complete path name which always starts with/
on UNIX