LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 05-19-2005, 01:56 AM   #1
smart_sagittari
LQ Newbie
 
Registered: Apr 2005
Posts: 26

Rep: Reputation: 16
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?
 
Old 05-19-2005, 03:52 AM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
Here's a couple:

1. ls -al | grep -v chap
2. ls -al [^chap]*

-twantrd
 
Old 05-19-2005, 04:02 AM   #3
smart_sagittari
LQ Newbie
 
Registered: Apr 2005
Posts: 26

Original Poster
Rep: Reputation: 16
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.
 
Old 05-20-2005, 01:54 AM   #4
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
Oops, you are correct. I truly apologize for that.

-twantrd
 
Old 05-20-2005, 01:55 AM   #5
smart_sagittari
LQ Newbie
 
Registered: Apr 2005
Posts: 26

Original Poster
Rep: Reputation: 16
But what about the solution?
 
Old 05-20-2005, 03:14 AM   #6
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 30
Didn't the first work? Maybe "ls | grep -v ^chap"...
 
Old 05-20-2005, 03:17 AM   #7
smart_sagittari
LQ Newbie
 
Registered: Apr 2005
Posts: 26

Original Poster
Rep: Reputation: 16
In fact, it did. BUT my problem is that I require this thing using just the ls command, and nothing else
 
Old 05-20-2005, 04:55 AM   #8
freakyg
Member
 
Registered: Apr 2005
Distribution: LFS 5.0 and 6.1
Posts: 705

Rep: Reputation: 30
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
 
Old 05-20-2005, 05:39 AM   #9
abisko00
Senior Member
 
Registered: Mar 2004
Location: Munich
Distribution: SuSE, Ubuntu
Posts: 3,511

Rep: Reputation: 58
What about 'ls --ignore=chap*'?

See 'man ls'
 
Old 05-20-2005, 06:32 AM   #10
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
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.
 
  


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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 8 12-18-2013 06:36 PM
Perl Pattern Matching Question pete1234 Programming 2 08-27-2005 11:26 AM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 10:22 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 10:53 AM
Doubt in Pattern matching and vi editor.. suriyamohan Linux - General 2 08-19-2003 06:03 AM


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