Delete all hidden files recursively in current directory
5,877
Not really one single command, but why make it more complicated than necessary?
find -type f -name ".*" -delete; rm *~
The first command removes all files starting with .
and the second one all ending with ~
Related videos on Youtube
Author by
Vicky Dev
B.E. COMPUTER ENGG. WEB DEVELOPER (PHP/Magento/Wordpress/jQuery/Core Javascript/PrototypeJs/)
Updated on September 18, 2022Comments
-
Vicky Dev over 1 year
I have a directory which contains hidden files and by that I mean, not just the files whose name starts with
.
but also the files whose name contains~
character at the end likesomefile.txt~
.I want to delete only those files (the remaining files need to be unaffected) in an efficient way.
How I can achieve that with a single command ?
Ubuntu 14.04 Trusty Tahr.
-
SE - stop firing the good guys almost 8 yearsOne way of doing this is
rm $(ls -a | grep -e "^\.[a-zA-Z0-9_ ].*" -e ".*~")
Perhaps a bit wordy, but is does the job without deleting anything it should not.
-
-
Vicky Dev almost 8 yearsNot working, got following error:
rm: cannot remove ‘.’: Is a directory rm: cannot remove ‘..’: Is a directory
-
Wayne_Yux almost 8 yearsah yes, I overlooked this. This is because
.*
is also expanded to the directories.
and..
.which cannot be deleted. See my edit for an alternative command that does not cause the error. -
SE - stop firing the good guys almost 8 yearsConfirmed to work.
-
Vicky Dev almost 8 yearsStill not working for me, I have hidden files with name ending in
~
, but they aren't deleted. -
Wayne_Yux almost 8 yearsare they found with
ls *~
? are they write-protected? -
Vicky Dev almost 8 yearsNope, not getting by that command either. Not even with
ls -R *~
. -
Wayne_Yux almost 8 yearswhat about
ls *~*
?