Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

ls exclude pattern

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-07-2009
JCR JCR is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 7 August 2010, 10:23 AM EDT
Posts: 52
Thanks: 5
Thanked 0 Times in 0 Posts
ls exclude pattern

Hello,

With ls *.html I am getting all the files ending with html; what would be the best why to get all the files not ending with html?

Thanks
Sponsored Links
    #2  
Old Unix and Linux 02-07-2009
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 23 June 2017, 6:44 PM EDT
Location: Saskatchewan
Posts: 22,254
Thanks: 1,105
Thanked 4,197 Times in 3,883 Posts
try 'echo *.html', it will do the same thing, since you're doing shell globbing, which isn't a feature of ls at all. shell globbing will fail if there are too many files in the directory, and shell globbing can't filter in reverse like that. grep works for an arbitrary amount of data and can filter in reverse.


Code:
# See all files ending in .html
ls | grep "\.html$"
# see all files not ending in .html
ls | grep -v "\.html$"

Sponsored Links
    #3  
Old Unix and Linux 02-07-2009
cfajohnson's Unix or Linux Image
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 11 July 2016, 2:55 PM EDT
Location: Toronto, Canada
Posts: 2,898
Thanks: 0
Thanked 134 Times in 118 Posts
Quote:
Originally Posted by JCR View Post
With ls *.html I am getting all the files ending with html; what would be the best why to get all the files not ending with html?

In ksh, or bash with extended globbing turned on:

Code:
printf "%s\n" *!(.html)

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comment/delete a particular pattern starting from second line of the matching pattern imas Shell Programming and Scripting 4 10-13-2008 02:37 AM
modify a particular pattern starting from second line of the search pattern imas UNIX for Dummies Questions & Answers 1 10-12-2008 01:19 PM
modify a particular pattern starting from second line of the search pattern imas UNIX for Dummies Questions & Answers 2 10-12-2008 11:30 AM
exclude columns with a matching line pattern greptastic UNIX for Dummies Questions & Answers 5 06-30-2008 03:32 AM
grep - to exclude lines beginning with pattern frustrated1 Shell Programming and Scripting 2 08-29-2005 07:18 AM



All times are GMT -4. The time now is 06:35 AM.