LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-18-2009, 09:10 AM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
How to delete a file who's name starts with a space via CLI


I have a file that when I do a ls -l it shows it as having a space as the first character in its name. how can I do a rm on just that one file? i'm not having any luck due to that space to start the file name.
 
Old 12-18-2009, 09:17 AM   #2
thorkelljarl
Senior Member
 
Registered: Jun 2008
Posts: 1,820

Rep: Reputation: 229Reputation: 229Reputation: 229
What about...

Have you tried the wildcard "?" to replace the blank space?

If so, what else have you tried and what results did you get? Have you tried to quote the file name?

Last edited by thorkelljarl; 12-18-2009 at 09:26 AM.
 
Old 12-18-2009, 09:20 AM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
That worked, thanks. is the ? just for a single character wildcard?
 
Old 12-18-2009, 09:28 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Code:
# EXAMPLE:
% ls -l
-rw-r--r--    1 paulsm   users           0 Dec 18 08:34  has a space
-rw-r--r--    1 paulsm   users           0 Dec 18 08:36 another_file
-rw-r--r--    1 paulsm   users           0 Dec 18 08:36 some_file

# Use a wildcard.
# Be sure to check your wildcard syntax with an "ls" 
# before you actually delete anything!
% ls -l ?has*
-rw-r--r--    1 paulsm   users           0 Dec 18 08:34  has a space

# If the wildcard deletes what you want - and ONLY what you want - go for it!
% rm ?has*
'Hope that helps .. PSM
 
Old 12-18-2009, 09:29 AM   #5
thorkelljarl
Senior Member
 
Registered: Jun 2008
Posts: 1,820

Rep: Reputation: 229Reputation: 229Reputation: 229
That was easy...

"?" is for one character. Read and learn more.

http://www.tuxfiles.org/linuxhelp/wildcards.html
 
Old 12-18-2009, 09:34 AM   #6
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Thanks to you both.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete system log file but the space not released yuanjunliang Linux - Server 2 09-05-2010 04:15 AM
scripting: how to cp a list of files which starts with - or space without - or space? simransab Linux - Newbie 8 10-15-2009 04:12 AM
Delete system log file but the space not released yuanjunliang Linux - Newbie 1 04-23-2009 03:09 PM
delete a file that starts if a "-" (minus) sign Four Linux - Newbie 2 03-14-2008 04:55 PM
Can't delete a file that starts with - vtrac Linux - Software 4 04-17-2006 05:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:22 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration