If you're thinking of something like
ls foo*.txt vs.
rm foo*.txt, then yes, they will show and remove the same files. The shell expands the glob, and passes it to the command in question, and the commands work on the listed files. One listing them, one removing them.
The obvious difference is that if any of those files happened to be a directory, then
ls would list its contents, but
rm would fail to remove it. That's usually not a problem, since
rm would remove less than what was shown by
The big issue here comes from running
ls * or
rm * in a directory containing filenames starting with a dash. They would expand to the command lines of the two programs as if you wrote them out yourself, and
ls would take
-r to mean "reverse sort order", while
rm would take
-r to mean a recursive removal. The difference matters if you have subdirectories at least two levels deep. (
ls * will show the contents of the first level directories, but
rm -r * will everything past the first sublevel, too.)
To avoid that, write permissive globs with a leading
./ to indicate the current directory, and/or put a
-- to signal the end of option processing before the glob (i.e.
rm ./* or
rm -- *).
With a glob like
*.txt, that's actually not an issue since the dot is an invalid option character, and will cause an error (until someone expands the utilities to invent a meaning for it), but it's still safer to put the
./ there anyway.
Of course you could also get different results for the two commands if you changed the shell's globbing options, or created/moved/removed files in between the commands, but I doubt you meant any of those cases. (Dealing with new/moved files would be extremely messy to do safely.)
rmdoes not have a
find -deletebe better than
rm? You say "That is why", but it's completely unclear to me what that refers to. Also note that your
findinvocation will delete all files recursively in the current directory, where
rmwill just delete the files in the immediate directory. Also
-name *is a no-op. All in all, I'm quite puzzled by your advice...
findis because you can run it, see all the files, and then run the same command with
-delete. Since you already saw the results from
find, there should be no ambiguity to what will be removed (I'd actually like to hear more details about this in the form of an answer)
-delete" - But how is that better than running
ls <filespec>, followed by
rm <filespec>(which the OP already knows how to do)?
find ... -printfirst to confirm what files would be deleted, and then
find ... -delete, you'll still delete files created between the two commands. If you use both
-delete, you don't get confirmation, just an after-the-fact report of what has been deleted (and you might as well use