Does 'rm files*' remove all matches from all sub-directories?
No. Normal globbing *
is not recursive and neither is rm
.
If a directory name matches, it won't be removed - you need the -r
flag to delete a directory.
So it's safe to do that if you're sure you want to delete those files.
You can also make rm
interactive
rm -i wordpress-*.sql
then it will ask for confirmation before deleting each file
Yes it does the trick for you and removes all files with that schema in the current directory. And NO, it does not removes files within the sub-directories.
When ever you are not sure what happens when you run a command like:
rm wordpress-*.sql
then just run it using ls
:
ls wordpress-*.sql
the files you see in output are the ones which will get removed.
When you are trying to get a list like: foo*
, it is better to use -d
switch with ls
to prevent listing files withing a directory named foobar/
etc.
ls -d foo*
This trick works for commands which are not used to do the job recursively.
The other thing you can do is to type your desired input, e.g: wordpress-*
then press Ctrl+Alt+*, and now all the matches are typed automatically in front of your command.
No, rm
does not recurse through subdirectories.
See Delete matching files in all subdirectories - SuperUser for methods for deleting files in subdirectories.
If you're ever concerned about accidentally deleting something important, use gvfs-trash
(which sends files to the trash) instead of rm
(which permanently deletes files).