Checking file existance by extension


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Checking file existance by extension
# 1  
Old 09-24-2008
Checking file existance by extension

I'm sure this can't be too tough, but.

I want to check the existance of file(s) by extension. There may be 0,1,N files. If any files exist, then remove them.

Thanks for any insight.
# 2  
Old 09-24-2008
well this is pretty crude but gets the job done:
Code:
ls | grep *.txt > file1 && while read FILES ; do rm $FILES ; done < file1 && rm file1

I am sure there is a way to do it without using another file but I am too new to know how...

edit: this should be obvious, but if it isn't replace txt with extension of your choice
# 3  
Old 09-24-2008
Thank you, I'll try this. In the meantime, I found this works:

for file in $BaseDir/* ; do
case $file in
*.sql)
rm $file;;
*.in)
rm $file;;
blah.*)
rm $file;;
check.output.*)
rm $file;;
esac
done

Since my script is in a cron job, it does not leave mail if it doesn't find the files.

Thanks again,
Paul
# 4  
Old 09-24-2008
Code:
find /path -name \( -name '*.in' -o -name '*.sql' \) -exec rm -f {} \;

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

2. Shell Programming and Scripting

Error while checking file existance

Kindly help on below script: << i='find ...' if then echo 'File Exists' else echo 'File Does Not Exist' >> If i has some file name then it runs properly but if i has nothing ( blank value) then it throws an error. I dont exactly remember right now but error seems like:... (2 Replies)
Discussion started by: ravigupta2u
2 Replies

3. UNIX for Dummies Questions & Answers

Test existance of a file

Hi, I need to find out if a particular file exists and i am using if with -e option. Scenarion is like There is a possibility of two files having nomaincluture like below First file = abc20101028.somthing Second File = abc20101028.somthing.done I need to check abc20101028.somthing... (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

4. Shell Programming and Scripting

Checking the existance of multiple files

I am trying to execute the following command to check the existance of a file (which has a date timestamp on it). If there are more than one file, then also it should give me 'success' result. if then <do some work> else <no files> fi Since there are more than one... (18 Replies)
Discussion started by: vivek_damodaran
18 Replies

5. Shell Programming and Scripting

Checking if the files in a directory have a txt extension

foreach file ($dir1/*) if ($file ~ *.txt) then echo "Skipping $file (is a txt file)" endif end that should work right guys? :confused: (15 Replies)
Discussion started by: pantelis
15 Replies

6. Shell Programming and Scripting

The checking of folder existance is not working...

Hi all, I have the following code: if ; then echo 'folder not exist'; else echo 'folder exist'; fi The "testing" folder is not exist in /home/batch , but thhe result is 'folder exist'. It seems that the code cannot detect that the folder "testing" not exist. ANybody know the... (1 Reply)
Discussion started by: suigion
1 Replies

7. Shell Programming and Scripting

checking existance of files and directories

I have a list of files and their directories, starting from a particular location. e.g. temp/new/a.c temp/new/b.c temp/old/a.c temp/old/older/b.c etc. Now I want to check the existence of all these files in the respective directories . I am trying something like cat "fileList" |... (4 Replies)
Discussion started by: herojeett
4 Replies

8. Shell Programming and Scripting

check the file existance

Hello, I have two files .. 1. inventory_i.txt 2. inventory_b.txt I want to check if these two files exists. If exists, then do the process, otherwise, quite... if ; then echo "exists" else echo " does not exists" fi The above logic is not working... It is always, displaying Does... (2 Replies)
Discussion started by: govindts
2 Replies

9. UNIX for Dummies Questions & Answers

Checking files extension

Hi, I need one line command to display all files that ends with .scr. Example: In a directory I have 10 files, out of that 4 files have filetype extension .dat and 4 files with .scr and 2 files with .txt.... In this i want to display only files that ends with .scr. I tried some commands,... (2 Replies)
Discussion started by: gwgreen1
2 Replies

10. Shell Programming and Scripting

File existance

Guys Iam trying to do a script to find what files are missing in particular directory.I came up with this for i in file6 file7 file8 file9 file10 file11 file12; do if ; then echo " $file not in /mnt/Server/base/i386/ " else echo " $file ... " fi done Iam trying to print... (2 Replies)
Discussion started by: coolkid
2 Replies
Login or Register to Ask a Question