LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-14-2012, 07:00 AM   #1
amr_salah944
LQ Newbie
 
Registered: Feb 2012
Posts: 20

Rep: Reputation: Disabled
problem with wildcards


Hello
I got a problem using wildcards , I always get unexpected results , for example I wanna list the files that only start with capital letters in /etc

$ls [A-Z]*


I got strange output that contains files not have any capital letters like :



Code:
xml:
catalog          docbook-xml.xml.old  resolver           xml-core.xml
catalog.old      docbook-xsl.xml.old  sgml-data.xml      xml-core.xml.old
docbook-xml.xml  rarian-compat.xml    sgml-data.xml.old

Also if I tried

$ls b*


I got

Code:
....
-rw-r--r-- 1 root root   11359 2011-03-01 13:50 no-oub.ttb
-rw-r--r-- 1 root root     839 2011-03-01 13:50 no.ttb
-rw-r--r-- 1 root root    1447 2011-03-01 13:50 numbers-dot6.tti
-rw-r--r-- 1 root root    1470 2011-03-01 13:50 numbers-dot8.tti
-rw-r--r-- 1 root root    1450 2011-03-01 13:50 numbers-french.tti
-rw-r--r-- 1 root root    1486 2011-03-01 13:50 numbers-nemeth.tti
.....

that's totally wired , can you help me ?
I am on ubuntu 11.11 , SHELL=/bin/bash
 
Old 02-14-2012, 07:35 AM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Hi amr_salah944,

Welcome to LQ!!!

Well that is not the correct way to do it and that is the reason you are not getting expected result.

If you want to list down all the files under /etc that start with a capital letter then you should run the command as follows:

Code:
ls -a /etc | grep ^[A-Z]
You can change the path I mean instead of using ls -a /etc you can also use /var to find out the files starting with capital letters under /var directory.
 
Old 02-14-2012, 07:41 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
cd /etc
ls -d [A-Z]*
works for me...
 
1 members found this post helpful.
Old 02-14-2012, 07:43 AM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

@ Cedrik,

Thank you.

@ amr_salah944,

Yes, that is another way to get the result you are expecting.
 
Old 02-14-2012, 08:00 AM   #5
amr_salah944
LQ Newbie
 
Registered: Feb 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by T3RM1NVT0R View Post
Hi amr_salah944,

Welcome to LQ!!!

Well that is not the correct way to do it and that is the reason you are not getting expected result.

If you want to list down all the files under /etc that start with a capital letter then you should run the command as follows:

Code:
ls -a /etc | grep ^[A-Z]
You can change the path I mean instead of using ls -a /etc you can also use /var to find out the files starting with capital letters under /var directory.

Thnx 4 ur help , but I really wanna use wildcard nor regexp , or you can say I wanna know what makes it give that strange output
 
Old 02-14-2012, 08:01 AM   #6
amr_salah944
LQ Newbie
 
Registered: Feb 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Cedrik View Post
Code:
cd /etc
ls -d [A-Z]*
works for me...

I tried this also but getting files such




Code:
hdparm.conf                    pcmcia               xul-ext
host.conf                      perl                 xulrunner-2.0
hostname                       pkcs11               zekr
hosts                          pm                   zsh_command_not_found
hosts.allow                    pnm2ppa.conf
 
Old 02-14-2012, 08:11 AM   #7
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

That is because you are not running the command mentioned as root user. Try it with the root user and I am pretty sure it will work. I got the same output as you are getting when I used a regular user account.
 
Old 02-14-2012, 08:15 AM   #8
amr_salah944
LQ Newbie
 
Registered: Feb 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by T3RM1NVT0R View Post
That is because you are not running the command mentioned as root user. Try it with the root user and I am pretty sure it will work. I got the same output as you are getting when I used a regular user account.

The same result
Really I don't wanna know another method , I just wanna know why this happens , so please help me
 
Old 02-14-2012, 08:42 AM   #9
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Appears to me as some limitation with regular user account to use wildcards. When I use the regular user account I get the same output. If I use root user account I got the correct output. If I add the regular use to sudo still I get the same output.

So it appears to be some limitation with regular user account to use wildcards.
 
Old 02-14-2012, 09:00 AM   #10
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Maybe something with your locale ??

Could you try
Code:
cd /etc
LC_ALL=C ls -d [A-Z]*
 
1 members found this post helpful.
Old 02-14-2012, 09:12 AM   #11
amr_salah944
LQ Newbie
 
Registered: Feb 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
@ T3RM1NVT0R
@Cedrik

I tried all of that but still the same problem , and by the way I tried it yesterday on a Centos machine and also I had a problem like that , that's why I decided that I must figure out what's happening , I don't know if It's a bug or what !!
 
Old 02-15-2012, 11:10 AM   #12
amr_salah944
LQ Newbie
 
Registered: Feb 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Hello again
I really don't want any suggestion for that function , I am just very curious to know what causes that strange output that is totally different from all what we learnt and what books say, so please help me know where the problem is
 
Old 02-15-2012, 08:32 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
ls [A-Z}?.*
works for me with ls --version=8.4, bash --version=4.1.2(1) & see also http://linux.die.net/Bash-Beginners-...ect_04_03.html
 
Old 02-16-2012, 03:38 AM   #14
amr_salah944
LQ Newbie
 
Registered: Feb 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
Code:
ls [A-Z}?.*
works for me with ls --version=8.4, bash --version=4.1.2(1) & see also http://linux.die.net/Bash-Beginners-...ect_04_03.html
Hello Chris
The dot is not a wildcard character , I still getting unexpected results, really I need to know what causes that , I am not asking about any complex issue , It's just the basics that we learnt years ago from books, I don't know why it's not working correctly !! Please help me figuring out that.
 
  


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
Wildcards randalleg Linux From Scratch 3 06-19-2011 08:09 AM
need help with wildcards yanivmomo Programming 4 05-24-2010 07:37 AM
using wildcards nadroj Linux - General 5 01-28-2007 08:39 PM
copy problem using wildcards plisken Linux - General 11 11-16-2005 08:34 AM
Wildcards dazdaz Linux - Newbie 3 01-23-2005 05:33 AM

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

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

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