LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 07-23-2010, 01:24 PM   #1
badwizard
LQ Newbie
 
Registered: Mar 2009
Posts: 6

Rep: Reputation: 0
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.
 
Old 07-23-2010, 01:40 PM   #2
rdgreenlaw
Member
 
Registered: May 2007
Distribution: Ubuntu 10.04
Posts: 58

Rep: Reputation: 16
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.
 
Old 07-23-2010, 01:48 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.
 
Old 07-23-2010, 03:45 PM   #4
badwizard
LQ Newbie
 
Registered: Mar 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 07-23-2010, 03:57 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Slackware
Posts: 14,880
Blog Entries: 2

Rep: Reputation: 3807Reputation: 3807Reputation: 3807Reputation: 3807Reputation: 3807Reputation: 3807Reputation: 3807Reputation: 3807Reputation: 3807Reputation: 3807Reputation: 3807
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.
 
Old 07-23-2010, 04:04 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.

Last edited by druuna; 07-23-2010 at 04:08 PM. Reason: Added -i option for safe execution.
 
1 members found this post helpful.
Old 07-23-2010, 04:37 PM   #7
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
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:

Last edited by GrapefruiTgirl; 07-24-2010 at 06:09 AM. Reason: removed extra junk which confused the post.
 
Old 07-23-2010, 07:43 PM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 239Reputation: 239Reputation: 239
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
 
Old 07-23-2010, 08:21 PM   #9
rdgreenlaw
Member
 
Registered: May 2007
Distribution: Ubuntu 10.04
Posts: 58

Rep: Reputation: 16
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!
 
Old 07-24-2010, 02:48 AM   #10
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
If everything else fails, try rm -i * . It will prompt you for confirmation; make sure you only confirm what you want to delete.
 
1 members found this post helpful.
Old 07-25-2010, 04:09 PM   #11
badwizard
LQ Newbie
 
Registered: Mar 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 07-25-2010, 07:49 PM   #12
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

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


Reply

Tags
command, escape, file, line, name, rm, sequence


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What does backslash n 033 means in echo -e "\033[1m linux"? mohit_parihar Linux - General 3 07-25-2010 08:21 PM
[SOLVED] How to delete a file who's name starts with a space via CLI rjo98 Linux - Newbie 5 12-18-2009 09:34 AM
Book to refer for RHCE 033 infovijay Linux - Certification 1 07-21-2009 11:19 PM
Remove file \033[2~evtlog.2009-01-07 indiancosmonaut Programming 3 02-10-2009 12:32 PM
[python] print "\033[5;",x,"H=>" datbenik Programming 1 01-05-2006 05:12 AM


All times are GMT -5. The time now is 05:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration