Searching for file names in a directory while ignoring certain file names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching for file names in a directory while ignoring certain file names
# 1  
Old 12-11-2009
Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question

Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain extensions. For example :

Files in directory
----------------
testfile1.txt
testfile2.txt
testfile3.txt
testfile4.txt
testfile1.exe
testfile2.exe
testfile3.exe
testfile4.exe

I have a find command like :

find . -name '*' -print > filelist.lst

This would obviously give me all of the file names listed above in the file called filelist.lst.

However, what command syntax would I use if I wanted to ignore *.exe files. So, in the end this find command should generate a file called filelist.lst which should contain only the names of the files that end in .txt.

I tried the -not command but that is not valid in my version of Sun Solaris. (i.e. find . -name "*' -not \( -name "*.exe" \) -print > filelist.lst )

---------- Post updated at 03:09 PM ---------- Previous update was at 02:57 PM ----------

Disregard. I finally found the answer.

find . -name '*' ! -name '*.exe' -print > filelist.lst
# 2  
Old 12-11-2009
anything keeping you from doing your find and doing a |grep -v on whatever you want to exclude?
Or alternatively |grep ".txt"
# 3  
Old 12-13-2009
Quote:
Originally Posted by 2reperry
find . -name '*' ! -name '*.exe' -print > filelist.lst
This should be enough.

Code:
find . ! -name '*.exe' -print > filelist.lst

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Renaming the file names in a directory

Hi, I have about 60 files in a directory and need to rename those files. For example the file names are i_can_phone_yymmdd.txt (where yymmdd is the date. i.e 170420 etc) i_usa_phone_1_yymmdd.txt i_eng_phone_4_yymmdd.txt The new file names should be phone.txt phone_1.txt phone_4.txt I am... (4 Replies)
Discussion started by: naveed
4 Replies

2. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

3. Shell Programming and Scripting

Compare file names on directory

Dears, Would you please help on following bash script: I want to get the most recent file named alfaYYYYMMDD.gz in one directory: for example: in directory /tmp/ ls -ltr alfa20130715.gz holding.gz alfa20130705.gz sart.txt merge.txt.gz alfa20130802.gz my result shoud be... (1 Reply)
Discussion started by: maxsub
1 Replies

4. Shell Programming and Scripting

Searching for file names with variables

Hello everyone We have a problem about searching and copying files with variables. we have variables like $year $jday $date and we want to search the files whose name contain these variables. we tried *$year*$jday*$date or with ? instead of * thank you everyone!!! (4 Replies)
Discussion started by: miriammiriam
4 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. UNIX for Dummies Questions & Answers

Searching File Names

I am interested in writing a really simple alias to search for duplicates in file names in a given directory. As an example, the file names follow a convention like: TGIFRIDAY_55566_RESTAURANT TGIFRIDAY_98744_RESTAURANT TGIFRIDAY_67778_RESTAURANT TGIFRIDAY_55566_RESTAURANT These are all... (8 Replies)
Discussion started by: Tennesseej
8 Replies

7. Shell Programming and Scripting

How to read file names in the directory?

I am having n files in a directory i want to read all the file names from the script file .It is better if any one provide a sample script. Elaborating the scenario: i am having n number of sql files in a directory i am running all the sql files from a single script. sqlplus... (4 Replies)
Discussion started by: dineshmurs
4 Replies

8. UNIX for Dummies Questions & Answers

How can I sort the file names in the directory

Hi , I have a list of files in the directory I want to sort based on the file name. But in the middle of filename contains the number based on that I need to sort.Could you suggest me on the same? Example filenames: /user1$ls RS.DEV.ISV.F1.RS.REFDATA.DATA... (1 Reply)
Discussion started by: praveen.thumati
1 Replies

9. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies

10. UNIX for Dummies Questions & Answers

Change All File Names in a Directory

Hi, If I have a directory full of say 100 random files, and I would like to organize them, for example: FILE001, FILE002, FILE003, FILE004, etc. How would I do this from Terminal, instead of manually changing each file? I'm using Mac OS X, if that makes a difference. Thank you in advance... (8 Replies)
Discussion started by: andou
8 Replies
Login or Register to Ask a Question