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 news Supermicro unveils AI-optimized storage powered by Nvidia New storage system features multiple Nvidia GPUs for high-speed throughput. By Andy Patrizio Oct 24, 2024 3 mins Enterprise Storage Data Center news Nvidia to power India’s AI factories with tens of thousands of AI chips India’s cloud providers and server manufacturers plan to boost Nvidia GPU deployment nearly tenfold by the year’s end compared to 18 months ago. By Prasanth Aby Thomas Oct 24, 2024 5 mins GPUs Artificial Intelligence Data Center news Gartner: 13 AI insights for enterprise IT Costs, security, management and employee impact are among the core AI challenges that enterprises face. By Michael Cooney Oct 23, 2024 6 mins Generative AI Careers Data Center news Network jobs watch: Hiring, skills and certification trends What IT leaders need to know about expanding responsibilities, new titles and hot skills for network professionals and I&O teams. By Denise Dubie Oct 23, 2024 33 mins Careers Data Center Networking PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe