Operating System - Linux
1748239 Members
3618 Online
108759 Solutions
New Discussion юеВ

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 !!!