LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   CLI Issues -- Annoying File name: \033[A\033[B\b\b , delete how? (http://www.linuxquestions.org/questions/linux-general-1/cli-issues-annoying-file-name-%5C033%5Ba%5C033%5Bb%5Cb%5Cb-delete-how-821750/)

badwizard 07-23-2010 01:24 PM

CLI Issues -- Annoying File name: \033[A\033[B\b\b , delete how?
 
First, please no giggling at seeing some Fortran source code. I would much rather be writing in python or some more modern language. Not my choice.

My issue is, however, that during the course of some Fortran execution, a file was created with some non-printable characters and some escape sequences. How do I delete this file? Here is a copy of my 'ls -l' output:
Code:

total 116
-rw-r--r-- 1 ##### users  7027 2010-07-08 07:10 \033[A\033[B\b\b
-rw-r--r-- 1 ##### users    0 2010-07-23 18:07 lsdump
-rw-r--r-- 1 ##### users  148 2010-07-01 20:10 makefile
drwxr-xr-x 2 ##### users  4096 2010-07-22 00:35 map/
drwxr-xr-x 2 ##### users  4096 2010-07-11 19:18 map2/
drwxr-xr-x 2 ##### users  4096 2010-07-13 23:54 map3/
drwxr-xr-x 2 ##### users  4096 2010-07-14 22:59 map4/
drwxr-xr-x 2 ##### users  4096 2010-07-15 06:53 map5/
-rwxr-xr-x 1 ##### users 14687 2010-07-22 00:34 psmod.f90*
-rw-r--r-- 1 ##### users  8347 2010-07-09 04:47 psmod.mod
-rw-r--r-- 1 ##### users 20920 2010-07-09 20:06 psmod.o
-rwxr-xr-x 1 ##### users  1988 2010-07-09 20:22 pstest.f90*
-rwxr-xr-x 1 ##### users 26521 2010-07-09 20:06 pstest.out*

The culprit file is \033[A\033[B\b\b.
The relevant commands attempted so far are:

$ rm \033[A\033[B\b\b
rm: cannot remove `033[A033[Bbb': no such file or directory

$ rm '\033[A\033[B\b\b'
rm: cannot remove `\\033[A\\033[B\\b\\b': no such file or directory

What gives? Is there another way to reference a file without the file name?
Shell is Bash on a Slackware machine.

rdgreenlaw 07-23-2010 01:40 PM

Hopefully this will work:

ls -b

This will list all the files in the current directory replacing unprintable characters by octal characters.

Then type

rm ?

Replace ? with the exact output of the ls command above.

druuna 07-23-2010 01:48 PM

Hi,

This might work:

Type rm \\0 and press the tab key. If all goes well the whole filename is expanded (including the needed escapes). Pressing enter would remove the file.

Hope this helps.

badwizard 07-23-2010 03:45 PM

A.
Quote:

Originally Posted by rdgreenlaw
ls -b
This will list all the files in the current directory replacing unprintable characters by octal characters.

Output of ls -b:
Code:

$ls -b
\033[A\033[B\b\b
lsdump
makefile
map
map2
map3
map4
map5
psmod.f90
psmod.mod
psmod.o
pstest.f90
pstest.out

Unfortunately I don't see any new information present.

B.
Quote:

Originally Posted by druuna
Type rm \\0 and press the tab key.

Also unfortunately, auto-complete does not work.
$ rm \\0 [TAB] does nothing.

Thanks for the stab at my problem.

TobiSGD 07-23-2010 03:57 PM

Try it with:
Code:

rm \\033[A\\033[B\\b\\b
I tried to generate a file with the given name with
Code:

touch \\033[A\\033[B\\b\\b
and to delete it with the command above, both worked.

druuna 07-23-2010 04:04 PM

Hi,

Ok, try using the file inode number to remove it.

First find the inode number of this file: ls -il
The inode number is in the first column.
Code:

$ ls -li
total 0
2080802 -rw-r----- 1 druuna internet 0 Jul 23 23:02 foobar

The blue part in the previous example.

Then remove it (replace InodeNumber with the found number) : find . -inum InodeNumber -exec rm -i {} \;

Hope this helps.

GrapefruiTgirl 07-23-2010 04:37 PM

Code:

sasha@reactor: touch $(printf '\033[A\033[B\b\b')
sasha@reactor: ls
\033[A\033[B\b\b
sasha@reactor: rm $(printf '\033[A\033[B\b\b')
sasha@reactor: ls
sasha@reactor:

:)

ghostdog74 07-23-2010 07:43 PM

Code:

# ls -ltrb
total 0
-rw-r--r-- 1 root root 0 2010-07-23 08:46 \033[A\033[B\b\b
-rw-r--r-- 1 root root 0 2010-07-23 08:46 file33.txt

$  rm -f "$(ls -1rt | grep -E "[[:cntrl:]]")"

$ ls -ltrb
total 0
-rw-r--r-- 1 root root 0 2010-07-23 08:46 file33.txt


rdgreenlaw 07-23-2010 08:21 PM

I had not thought of using grep to extract the filename based on the fact that it contained one or more control characters.

This is a very good solution by ghostdog74. Hope it works for you!

Wim Sturkenboom 07-24-2010 02:48 AM

If everything else fails, try rm -i * . It will prompt you for confirmation; make sure you only confirm what you want to delete.

badwizard 07-25-2010 04:09 PM

Thank you druuna, GrapefruiTgirl, and ghostdog74 for your advice: all three methods worked in my case only after a bit of tweaking:

Code:

$ls -li
total 0
284789 -rw-r--r-- 1 corey users 0 2010-07-25 21:07 \033[A\033[B\b\b
284790 -rw-r--r-- 1 corey users 0 2010-07-25 21:04 file.txt
284798 -rw-r--r-- 1 corey users 0 2010-07-25 21:08 lsdump
$ rm $(find ./ -inum 284789)
$ ls -li
284790 -rw-r--r-- 1 corey users 0 2010-07-25 21:04 file.txt
284798 -rw-r--r-- 1 corey users 0 2010-07-25 21:08 lsdump
$

Code:

$ls -li
total 0
284789 -rw-r--r-- 1 corey users 0 2010-07-25 21:07 \033[A\033[B\b\b
284790 -rw-r--r-- 1 corey users 0 2010-07-25 21:04 file.txt
284798 -rw-r--r-- 1 corey users 0 2010-07-25 21:08 lsdump
$ rm $(printf '\033[A\033[B\b\b')
$ ls -li
284790 -rw-r--r-- 1 corey users 0 2010-07-25 21:04 file.txt
284798 -rw-r--r-- 1 corey users 0 2010-07-25 21:08 lsdump
$

Code:

$ls -li
total 0
284789 -rw-r--r-- 1 corey users 0 2010-07-25 21:07 \033[A\033[B\b\b
284790 -rw-r--r-- 1 corey users 0 2010-07-25 21:04 file.txt
284798 -rw-r--r-- 1 corey users 0 2010-07-25 21:08 lsdump
$ rm $(ls | grep -E "[\[:cntrl:]]")
$ ls -li
284790 -rw-r--r-- 1 corey users 0 2010-07-25 21:04 file.txt
284798 -rw-r--r-- 1 corey users 0 2010-07-25 21:08 lsdump
$

Thanks again for all the help :D

GrapefruiTgirl 07-25-2010 07:49 PM

You can now mark this [solved] using Thread Tools, at the top of the thread. :)


All times are GMT -5. The time now is 04:20 PM.