Here are some ways to deal with troublesome files on your Unix or Linux system. Oops! Wrong location! If you accidentally extract files from a tar file into the wrong location and want to reverse the process, here’s a fairly easy way to do that. Say you just extracted some files meant for /var/app/bin into /bin instead. Oops! You can spend a lot of time looking through a listing of the archive you just extracted from or you can remove the files with a command that contains a variation of the extract command. If, for example, you used the command tar xvf bin.tar.gz to extract the contents, then you could use this command to remove the files. $ rm -f `tar ztf bin.tar.gz` What does this command do? The backticked section creates a list of all the files in the archive and rm -f command then removes them. The command won’t replace files that might have been overwirtten by same-named files on the archive you extracted from (unlikely to have happened) and it won’t remove files that just happen to have blanks in their names as the remove command will assume a file named “my favorite file” is actually three separate files. Clearing out files that are open Removing files that are rapidly consuming disk space but still open by some executable can at times be critical. The command shown below removes the contents by essentially cat’ing /dev/null to the file — even if the file is still in use and growing. > filename Removing files that start with a hyphen Removing files with odd characters in their names can be troublesome. Filenames that begin with a hyphen confuse the shell because it assumes that the name is really a list of options. The easiest way to get past this problem is by adding a double hyphen after rm as shown in the command below. rm -- -myfile Removing or renaming files that contain odd characters Removing files with odd characters in their names is also fairly easy. You can put the name of the file in quotes. $ ls my* myfile my file my-file my*file myfile.why $ rm "my*file" $ ls my* myfile my file my-file myfile.why You can use a backslash character to keep the shell from translating the special character. $ ls my* myfile my file my-file my*file myfile.why $ rm my*file $ ls my* myfile my file my-file myfile.why If you have a file with a blank in its name, either of these commands will work as well. rm "my file" rm my file Removing files by inode number You can also remove files by using their inode number. You just have to first use the ls -i to get the inode num and then use this information in a find command that also removes the file. $ ls -i my* 413215 myfile 413234 my-file 413538 my*file 261319 myfile.why $ find . -inum 413538 -delete $ ls -i my* 413215 myfile 413234 my-file 261319 myfile.why Related content how-to Compressing files using the zip command on Linux The zip command lets you compress files to preserve them or back them up, and you can require a password to extract the contents of a zip file. By Sandra Henry-Stocker May 13, 2024 4 mins Linux opinion NSA, FBI warn of email spoofing threat Email spoofing is acknowledged by experts as a very credible threat. By Sandra Henry-Stocker May 13, 2024 3 mins Linux how-to The logic of && and || on Linux These AND and OR equivalents can be used in scripts to determine next actions. By Sandra Henry-Stocker May 02, 2024 4 mins Linux how-to Using the apropos command on Linux By Sandra Henry-Stocker Apr 24, 2024 3 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe