LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-01-2011, 12:27 PM   #1
scazz
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Rep: Reputation: Disabled
bash wildcard expansion length issue


Hi guys,

So I've got a directory with quite a few thousand files (+27000) in it. They aren't named anything stupid; only numbers and _s.

I'm using the bash shell.

When I try and manipulate the files, starting with a *, I get an error:

ls *.gif
ls: invalid option -- _
Try `ls --help' for more information.

I can use the wildcard in the middle of my query, just not at the start.

Same thing happens for cp, mv etc

I can get round it by:
ls -- *.gif

However, my question is: why on earth does this happen? I first thought maybe there was a character limit for the expansion... but I didn't see how the -- would help me.

Obviously google isn't particularly helpful when searching for '--'

Anyone have any ideas?
Cheers
Scazz
 
Old 11-01-2011, 12:40 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Maybe there are files starting with an hyphen, so that the commands interpret these file names as options. The -- (double hyphen) in many linux commands serves to terminate the list of options, so that everything that follows is treated as a real argument (positional parameter). It is the right way to go, if you want to manage these files from the command line.
 
Old 11-01-2011, 01:32 PM   #3
scazz
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
You're right! I checked for that by

ls | less
and
ls | tail -10

thinking that '-' would either be sorted before numbers or after numbers - it turns out ls ignores the leading '-' and sorts by the next character.

I thought I ruled that out!
Thanks for the explanation
Scazz
 
  


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
Wildcard/regex in bash command logicalfuzz Linux - General 2 10-27-2011 03:40 PM
SED: wildcard expansion in variables Gracie Belle Linux - Newbie 3 02-20-2008 08:43 AM
Variable expansion in BASH champak Programming 5 11-26-2007 03:44 AM
Bash variables expansion olaola Linux - Newbie 4 10-16-2006 12:45 PM
bash in ubuntu: save the wildcard expansion beebop Programming 0 03-12-2006 02:19 AM


All times are GMT -5. The time now is 10:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration