Operating System - HP-UX
1832932 Members
3324 Online
110048 Solutions
New Discussion

Re: Removing a file name with a space

 
SOLVED
Go to solution
Gabriel McCray
New Member

Removing a file name with a space

How would I remove a filename with a space such as:

test 1

Based on some research, I thought it was impossible to run into something like this.

What should I do?

10 REPLIES 10
Robert-Jan Goossens
Honored Contributor
Solution

Re: Removing a file name with a space

Hi,

try this one

# rm -- test 1

or

# rm -- "test 1"
A. Clay Stephenson
Acclaimed Contributor

Re: Removing a file name with a space

No, the dumb UNIX box did just what you asked BUT it may not be a space - possibly a control character.

First do an ls -b to make sure that there are no non-printables in the filename.

Now, rm 'test 1' or if control characters are embedded rm -i test* and answer y to the file you want to delete.
If it ain't broke, I can fix that.
TwoProc
Honored Contributor

Re: Removing a file name with a space

try
rm -i ./*test*

Then, when the correct filename pops up on the list, answer yes. To all others, answer no. This should do it for you.
We are the people our parents warned us about --Jimmy Buffett
Dave La Mar
Honored Contributor

Re: Removing a file name with a space

Gab -
Back up one directory, then -

rm -i directory/tes*

Regards,
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Eileen Millen
Trusted Contributor

Re: Removing a file name with a space

Hi Gabriel,

The easiest way is to go into the file manager with the GUI interface.

Eileen
Michael Steele_2
Honored Contributor

Re: Removing a file name with a space

cd dir
ls -i *

find -inum -exec rm -f {} \;

Example:

find . -inum 17321 -exec rm -f {} \;
Support Fatherhood - Stop Family Law
Jose Mosquera
Honored Contributor

Re: Removing a file name with a space

Hi,

If you have a graphical ftp tool will be very easy, connect as "root", select and delete it!

Rgds.
Scott Van Kalken
Esteemed Contributor

Re: Removing a file name with a space

I prefer the rm -i option as well.

It's a neat way to see all of the other weird characters that are there too.
Bill Hassell
Honored Contributor

Re: Removing a file name with a space

Unix does indeed allow you to create almost any filename with characters from the keyboard. A lot depends on the program (or shell) used to create the filename. But as you've seen, there are many ways to remove filenames with special characters.


Bill Hassell, sysadmin
Alex Lavrov
Regular Advisor

Re: Removing a file name with a space

the best way to do it, is like in the first reply:
rm -- "test 1"

"--" option is a very useful thing, it says to rm, that from now on there will be no options, only the file names, did u ever try to remove file named "-alex" ? :)

good luck.