2

I recently unpacked a set of backup files in RHEL3 - 2.4kernel with tar via:

tar -xvf backupfile

It started to error out a bunch and I aborted thinking that maybe it was a gzip instead. Unpacking via:

tar -zxvf backupfile

Worked fine but now I have a handful of files that are highlighted red with crazy random names. I am unable to delete them using rm -f. Is there any thing else I can do? I'm root, they are owned by root/root. Any help is greatly appreciated! Thanks.

6
  • What do you mean by "I am unable to delete them using rm -f."? Is it that you're unable to type the filenames, because they're "crazy" and "random"? Or are you successfully typing the names, but rm is giving you an error message? If the latter, what is the error message? Oct 20, 2014 at 23:04
  • Sorry, I should have been more clear. I've input "rm -f filename" after pressing enter, rm completes as if successful. When I check the directory, the file remains.
    – Chris N
    Oct 20, 2014 at 23:14
  • Part of the meaning of the -f flag to rm is "ignore nonexistent files". For example, if you were to type something like rm -f the_quick_brown_fox_jumps_over_the_lazy_dog, you'll get a shell prompt (with no error message), but nothing will happen (unless you happen to have a file by that name). I suspect that the file names have invisible control characters, and so you're just not typing them accurately. One quick way to check this would be to type the rm commands without -f. Oct 20, 2014 at 23:19
  • Ok, this makes sense so for instance when I type the full filename of a file that does not have control characters(I wouldn't know how to type those anyway), I get a command prompt (>) after: rm -f ?=?e??}1?21?t?Q?????G4b&?V???n??ZX?4h"??cPD?3Dja%?F?B??HY+?????????g??[`?*????}??O???_?^?*????.&?T please excuse my syntax errors and thanks for trying to help. How can I delete a file with such a long name, I tried "*" to no avail.
    – Chris N
    Oct 20, 2014 at 23:28
  • Update: Typing rm without -f gives me a sub-prompt (>) and nothing else. rm ?=?e??}1?21?t?Q?????G4b&?V???n??ZX?4h"??cPD?3Dja%?F?B??HY+?????????g??[`?*????}??O???_?^?*????.&?T then one line below >
    – Chris N
    Oct 20, 2014 at 23:46

2 Answers 2

0
  • Quite possibly the easiest way to clean up your directory is to
    • Save backupfile (the tar file) somewhere safe,
    • Delete the entire directory,
    • Restore the tar file, and
    • Extract it again.
  • But if you’d rather just delete the files that you want to delete, you could:
    • Use wildcards.  Find wildcard patterns that match the files you want to delete, and only them.  Check that they match the files you want to delete, and only them, by typing ls -ld wildcard.  If that shows you the files you want to delete, and only them, then type rm wildcard.
      • For example, if all the “crazy”, “random” filenames are longer than 17 characters, and all your valid filenames are shorter than that, use ?????????????????*.
      • If there’s a file that you want to delete whose name has an = as the second character and an e as the fourth, and that doesn’t describe any of your valid files, then use ?=?e*.
    • Type rm -i * .*.  The -i (interactive) option tells rm to ask for confirmation for each file.
    • Type find . -type f -ok rm {} \;.  This is a lot like the rm -i; it will display the filenames and ask whether you want to delete them.
1
  • I used rm -i * .* in this case. It helps a lot when it's nearly impossible to type the characters in these file names and wildcards weren't working. Thank you!
    – Chris N
    Oct 21, 2014 at 15:11
1

Prefer tar tzf mytar.tgz | xargs rm -r

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .