3

I've created a linux bash file in a windows text editor. This file contained commands for moving files to another location under linux.

After i ran this file i discovered that destination files have "\r" symbol in their end. (I guess this is because linux and windows use different line end symbols)

So 'Dir' command shows that i have files like these: "httpd.conf\r" while 'ls' shows the same filename as: "httpd.conf?"

How do i delete these files ?

These commands do not work:

Rm httpd.conf\r
Rm httpd.conf\\r
rm 'httpd.conf\r'

I receive the following error:

rm: cannot lstat `httpd.confr': No such file or directory

5 Answers 5

5

The simpler way would be:

rm -i httpd.conf?
0
5

If you get a really chewy filename, you can delete it by inode: run ls -il to get the inode number, then use: find -inum <inode number> -exec rm -i {} \; to delete it.

(Credit to one of my old bookmarks for this one: http://www.cyberciti.biz/tips/delete-remove-files-with-inode-number.html)

1
  • This should be the marked answer.
    – Roman
    Aug 5, 2019 at 18:49
2

If you are using bash and bash's tab completion is enabled you can use it to complete the filename with the character in question automatically escaped.

2

You can do:

rm $'httpd.conf\r'

or

rm 'httpd.conf^M'

You obtain ^M by pressing Ctrl-v then Ctrl-m.

1

Suppose you have two files in the same directory:httpd.conf and httpd.conf\r.

Copy the file(s) you want to keep:

$ sudo cp httpd.conf httpd-keep.conf

Simply remove ALL files that start with httpd.conf:

$ sudo rm httpd.conf*

Restore the original file:

$ sudo mv httpd-keep.conf httpd.conf

You need to BACKUP ALL OTHER FILES that start with "httpd.conf" if any before executing the rm command as shown above.

You must log in to answer this question.

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