Backslashes in Filenames


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Backslashes in Filenames
# 1  
Old 10-28-2008
Backslashes in Filenames

Using a small script, I automatically generated some text logs. The files ended being undownloadable, unopenable and undeletable. Upon further investigation, the files ended up looking like this:

log\r
log2\r
log3\r

I've tried a few different things, including double slashing before the r in order to try and get these files to be usable. I've adjusted the script so it no longer does this, but I'd like to be able to access these other logs.

Any ideas?
# 2  
Old 10-29-2008
Are the files isolated in a directory?

If so, you could try:
Code:
cat log*

... or something similar. The best way around this problem is probably to use a wildcard match rather than include the \ literal.
# 3  
Old 10-29-2008
No. They're not. Let me try that though and see if it does any good.
# 4  
Old 10-29-2008
If it doesn't help, you can try to connect via ftp and delete them from there. Sometimes it allows to use names, which on a shell may not be used or can't be correctly found.
# 5  
Old 10-29-2008
Yeah.. I tried that. I get critical error. The filenames don't show with the \r so I am certain that is causing some sort of conflict with the filename. I've tried renaming with wildcards. Frustrated.

Thanks for all the suggestions. I do appreciate it.
# 6  
Old 10-29-2008
Try ls -lab to find out exactly what characters are in the filenames and (more importantly) how many characters are there.
Then "ls" each file with question marks for the doubtful characters to make sure you can refer to the file uniquely.
Then rename (mv) each file - again using question marks for the doubtful characters.
Finally delete the renamed file.
# 7  
Old 10-29-2008
Here is a dead-sure way of erasing even the most nastily named file:

get the inode number by using "ls -lai":

Code:
bakunin@machine # ls -lai
246400 drwxr-x---   5 user     staff           256 Oct 21 15:08 .
246236 drwxr-x---   4 user     staff           256 Oct 17 14:26 ..
246237 drwxr-x---   2 user     staff           256 Oct 14 15:50 SPECS
249856 drwxr-x---   2 root     admin           256 Oct 21 15:08 aix
246613 -rw-r-----   1 user     staff          6499 Oct 20 12:45 some_file_with_a_funny_name

Now use the inode for a "find"-command:

Code:
bakunin@machine # find . -inode 246613 -exec rm -f {} \;

Instead of "rm" use whatever command you want to apply to the file. This will even work on files named "..." (yes, this is legal - if you want to torture your sysadmin) or something like that.

But in your case it might be even simpler than that: if the "\r" in the filenames are real character and not the visualization of some nasty control chars (find out by piping "ls -la" to a file and use "set list" in vi to display control codes) then simply escaping the backslash should suffice: "filename\\r" for what is displayed as "filename\r", etc.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing FileNames

Hi, Its been a long time since I've done any shell scripting and I need some help here. Thanks in advance... I need this as a bourne or csh script running under SCO. In a folder I have a list of Backup files named with "TarBackup plus a date and time component suffix" like this; ... (2 Replies)
Discussion started by: stanlyn
2 Replies

2. Shell Programming and Scripting

Script to add backslashes to end of certain lines of text

I'd like to write up notes in a relatively readable format and then use a shell script to add LaTeX formatting. Specifically, I'm trying to figure out how to add the LaTeX newline character (\\) to the end of lines without \begin{} or \end{} statements example notes file: \begin{enumerate} --... (2 Replies)
Discussion started by: icskittles
2 Replies

3. AIX

filemon with no filenames...

i excuted filemon with filemon -u -o /tmp/filemon.out -O all;sleep 60; trcstop. everything is ok, but i only get PID for filenames in Most Active Files. is there any different flags i need to use to get filenames? Code tags please, thanks. (3 Replies)
Discussion started by: curtis911
3 Replies

4. UNIX for Dummies Questions & Answers

printing backslashes

printf "\\" prints a backslash.how we can print multiple backslashes such as "\\\\\\\\\\\\\\\\\\\\". Thanks (4 Replies)
Discussion started by: pandeesh
4 Replies

5. Shell Programming and Scripting

escaping backslashes to evaluate paths

Hi there, i am struggling with this one, basically i want to replace an existing path string in a file with a new one, but the new one contains slashes which causes problems with "sed", i thought i could change the replacement string into a variable but of course when the variable is evaluated... (4 Replies)
Discussion started by: surfbus78
4 Replies

6. Shell Programming and Scripting

Replacing 3 backslashes with 2 in a string

Hi, I have a requirement where i need to replace 3 backslashes with 2 in the below mentioned string, but i am facing problem with backslashes. However i tried the option below but doesnt work. My input remains a constant as i receive it from my upstream. Input String= "-rfile... (3 Replies)
Discussion started by: kk_madrid
3 Replies

7. UNIX for Dummies Questions & Answers

Inserting commas and replacing backslashes with commas

Hi, Newbie here. I have a file that consists of data that I want to convert to a csv file. For example: Jul 20 2008 1111 / visit home / BlackBerry8830/4.2.2 Profile/MIDP-2.0 Configuration/CLOC-1.1 VendorID/105 Jul 21 2008 22222 / add friend / BlackBerry8830/4.2.2 Profile/MIDP-2.0... (3 Replies)
Discussion started by: kangaroo
3 Replies

8. Shell Programming and Scripting

Trouble with Backslashes

Hi folks, there are windows device names in the sixth column of a comma separated file. A example device name is: \\.\Tape0 I don't get the all string in to a variable, because of the preceding backslash. The first backslash is just cut off and my attempts to manipulate the string afterward... (0 Replies)
Discussion started by: wibo1
0 Replies

9. Shell Programming and Scripting

How to echo 4 backslashes more easy ?

How to echo 4 backslashes more easy ? I can use 16 to echo 4 backslashes. # echo \\ \ # echo \\\\ \ # echo \\\\\\ \\ # echo \\\\\\\\ \\ # echo \\\\\\\\\\ \\\ # echo \\\\\\\\\\\\ \\\ # echo \\\\\\\\\\\\\\ \\\\ (4 Replies)
Discussion started by: sun-guy
4 Replies

10. Shell Programming and Scripting

spaces in filenames

I have a problem with the script below #!/bin/sh for vo in `find -maxdepth 1 -type f -regex "^\./*$"` do ls -l "$vo" some other commands done It works fine until `find ...` returns files with spaces. I've tryed to change IFS but haven't succeed Any solutions? (4 Replies)
Discussion started by: Hitori
4 Replies
Login or Register to Ask a Question