LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 11-18-2004, 12:34 PM   #1
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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?
 
Old 11-18-2004, 02:05 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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.
 
Old 11-19-2004, 12:39 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Original Poster
Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
Old 04-06-2009, 12:23 PM   #4
LogicMagic0
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Take a look at prune prunepaths

updatedb --prunepaths='path1 path2...'
find -prune
 
Old 04-06-2009, 03:18 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by LogicMagic0 View Post
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
 
Old 04-06-2009, 03:21 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by David the H. View Post
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
 
  


Reply



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
Find excluding multiple directories with a wildcard pteigeler Linux - Software 1 09-02-2005 10:57 AM
tar, excluding directories recursively towlie Linux - Newbie 3 06-17-2004 12:32 PM
Excluding directories from zip files jonathanztaub Linux - General 1 05-17-2004 02:17 AM
tar and excluding files murshed Linux - Newbie 7 03-15-2003 02:32 PM
DHCP excluding IP addresses AndyJ Linux - Networking 8 03-03-2003 03:09 PM

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

All times are GMT -5. The time now is 01:43 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