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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-18-2004, 12:34 PM
|
#1
|
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,577
|
excluding directories from commands
How can I exclude certain directories from bash commands like find, locate, cp, and such? For example, if I want to find and/or copy all .ogg files on my system that aren't already in my main music folder, how do I set up the commands to ignore that folder?
|
|
|
|
11-18-2004, 02:05 PM
|
#2
|
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,572
|
Where find is concerned, you can limit the part of the directory tree to search by specifying /, /etc, /home, /usr, etc in the find command. Locate uses regular expressions to search the locate database. I think you're SOL there. Cp may work if it's in a script, inside nested loops to compare directories, etc.
As far as your .ogg files are concerned, nested loops with an if-then-else-fi or case argument would work. The outer loop reads file names from one directory of interest; the inner loop reads file names from the other directory of interest; the if-then-else or case argument compares contents of the two directories, using bash variables such as -e (exists); !-e (doesn't exist); -a (and) and so on to make the filename comparison. The if-then-else or case arguments would then step through the options. If it exists here but doesn't exist there, copy from here to there. If it exists both places, skip to the next one, and so on.
A thorough (an I mean thourgh) reading of the bash man pages, or the Advanced bash-scripting guide, is in order. The loops I mentioned will require the use of square brackets to enclose arguments. In some cases, there MUST be a blank space between the brackets and the arguments enclosed by the brackets. If the blank space is omitted, the command won't work. Little things like that can make debugging scripts a nightmare.
|
|
|
|
11-19-2004, 12:39 PM
|
#3
|
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,577
Original Poster
|
Gah, that's too complicated. Besides, your suggestion for find wouldn't help me. I would want to search my whole profile starting at ~/, but exclude only the ~/music subtree, for example.
My .ogg example was only one example, though. For another, I have a folder /backups where I keep copies of important files that I don't want to show up on most searches. If I start a search from /, then the /backup folder is automatically included in the search, making it take more time than necessary and sometimes giving me duplicate matches.
All I really was hoping for was a fairly simple way to exclude a file or folder sub-tree from *any* major bash function. I was thinking that a regex might be the key, since most commands support them in some way. I tried playing around with expressions that would exclude certain strings while matching everything else, but I couldn't get anything to work. I just don't have enough knowledge of either bash or regex to do myself any good. I've only done a couple of easy scripts before too. I'm not ready yet for something that complicated.
I would think that it's possible. I can't imagine I'm the only person who's ever needed this kind of functionality.
|
|
|
|
04-06-2009, 12:23 PM
|
#4
|
|
LQ Newbie
Registered: Apr 2009
Posts: 1
Rep:
|
Take a look at prune prunepaths
updatedb --prunepaths='path1 path2...'
find -prune
|
|
|
|
04-06-2009, 03:18 PM
|
#5
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
Quote:
Originally Posted by LogicMagic0
updatedb --prunepaths='path1 path2...'
find -prune
|
Ummmm ....
That's very nice, but find doesn't make any use of locates
database for its searches, so it's a pretty useless combination.
To the OP ...
Code:
find /path/to/where/to/search/from \( -path ./oggs -prune -o -path ./other -prune \)
Cheers,
Tink
|
|
|
|
04-06-2009, 03:21 PM
|
#6
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
Quote:
Originally Posted by David the H.
All I really was hoping for was a fairly simple way to exclude a file or folder sub-tree from *any* major bash function. I was thinking that a regex might be the key, since most commands support them in some way. I tried playing around with expressions that would exclude certain strings while matching everything else, but I couldn't get anything to work. I just don't have enough knowledge of either bash or regex to do myself any good. I've only done a couple of easy scripts before too. I'm not ready yet for something that complicated.
I would think that it's possible. I can't imagine I'm the only person who's ever needed this kind of functionality.
|
That's not generically possible, you can just filter out any output
you don't desire ... but that will vary with different commands, and
their different invocations. You still have the processing overhead
(searching/accessing the disks).
Cheers,
Tink
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:28 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|