Operating System - Linux
1827468 Members
2874 Online
109965 Solutions
New Discussion

Re: Deleting an archive with an space

 
SOLVED
Go to solution
Manuales
Super Advisor

Deleting an archive with an space

Hi ....
how can i delete a file which contains an space ?
For example: there is a file named
root@user1> ls -1
log commands.txt
name of programs.txt
book to learn spanish.txt
root@user1>
If i aply: rm log* it can not deleted
how can i delete them?

Thanks, Manuales.

18 REPLIES 18
Jeff_Traigle
Honored Contributor

Re: Deleting an archive with an space

Put quotes around the file name:

rm "file name"
--
Jeff Traigle
Torsten.
Acclaimed Contributor

Re: Deleting an archive with an space

Simply put the name in quotes, like

"the name.log"

should work.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Stephen Keane
Honored Contributor

Re: Deleting an archive with an space

rm log[[:blank:]]*.txt

Will deal with more than one space, or tab between the "log" part of the name and the remainder.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Deleting an archive with an space

Hi Manuales:

A general variation of this problem is to handle a file with special, non-printing characters as well as embedded spaces. Here's one way to search-and-destroy those:

# cd filesystem
# find . -xdev name "bad*" -exec ls -li {} \;

(or):

# ls -ilb . #...in place of the above 'find'

Either the 'find' or the 'ls' alone will expose the inode number of the file in question. Now use it to delete the file, like this:

# find . -inum 152 -xdev -exec rm -i {} \;

REMEMBER that an inode number is only unique WITHIN a filesystem! Using an interactive 'rm' is always a safety net. The '-xdev' option of 'find' also insures that you do NOT cross mountpoints (filesystems).

Regards!

...JRF...
Sanjay_6
Honored Contributor

Re: Deleting an archive with an space

Hi,

Try some of the suggestion in this question posted in the forum before for a similar situation.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=953425

Hope this helps.

regds
Kent Ostby
Honored Contributor

Re: Deleting an archive with an space

In the directory where the file exists, type:

ll -i

this will list the inode number in the first column.

Like this:

571217 -rw-r--r-- 1 kmo users 0 Jan 3 12:52 fred

You're file's number will be different then 571217 of course.

With this information, you type:

find . -inum 571217 -exec rm {} \;

Of course, you would replace the 571217 with your inum.

Oz
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Manuales
Super Advisor

Re: Deleting an archive with an space

No, any of last recomendations worked.

do you know another one?

Thanks.
James R. Ferguson
Acclaimed Contributor

Re: Deleting an archive with an space

Hi (again) Manuales:

What didn't work? They doing this (as I first suggested):

# cd /tmp
# touch "book to learn spanish.txt"
# ls -li /tmp/"book*"
# find . -xdev -name "book*" -exec ls -li {} \;

...either command shows me 152 as the inode number on my filesystem. Hence:

# find . -xdev -inum 152 -exec rm -i {} \;
./book to learn spanish.txt: ? (y/n) y

Regards!

...JRF...
Manuales
Super Advisor

Re: Deleting an archive with an space

Hi James, i was refered to Torsten, Stephen and Jeff answer ...
now, in this moment i'm verifying the others answers ...
thanks !!!
Arturo Galbiati
Esteemed Contributor

Re: Deleting an archive with an space

Hi,
try rm -i *command*txt and confirm when asked.
probably rm log* doesn't run because the separator is not a speca but a non printable chars.
HTH,
Art
Stephen Keane
Honored Contributor

Re: Deleting an archive with an space

If my recommendation didn't work, then you don;t have spaces between the words making up the file name.

try the following to see non-printtable characters ...

# ll | cat -v

you can match each non-printable character with a '?'
Manuales
Super Advisor

Re: Deleting an archive with an space

Hi ..!!!
i can't delete the file !!!

the name of the file is: "-sh proceso.log"

how can i do it??

please help !!!

Thanks !!!
Tom Danzig
Honored Contributor

Re: Deleting an archive with an space

rm -- "-sh proceso.log"
Jeff_Traigle
Honored Contributor

Re: Deleting an archive with an space

Or by per the example in the rm man page:

rm "./-sh proceso.log"
--
Jeff Traigle
James R. Ferguson
Acclaimed Contributor

Re: Deleting an archive with an space

Hi Manuales:

Once again, the method I posted is generally applicable to files with *any* special characters. This includes files beginning with "-".

You can also do:

# touch /tmp/-
# cd /tmp
# rm -- -

The "--" syntax says that there are no more switches to a command and what follows is an argument; in this case a filename.

By the way, in my earlies posts, above, I dropped the hyphen form 'xdev'. The 'find' should read:

# find . -xdev -name "bad*" -exec ls -li {} \

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Deleting an archive with an space

Hi Manuales:

Once again, the method I posted is generally applicable to files with *any* special characters. This includes files beginning with "-".

You can also do:

# touch /tmp/-
# cd /tmp
# rm -- -

The "--" syntax says that there are no more switches to a command and what follows is an argument; in this case a filename.

By the way, in my earlies posts, above, I dropped the hyphen form 'name'. The 'find' should read:

# find . -xdev -name "bad*" -exec ls -li {} \

Regards!

...JRF...
Manuales
Super Advisor

Re: Deleting an archive with an space

Thanks all friends !!!

it was worked with:
rm -- "-sh proceso.log"

Thanks !!!
Manuales.
Manuales
Super Advisor

Re: Deleting an archive with an space

Hi Sanjay, thanks for link
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=953425

and Geoff Wild, thanks for link http://www.sas.upenn.edu/computing/help/Unix/special_char.html

Thanks, is very interesting this site !!!

:0D
Manuales.