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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-19-2005, 12:56 AM
|
#1
|
|
LQ Newbie
Registered: Apr 2005
Posts: 26
Rep:
|
list files NOT matching a pattern
I have a set of files in a directory:
chap1, chap2, chap3, test.c, hello.pl
I want to list all those files which do not start with chap. How do I use only the ls command to do this?
Also, if possible can someone send me a link as to where I can get examples which use ls and regular expressions?
|
|
|
|
05-19-2005, 02:52 AM
|
#2
|
|
Senior Member
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,430
Rep:
|
Here's a couple:
1. ls -al | grep -v chap
2. ls -al [^chap]*
-twantrd
|
|
|
|
05-19-2005, 03:02 AM
|
#3
|
|
LQ Newbie
Registered: Apr 2005
Posts: 26
Original Poster
Rep:
|
Quote:
Originally posted by twantrd
2. ls -al [^chap]*
|
This command gives the list of all those files which do not start with either c or h or a or p. As a result, I dont get the files in the directory starting with these letters.
|
|
|
|
05-20-2005, 12:54 AM
|
#4
|
|
Senior Member
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,430
Rep:
|
Oops, you are correct. I truly apologize for that.
-twantrd
|
|
|
|
05-20-2005, 12:55 AM
|
#5
|
|
LQ Newbie
Registered: Apr 2005
Posts: 26
Original Poster
Rep:
|
But what about the solution?
|
|
|
|
05-20-2005, 02:14 AM
|
#6
|
|
Member
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410
Rep:
|
Didn't the first work? Maybe "ls | grep -v ^chap"...
|
|
|
|
05-20-2005, 02:17 AM
|
#7
|
|
LQ Newbie
Registered: Apr 2005
Posts: 26
Original Poster
Rep:
|
In fact, it did. BUT my problem is that I require this thing using just the ls command, and nothing else 
|
|
|
|
05-20-2005, 03:55 AM
|
#8
|
|
Member
Registered: Apr 2005
Distribution: LFS 5.0 and 6.1
Posts: 705
Rep:
|
Quote:
Originally posted by smart_sagittari
In fact, it did. BUT my problem is that I require this thing using just the ls command, and nothing else
|
ain't gonna happen, you need to specify some options with "ls" in order for
it to work properly...........read the man page
http://man.linuxquestions.org/index....ction=0&type=2
|
|
|
|
05-20-2005, 04:39 AM
|
#9
|
|
Senior Member
Registered: Mar 2004
Location: Munich
Distribution: SuSE 12
Posts: 3,511
Rep:
|
What about 'ls --ignore=chap*'?
See 'man ls'
|
|
|
|
05-20-2005, 05:32 AM
|
#10
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
Don't forget this is linux! If the command you want does not exist, create it 
So create your own command, that will do ls, and then filter through grep. Else you can define a "ls" function in your .profile, that pipe /bin/ls into grep... Many things are possible.
Yves.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:33 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|