LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-20-2009, 10:36 AM   #1
amicke
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
find a folder containing a specific file


Hi,

I have tried in different ways of doing this but can't figure it out.

How should the bash-command find be typed to show folders containing a specific file?
I only want a folder to be shown once. So it looks trough a folder find a given file, return it, then continue with next folder. This is because one folder may have lot's of these files and I would only like to run the -execdir once on each folder.

Thanks

Mikael
 
Old 04-20-2009, 10:53 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
Hi,

Maybe not the most elegant and there are probably other ways, but this should work:

find . -type f -name "YOUR_FILENAME_HERE" | sed 's%\(.*/\).*%\1%' | sort -u

Find gives back all the files, the sed command strips the file from the dir structure, the sort command sorts them (duh...) and shows only unique output.

Hope this helps.
 
Old 04-20-2009, 10:57 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Something like extract the directory name (path) and remove duplicate entries? You can try something like this:
Code:
find /path/to/search/dir -name file\* -exec dirname {} \; | sort -u
Edit: beaten by druuna

Last edited by colucix; 04-20-2009 at 10:58 AM.
 
Old 04-20-2009, 11:04 AM   #4
amicke
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the answers! But I run an apple TV and do not have the sort command.

However I have installed unrar and figured out a ugly but working solution.

Code:
find . -name *.rar -execdir unrar x {} -o- \;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Way to make autofs mount to specific USB flash drive to specific folder? utahnix Linux - Software 2 11-24-2010 06:27 PM
Sharing specific folder or file in apache server farid_lmu Linux - Server 1 02-10-2009 09:00 AM
find a folder not containing a specific file itzfritz Linux - Server 2 09-10-2008 12:23 PM
howto folder/file sharing with specific groups kmhui Linux - Newbie 5 09-18-2004 08:05 PM
How do I find a specific file? Itzac Linux - Newbie 6 02-05-2003 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration