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 How to find files on Linux There are many options you can use to find files on Linux, including searching by file name (or partial name), age, owner, group, size, type and inode number. By Sandra Henry Stocker Jun 24, 2024 8 mins Linux opinion Linux in your car: Red Hat’s milestone collaboration with exida With contributions from Red Hat and critical collaborators, the safety and security of automotive vehicles has reached a new level of reliability. By Sandra Henry Stocker Jun 17, 2024 5 mins Linux how-to How to print from the Linux command line: double-sided, landscape and more There's a lot more to printing from the Linux command line than the lp command. Check out some of the many available options. By Sandra Henry Stocker Jun 11, 2024 6 mins Linux how-to Converting between uppercase and lowercase on the Linux command line Converting text between uppercase and lowercase can be very tedious, especially when you want to avoid inadvertent misspellings. Fortunately, Linux provides a handful of commands that can make the job very easy. By Sandra Henry Stocker Jun 07, 2024 5 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe