How to Remove Multiple Files from the Command Line

While web-based control panels are good for some tasks, bulk file management is not one of them.  It is quite a bit slower to have to navigate through various directories, especially if you have a good size dedicated server with many domains attached to it.  Using a web-based file manager can be downright painful.  Fortunately, a quick SSH into your server can make your problems literally go away.

To remove files from the command line in a Unix-like operating system such as Linux or FreeBSD, you can use the “rm” command.  As you might expect, “rm” stands for “remove”.  Normally, to remove one at a time, you would type:

rm filename

With that command, rm will prompt you before going ahead with the cleansing, giving you a chance to back out of it.  Add the “-f” flag to force it to go through without confirmation.

If all of your files are in the same directory, and you want to delete the entire directory, use the following command:

rm -rf directory

“-r” in this case stands for “recursive”, meaning it will not stop at a directory but will delete its contents and the directory itself.

If you only want to remove some of the files, type each name with a space separating them:

rm one.jpg three.jpg five.jpg seven.jpg

To remove all the files in a directory but not the directory itself, enter into the directory, and then use “*”.

cd directory

rm *

You can also remove files with certain extensions, like:

rm *.jpg

or remove ones containing a certain word

rm *certainword*

You can do much more with “rm” if you play around with it a bit, but remember, it does not move files to a “trash can”.  It deletes them permanently, meaning you will not be able to recover the files without drastic measures.











Comments: