LinuxQuestions.org
Review your favorite Linux distribution.
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, 10:10 AM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,559

Rep: Reputation: 37
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, 10:17 AM   #2
thorkelljarl
Senior Member
 
Registered: Jun 2008
Posts: 1,742

Rep: Reputation: 196Reputation: 196
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 10:26 AM.
 
Old 12-18-2009, 10:20 AM   #3
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,559

Original Poster
Rep: Reputation: 37
That worked, thanks. is the ? just for a single character wildcard?
 
Old 12-18-2009, 10:28 AM   #4
paulsm4
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, 10:29 AM   #5
thorkelljarl
Senior Member
 
Registered: Jun 2008
Posts: 1,742

Rep: Reputation: 196Reputation: 196
That was easy...

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

http://www.tuxfiles.org/linuxhelp/wildcards.html
 
Old 12-18-2009, 10:34 AM   #6
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,559

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


Reply


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 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 05: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 05:12 AM
Delete system log file but the space not released yuanjunliang Linux - Newbie 1 04-23-2009 04:09 PM
delete a file that starts if a "-" (minus) sign Four Linux - Newbie 2 03-14-2008 05:55 PM
Can't delete a file that starts with - vtrac Linux - Software 4 04-17-2006 06:25 AM


All times are GMT -5. The time now is 07:42 PM.

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