LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-06-2016, 05:57 AM   #1
new2lnx
LQ Newbie
 
Registered: May 2016
Location: Chicago, IL
Distribution: CentOS 6.6
Posts: 3

Rep: Reputation: Disabled
Unhappy What am I doing wrong with the square bracket wildcard?


I've just started on the basics, so please bare with me! I'm now on wildcards and could understand the "?". However, when I practice the "[]", they just aren't giving me the results. Click image for larger version

Name:	Screenshot (1).png
Views:	59
Size:	145.1 KB
ID:	22670

Click image for larger version

Name:	Screenshot (2).png
Views:	43
Size:	153.8 KB
ID:	22671
From the two screenshots can anyone tell me if and what I'm doing wrong? If I do "rm" instead of "ls", I get the same results - the wrong files get deleted
 
Old 08-06-2016, 06:11 AM   #2
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware, OpenBSD
Posts: 4,057
Blog Entries: 11

Rep: Reputation: 2238Reputation: 2238Reputation: 2238Reputation: 2238Reputation: 2238Reputation: 2238Reputation: 2238Reputation: 2238Reputation: 2238Reputation: 2238Reputation: 2238
Square brackets always map to a single character. Multiple characters within the brackets (other than special ones like "-" and "^") are treated as alternatives. So your first formula is actually specifying a single character which could be 1,0 or 2. File1 and file2 are correct answers. Your second one specifies a character which is not a digit, so filea and fileb are correct.

To get what you want, you would need file10[0-2].
 
Old 08-06-2016, 10:13 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Or use braces
Code:
ls file{101,102}
 
Old 08-08-2016, 02:24 PM   #4
new2lnx
LQ Newbie
 
Registered: May 2016
Location: Chicago, IL
Distribution: CentOS 6.6
Posts: 3

Original Poster
Rep: Reputation: Disabled
Smile Thanks!

hazel, you hit the nail on the head with your first sentence, thanks! I won't forget it anytime soon! Thanks to keefaz too! Also,I was trying to get a listing of all files ending in numerals and a slight variation to keefaz’s suggestion “ls file{1..103}” got me the results, but with a whole bunch of “cannot access” messages for the “missing” files!
 
  


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
[SOLVED] Circle square; How draw/compute w square pixels? Trigonometry, language rico001 Programming 6 04-27-2016 05:48 PM
[SOLVED] Excluding square bracket pattern from file slik Linux - Newbie 4 06-20-2014 10:29 AM
Square bracket hoax w1k0 Programming 14 05-19-2013 11:11 AM
"Missing right curly or square bracket at -e" error in perl nivedhitha Programming 7 08-31-2011 04:17 AM

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

All times are GMT -5. The time now is 08:59 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