Listing files in a Unix Directory ending with .....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Listing files in a Unix Directory ending with .....
# 1  
Old 09-14-2012
Bug Listing files in a Unix Directory ending with .....

Hi Unix Gurus,

I need to list all files in a Unix Directory which either end with a
.pdf or .rtf and they should be case insensitive ie .Pdf , .pDF , .RtF etc are also possible.

How can i accomplish this with with a ls command ? If not then a find command.
# 2  
Old 09-14-2012
Quote:
Originally Posted by pchegoor
Hi Unix Gurus,

I need to list all files in a Unix Directory which either end with a
.pdf or .rtf and they should be case insensitive ie .Pdf , .pDF , .RtF etc are also possible.

How can i accomplish this with with a ls command ? If not then a find command.
Try this..

Code:
ls | grep -i -E ".pdf|.rtf"

This User Gave Thanks to pamu For This Post:
# 3  
Old 09-14-2012
Thanks Pamu.
# 4  
Old 09-14-2012
Alternative:
Code:
ls *.[pP][dD][fF] *.[rR][tT][fF]


--
@pamu: The dots should be escaped and the strings should be anchored..:
Code:
ls | grep -iE '\.pdf$|\.rtf$'

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 09-14-2012
So Scrutinizer, which one is preferable?

Code:
ls *.[pP][dD][fF] *.[rR][tT][fF]

or

Code:
ls | grep -iE '\.pdf$|\.rtf$'

Thanks again.

Last edited by Scrutinizer; 09-14-2012 at 04:43 AM.. Reason: code tags
# 6  
Old 09-14-2012
Just choose what you feel most comfortable using on the command line or what is easier to use or remember. The first is more efficient, since it does not involve a subshell and an extra external program so that might matter in a scripted situation...

Last edited by Scrutinizer; 09-14-2012 at 06:42 AM..
# 7  
Old 09-14-2012
The ls version is preferred if you need to deal with more than a few dozen files.

The * version is preferred when the number of files is known to be small. It may fail with 'too many arguments' if the number of files grows too large to fit in one shell variable.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Listing only the files under a directory from the result of find command

Hi, I have a main folder 'home'. Lets say there is a folder 'bin' under 'home'. I want to check the list of files under subdirectories present under the /bin directory created in the last 24 hours. I am using the following find command under home/bin directory: find . -mtime -1 -print ... (3 Replies)
Discussion started by: DJose
3 Replies

2. Homework & Coursework Questions

Listing the files in a directory

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A script that takes any number of directories as command line arguments and then lists the contents of each of... (3 Replies)
Discussion started by: Phaneendra G
3 Replies

3. Shell Programming and Scripting

Convert directory of text files to Unix/Linux Line Ending

I need help converting a directory of *.txt with Windows line ending to UTF-8 character encoding and Unix/Linux line ending. (9 Replies)
Discussion started by: chipperuga
9 Replies

4. Shell Programming and Scripting

Help with listing given files in a given directory path

hello every one, i'm a novice in the field of Linux, so please help me out with this problem. a text file with the following syntax is given: file1 file2 file3 file4 file5 a script is to be written to list all d file names and tar the files with the filename... (3 Replies)
Discussion started by: Amruthesh C
3 Replies

5. Shell Programming and Scripting

Listing files in a given directory with given extention

for some reason my code does not give the right number of files. can omeone help me please? (2 Replies)
Discussion started by: andrew1400
2 Replies

6. UNIX for Dummies Questions & Answers

Listing files in a non-parent directory

Hi, Edit: The title should really read listing files in a non-parent directory, sorry! Im trying to get one of my Bash scripting assignments done for uni and now I'm stuck. This is probably going to be one of those kick yourself moments but, in my script I have a variable usrDir which... (2 Replies)
Discussion started by: Adzi
2 Replies

7. UNIX for Dummies Questions & Answers

listing files in a directory in bases of size

Hi , I want to list all files in the order of size . Just want to know which files occupies more size and which occupies less size . Is it possible with ls command ? :) Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

8. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

9. UNIX for Dummies Questions & Answers

listing files and directory in Page wise

!hello , Any one can me how can i display files and directory in Pagewise. how to change prompt in UNIX . (1 Reply)
Discussion started by: smdakram
1 Replies

10. UNIX for Dummies Questions & Answers

Printing a Directory Listing in Unix

Does anyone know if there is a way to print the list of files contained in a directory (besides screen print)? Thanks!!! (10 Replies)
Discussion started by: lfulton
10 Replies
Login or Register to Ask a Question