Simply Bash Script to Confirm that there are 2 Files in Same Folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simply Bash Script to Confirm that there are 2 Files in Same Folder
# 1  
Old 12-20-2018
Simply Bash Script to Confirm that there are 2 Files in Same Folder

Im looking for 2 Files -> *.WAV and *.wav with

Code:
find . -name 'unavail.wav' -o -name 'unavail.WAV'

I need to list the Folders that contains these 2 Files?

Thx in advance
# 2  
Old 12-20-2018
Maybe like this?

Code:
find . -iname 'unavail.wav' | tr A-Z a-z | sort | uniq -cd

That won't work as expected if there are folders that only differ in case too.

Last edited by stomp; 12-20-2018 at 06:39 AM..
# 3  
Old 12-20-2018
yeah, seems to working

Code:
XXX:[XXX]/voip/old # find . -name 'unavail.wav' -o -name 'unavail.WAV' | tr A-Z a-z | sort | uniq -cd
      2 ./2309/unavail.wav
      2 ./2315/unavail.wav
      2 ./33010/unavail.wav
      2 ./8336/unavail.wav
XXX:[XXX]/voicemail/voip/old #


thank you very much. otherwise i would have to check more then 600 folders manually.




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-20-2018 at 06:58 AM.. Reason: Added CODE tags.
# 4  
Old 12-20-2018
Hi,

You could also use;

Code:
find . -name 'unavail.wav' -o -name 'unavail.WAV' -printf %h

This should print only directory names where matching files exist.

Regards

Gull04
This User Gave Thanks to gull04 For This Post:
# 5  
Old 12-20-2018
Should there be directories that differ in case only (the caveat that stomp mentioned, which is negligible with your numeric directories obviously), you could use
Code:
find . -iname 'unavail.wav' | rev | sort -t"/" -k2 | cut -d"/" -f2- | rev | uniq -cd

on the other hand, with a looong pipeline like that, you might be better off using e.g. awk.
# 6  
Old 12-20-2018
this doesnt work for me. I find many folders but not those where both files (unavail.WAV & unawail.wav) were contained.

Code:
XXX:[XXX/voip/old # find . -name 'unavail.wav' -o -name 'unavail.WAV' -printf %h 
./7325./6657./2309./5863./3339./4045./96964./5867./3336./98764./33010./5891./2312./2057./2352./5861./7322./7332./8336./5890./2311./2128./2346./5880./2333./2300./5553./5881./5882./2313./2304./2360./2339./2335./5883./2369./2308./98765./2129./2325./96962./5252./7333./5371./4950./2329./6606./3333./2344./2306./5859./5898./5830./5897./5860./2321./2347./2316./5862./5864./2310./2307./34699./7331./2345./5896./5870./2399./2371./7320./3338./2356./2368./5866./2323./2380./2318./5868./2330./5872./5601./5833./2365./5894./5865./5885./2361./5843./2338./9015./2328./5869./2301./5886./2341./2354./2353./4946./2367./5893./2317./1234./2320./2303./2357./2319./2315XXX:[XXX]/voip/old #

when i look into the found foldes I see just one file
Code:
XXX:[XXX]/voip/old # ll 7325
insgesamt 12
drwxr-xr-x 2 root root 4096  5. Aug 2011  INBOX
-rw-r--r-- 1 root root 6040  5. Aug 2011  unavail.WAV
XXX:[XXX]/voip/old #

but I need those Folders where both Files (unavail.wav & unawail.WAV) are in it.
Code:
XXX:[XXX]/voip/old # find . -name 'unavail.wav' -o -name 'unavail.WAV' | tr A-Z a-z | sort | uniq -cd
      2 ./2309/unavail.wav
      2 ./2315/unavail.wav
      2 ./33010/unavail.wav
      2 ./8336/unavail.wav
XXX:[XXX]/voip/old #

So when I look into these folders:
Code:
XXX:[XXX]/voip/old # ll 2309
insgesamt 164
-rwx------ 1 root root    386  5. Aug 2011  busy.WAV
drwx------ 2 root root   4096  5. Aug 2011  Cust5
-rwx------ 1 root root   1750  5. Aug 2011  greet.WAV
drwxr-xr-x 2 root root   4096  5. Aug 2011  INBOX
drwx------ 2 root root   4096  5. Aug 2011  Old
-rw-r--r-- 1 root root 134198  5. Aug 2011  unavail.wav
-rwx------ 1 root root   2010  5. Aug 2011  unavail.WAV
drwx------ 2 root root   4096  5. Aug 2011  Work
XXX:[XXX]/voip/old #


thx anyway
# 7  
Old 12-20-2018
Hi,

Sorry, I assumed that you would have a bit more knowledge of find so for completeness;

Code:
find ./ -name 'unavail.wav' -o -name 'unavail.WAV' -printf '%#m %u %h\n'

Give that a try - you should read the find man page and adjust the required output on the printf option.

Regards

Gull04
This User Gave Thanks to gull04 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Bash script read specific value from files of an entire folder

Hello, I heva a problem creating a script that read specifc value from all the files of an entire folder I have a number of email files into a directory and i need to extrect from each file 2 specific values. After that i have to put them into a new file that looks like that: To: value1 ... (1 Reply)
Discussion started by: ahmenty
1 Replies

3. Shell Programming and Scripting

Simply bash script

I have a bash script that has 13 variables and runs commands on them. I've copied the commands 13 times but I'd like to simplify it to simply add 1 to the previous and run 13 times. The variables are dir01=/path/to/dir01 dir01=/path/to/dir02 ... up to 13. (more may be added later) ...... (6 Replies)
Discussion started by: scribling
6 Replies

4. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

5. Shell Programming and Scripting

Bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

6. Shell Programming and Scripting

URGENT!!! bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

7. UNIX for Dummies Questions & Answers

Bash script to rename all files within a folder...

Hi. I don't have any experience with making scripts in bash. I need a simple script to rename all files in a folder to the format file1.avi, file2.avi, file3.avi, and so on..... Please note that the original files have different filenames and different extensions. But they all need to be... (2 Replies)
Discussion started by: dranzer
2 Replies

8. Shell Programming and Scripting

Bash folder manipulation - selecting/copying specified files

Bash/scripting newbie here - I feel this might be a trivial problem, but I'm not sure how to tackle it. I've got a folder of a year's worth of files, with some random number of files generated every day of the year (but at least one per day). I'm writing a script to automatically grab the file with... (6 Replies)
Discussion started by: WildGooseChased
6 Replies

9. Shell Programming and Scripting

bash - batch processing folder of files by name

Hello Everyone!!! I need some help with a shellscript to batch process a folder of files with the imagemagick convert -append/+append command. The folder contains some hundred or thousand of small images in .png format which I would like to join together in order of their filenames. The... (3 Replies)
Discussion started by: imtombi
3 Replies

10. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies
Login or Register to Ask a Question