How can I delete one file from every place on my disk using Linux? In Windows’ I’d open up a command window and use the command
del archive.txt /s
but what’s the Linux equivalent?
Alright, I know about the del command in DOS, but I don’t know about the “/s” flag. I had to dig for quite a while before I finally found out that the “/s” switch deletes all files from subdirectories. As I suspected, what you’re trying to do is delete all files with the specified name regardless of where they are on your PC.
First off, this seems rather dangerous! If nothing else, I’d certainly start out in my own home directory (just use cd without any arguments and you’ll be taken there directly) to ensure that I didn’t accidentally delete a file that some other program (or user!) needed.
In any case, the Linux command you seek is find and it’s far more powerful than the DOS del command, but, um, more complex too.
To find all occurrences of a specific filename at the current point in the file system and below, use this command:
find . -name archive.txt
The output will be a list of fully-qualified filenames like “./save/archive/archive.txt” and similar. There are a couple of ways to delete this set of files, but I always use the xargs command in a pipe:
find . -name archive.txt | xargs rm
If you’re still unsure, add the “-i” flag to the rm command and it’ll ask you to confirm each and every deletion before it occurs.