Unix find command...

My problem exists with the behavior on the unix find command, or my lack of understanding of it.
For example, I work for a graphics company and we have a constant folder structure like this:
*12345 Apple - Poster*
~....~01_Layouts
~....~02_Images
~....~03_Fonts
~....~04ClientOriginals
~........~01.28.08_14:46
~........~03.07.08_15.03
~........~03.10.08_17.22
When we receive files from a customer, the CSR creates a folder inside 04ClientOriginals following a format like 03.06.08_10.15, and copies the files/folders from customer supplied media into them.
I have set up a launchd script that finds all of the date/time stamped folders inside of 04ClientOriginals that have not been modified within the past month and stuff them with the Stuffit command line utility. I do that with this command:
find . -type d –mtime +30 -ipath #/04ClientOriginals/# -exec /usr/local/bin/stuff -f sit5 -m 2 -o -D {} \;
This command works fine except in those cases where there are folders over 30 days old inside of a parent directory that is not 30 days old yet. I only want the find to descend to one level below 04ClientOriginals, and no further.
I thought by adding an extra "/" at the end of the path #/04ClientOriginals/#/ instead of #/04ClientOriginals/# would keep it from descending further down, but when I try this the search returns no results. Also, I can’t use -maxdepth in my find arguments because the depth of 04ClientOriginals is not always constant.
Any help would be greatly appreciated.
Thanks.
Edit: Due to the lack of decent markup tools for formatting code on the Apple Discussion Board, the wildcards in my file paths have been substituted with a "#". Kind of ridiculous for a unix discussion board to not have code highlighting capability.
Message was edited by: Guriboy

etresoft wrote:
I don't know if these will work or not. Regular expressions are powerful, but tricky. Plus, there are a few different, but similar, varieties. Also, I don't know if the find within a find syntax will work. This might be something that is better suited to Perl. You would then have much more control over what you are doing.
Running this find command finds exactly what I'm looking for:
find . -type d -name "04ClientOriginals" -exec find {} -mtime +30 -type d -maxdepth 1 ;
I hope I'm wrong, but can't you call -exec only once? As a test I ran this:
find . -type d -name "04ClientOriginals" -exec find {} -mtime +30 -type d -maxdepth 1 -exec ls -l {} ;
If I invoke -exec a second time, I get this error:
find: -exec: no terminating ";" or "+"
find: -exec: no terminating ";" or "+"
find: -exec: no terminating ";" or "+"
I've searched high and low and I cannot find an example of the find command calling -exec more than once.
My regex skills are pretty weak, so I'll only tread those waters if I have to.

Similar Messages

  • Help please! [using Runtime.exec() to run find command in UNIX]

    Hi guys! im trying to use exec() to run the UNIX find command
    that my application uses. As you can see from my sample code, the find command finds all files ending with html in my home directory. Unfortunately when I run the program it doesn't give me an output, but when I run it on the shell in the same directory as this code is saved, it works perfectly fine.
    Could someone please help me on this one. Many thanks! =)
    import java.io.*;
    import java.lang.String;
    public class RunCommand {
            public static void main(String[] args) {
                    try {
                            String[] command = {"find", "~/", "-name",
                                            "*.html", "-print"};
                            String find_str;
                            Process find_proc = Runtime.getRuntime().exec(
                                            command);
                            DataInputStream find_in = new DataInputStream(
                                            find_proc.getInputStream());
                            try {
                                    while ((find_str = find_in.readLine())
                                                                    != null) {
                                            System.out.println(find_str);
                            } catch (IOException e) {
                                    System.exit(0);
                    } catch (IOException e1) {
                            System.err.println(e1);
                            System.exit(1);
                    System.exit(0);
    }

    I don't see anythi obvious. In both catch blocks, call printSckTrace on the exception yhou caught.
    I think the real culprit is the ~ though.
    ~ is interpreted by some (most?) shells to men home dir. However, when you just exec a command, you don't have a shell to do that interpretation for you, so it's looking for a directory that's literally named ~.
    Either exec a shell (read the man pages for the shell of your choice, but for zsh I think it's "/bin/zsh -c find ~ blah blah blah) or else just put the actual path to your home directory into the string you pass to exec. You can get that from System.getProperty("user.home").

  • Does find command work on Time Machine Volumes

    Trying to help someone search for instances of a file that is within a Time Machine backup. When using the UNIX find command it seems to take a lot longer to run than one would expect with the amount of data on the Time Machine disk.
    Does anyone know if find (in 10.5.8) can search Time Machine backups?

    I've had a find running on my TM disk for about 4 hours now and it hasn't returned anything. Don't think it should take that long to search through ~350 Gig worth of files.
    But it doesn't look like 350GB to find. Rather it looks like 350GB times the number of TimeMachine increments you have.
    Or more correctly, if you have 1 million files on your disk (I actually have 1.2 million), and if you have 50 TimeMachine increments, then find thinks you have 50 million files to be searched.
    And most likely each file access is going to be at least 1 disk access, so that would be 50 million disk accesses. Your typical hard disk is good for 50 to 100 disk accesses per second, so that could be over 100 hours on a good day. That seems a bit long, so my guess about 1 access per file is most likely too high, but I'm still sure that accessing 50 million files is going to take a long time (hours).

  • A Unix question: find command

    Hi all,
    Sorry for posting a Unix question here.
    In the following directory I have:
    /opt/SonicSoftware/SonicMQ/samples/TopicPubSub/DurableChat>ls
    DurableChat.class DurableChat.java Readme.txt
    However, if I try:
    /opt/SonicSoftware>find -iname DurableChat.class
    The path can not be found, it just gives me the prompt back; I don't know what the reason is. Any idea?

    I'm just wondering can the symbolic link be the
    reason that class file can not be found (I guess, not
    though, b/c other classes can be found):What do you mean "not found"?
    Do you mean why the find command isn't finding it? Yes, that's why. But now that you know, you can use -follow.
    Or do you mean the VM is unable to find the class at runtime? I'm almost certain the classloader can follow symbolic links in the classpath, so I don't think that's the problem.
    >
    /opt/SonicSoftware/SonicMQ/samples/TopicPubSub/Chat>..
    /../SonicMQ.sh DurableChat -u AlwaysUp
    Exception in thread "main"
    java.lang.NoClassDefFoundError: DurableChat
    Should I change the path that it won't be symbolic
    anymore?Try it and see if it fixes it. I'd be surprised, but you never know. If making it not a link fixes it, then maybe that's what you have to do. If it doesn't fix it, then you know you have to look somewhere else.

  • How to ignore subdirectories in find command of unix

    how to exclude subdirectories of a path from find command
    /app
    /app/fmbs
    /app/fmbs/temp
    find /app/fmbs -name *.fmb
    i want to ignore any fmb file existing into subdirectories created under temp subdirectory.
    regards

    Not sure if this helps but instead of using "find" as you are giving a specific path why not use "ls"
    Example:
    # ls /app/fmbs | grep ".fmd" (This will list all file names in specified directory)
    or
    # ls /app/fmbs/*.fmd (This will list all file names & path in specified directory)
    I hope this helps
    I am working on increasing our list of useful 1 liner commands and what we've got can be found at unbreakablehelp.com main page left hand side there are two links.
    Enjoy it.

  • Unix find - need nonrecursive solution

    Hey got another UNIX question.
    I'm on Unix, in SunOS 5.10
    I'm trying to use the find command to pick off some target files, however, it traverses all subfolders
    recursively. I realize I could just use an "ls" solution, however, I also want to utilize the -mtime option of
    find (to pick off only files older than - for example - 4 weeks.)
    So I suppose my bigger question is: "What's the easiest way to search a single directory for files older than a
    given time (ie # of days), and not recursively search child folders?"
    So first off, a test case:
    mkdir test
    cd test
    touch abc.txt
    touch abc.sh
    mkdir dir1
    touch dir1/abc.sh
    cd ..
    find ./test -type f -name "*.sh"
    ./test/abc.sh
    ./test/dir1/abc.sh
    So here, I just want to return:
    ./test/abc.sh
    Now doing some Googling, I found a few threads that mention some other options:
    1) -maxdepth
       Tried this, doesn't seem to be there in my version of Unix/ksh
       find ./test -type f -name "*.sh" -maxdepth 1
       find: bad option -maxdepth
    2) -xdev
       Only works on mount points, not a good/generic solution. (doesn't work for me, these aren't mount points)
    3) -prune
       find dir \( ! -name dir -prune \) ...
       so :
       find ./test \( ! -name ./test -prune \) -type f -name "*.sh"
          (no results)
       find ./test \( ! -name "./test" -prune \) -type f -name "*.sh"
          (no results)
    Any ideas?

    sybrand_b wrote:
    My big question is
    Why are you asking off-topic Unix questions in a forum about Oracle RDBMS?
    Sybrand Bakker
    Senior Oracle DBA
    Ah, I see what I did. I thought I was posting to a generic "General" forum, however, this is the "General" sub forum WITHIN the Oracle Database forum - my bad.
    I know we had some areas on this site for other topics, (ie Java, Linux, etc), and I was trying to get to there, but it's the first time I wanted to post outside of Oracle topic - and I did it wrong. Sorry about that.
    Is it possible to move this thread to this forum, perhaps? where it might be more "on-topic"?
    https://community.oracle.com/community/developer/english/server_%26_storage_systems/solaris/solaris_10

  • File path from find command and using POSIX

    Hi,
    I have a find command in do shell script returning output files of the form ./xyz/abc/.../...
    instead of the full path.
    I am guessing that this is the problem when I use POSIX path of one of those files. Can Applescript understand the "./" or does it need a full Unix path to convert it back?
    In that case, how do I ask find command to return the full path?
    Thanks in advance!

    >I am guessing that this is the problem when I use POSIX path of one of those files. Can Applescript understand the "./" or does it need a full Unix path to convert it back?
    You're right - AppleScript won't be able to use those paths because AppleScript has no idea of the current directory used by the shell.
    The problem is that you're defining '.' a the start point of your search.
    For each matching file find will print this start point in front of the relative path, assuming that you know where you're starting from. So the solution is to provide that path as the search start point rather than .
    For example, if your current script says:
    <pre class=command>cd /some/directory
    find . -name "*.mp3"</pre>
    You could/should rewrite this as:
    <pre class=command>find /some/directory -name "*.mp3"</pre>
    in the second case all matches would include the full path including the /some/directory part.
    If you can't predict what your search directory will be you can write your find like this:
    <pre class=command>find `pwd` -name "*.mp3"</pre>
    which will fill in the current directory (via pwd at the time the search is executed and will output full paths that AppleScript can work with.

  • Unix Fan Command?

    I recently installed two new fans in my TiBook (a somewhat nightmarish process, but everything seems to be okay). I'm confident that the primary fan is working at both high and low speed -- I can hear it. But, even after running hardware test, I'm unsure about the status of the secondary fan.
    I have searched in vain for a utility that will let me turn the fans on and off to test them. Is there a Unix command or utility that I can use? (BTW, the widgets that show fan status, etc., do not work on this old-but-loved beast).
    Thanks in advance for your assistance.

    etresoft wrote:
    I don't know if these will work or not. Regular expressions are powerful, but tricky. Plus, there are a few different, but similar, varieties. Also, I don't know if the find within a find syntax will work. This might be something that is better suited to Perl. You would then have much more control over what you are doing.
    Running this find command finds exactly what I'm looking for:
    find . -type d -name "04ClientOriginals" -exec find {} -mtime +30 -type d -maxdepth 1 ;
    I hope I'm wrong, but can't you call -exec only once? As a test I ran this:
    find . -type d -name "04ClientOriginals" -exec find {} -mtime +30 -type d -maxdepth 1 -exec ls -l {} ;
    If I invoke -exec a second time, I get this error:
    find: -exec: no terminating ";" or "+"
    find: -exec: no terminating ";" or "+"
    find: -exec: no terminating ";" or "+"
    I've searched high and low and I cannot find an example of the find command calling -exec more than once.
    My regex skills are pretty weak, so I'll only tread those waters if I have to.

  • UNIX sed commands to clean up data before loading into BI

    Hi all,
    we are trying to load the data into BI from text files.. This data needs to be cleaned before it can be loaded into BI and this has to be done using UNIX sed commands!!
    We basically need to do a data cleansing act, like removing unwanted characters (tab values and newline values as part of the characteristic values). How can it be done using unix sed commands??
    your help is very much appreciated.
    Regards

    Hi all,
    we are trying to load the data into BI from text files.. This data needs to be cleaned before it can be loaded into BI and this has to be done using UNIX sed commands!!
    We basically need to do a data cleansing act, like removing unwanted characters (tab values and newline values as part of the characteristic values). How can it be done using unix sed commands??
    your help is very much appreciated.
    Regards

  • Find Command in iCal doesn't work

    I have tried to use the Find Command in iCal. It doesn't work either from the Edit pull down command nor the keyboard command. Please try this in your setup and tell me whether it works?
    I have an Intel Mac Mini running 10.4.9.
    Bob Gallant

    Hi Bob,
    It works for me.
    Find will only search in selected calendars. Do you have the relevant calendars checked in the calendar list? (you can select all calendars by Command-Clicking one checkbox)
    Best wishes
    John M

  • Incomplete Finder find command results

    In Tiger I would use the search box in any Finder window to look for files. It would do a decent job of sorting and it displayed results sorted by "type" of file. With Leopard I cannot find folders or files in the user's Library folder (and other places). Is there a way to get Finder's find command to do a more thorough search? BTW I usually look for folders and files by name.

    system files are excluded from searches by default. to include them do the following.
    type command+f to bring up a search window. Click on "kind", scroll down and select "Other". in the resulting popup choose "system files" and set to include.

  • Finder Find command is suddenly not speedy and works weirdly

    I have a number of small, and one large, problems when I use command-F to find things in the Finder.
    After upgrading to Leopard from Tiger, like all users I experienced a WONDERFUL increase in the usefulness of this command. So I use it a lot, and for a long time it worked perfectly. My current problem is that when I type command-F, it opens a new finder window, and...
    (1) ... when I click on the box to type the words I want to find, the insertion point doesn't appear, but the letters do appear there after I type something [minor], and...
    (2) ... a FEW results of the search do appear instantly, but the window seems to enter a semi-frozen state [major; see below], and ...
    (3) ... the Finder window which is finding shows signs of being inactive (scroll bar bubble is gray, not colored; columns do not sort when column header is clicked); window is in some ways unresponsive [middling], and ...
    (4) ... after awhile (often as long as 30 or 40 seconds) the window suddenly finishes whatever was holding it up and the full set of results appear, the scroll bar bubble becomes colored, column-header-clicking sorts the column instantly.
    In short, there is now a long, weird, semi-inactive period between the initial appearance of a few Find results and the final appearance of the entire list, when I have gotten used to the seemingly 100% instantaneous appearance of a Find request's results. I'm spoiled, and I want my wonderful Find command back!
    The only thing I can think of that I might have done to contribute to this is that I HATE the behavior of the Finder searching using the title bar's oval Find window, so I removed that part from the default window setup. That is, I've changed my preferences so that when a new Finder window appears, there is no oval Find window in its upper right-hand corner. Thus, when I type command-F the Finder notices that there is no Find window to put the insertion point into, so it opens a few window with a search field at the top (the "Search for" box). (And then it refuses to put an insertion point into the window where I'm supposed to type the Search string.)
    Am I being clear?

    Did you read my hint at http://www.macosxhints.com/article.php?story=20080229204517495 ?

  • How to call unix script/command in ODI

    Hello Gurus,
    Please let me know how to call unix script/command in ODI?
    Thanks
    Shridhar

    you can call shell script using the OS command found in Package.
    Step 1. Drag the OS Command in the Packgae
    Step 2. In the Text mentiond call the script say for ex sh /opt/path/script.sh
    Step 3. Execute.
    Note : Make sure the User through which ODI is triggering does have the required permission to execute shellscript , also always provide the full path , since scripts are execute from the oracldi/bin folder so its necessary to provide the complete path of the script location.
    Hope this helps.

  • Find command doesn't work

    The find command F or just Find doesn't work any ideas on fixes? I tried trashing kybrd and finder prefs. This is on a G3 running 9.2
    Thanks

    Hi, Bookalaka -
    If Sherlock, or an alias to it, is not in the Apple Menu Items folder (in System Folder), then the Find function (Command-F) will not work. If that is the case, replace that item - move either Sherlock itself, or place an alias to it, into the Apple Menu Items folder.
    Note - if you use Internet Explorer, and want to be able to use the supplemental toolbar icon for Sherlock, then Sherlock itself must be placed in the Apple Menu Items folder (IE does not recognize an alias to it).
    If for some reason you are missing Sherlock completely, you can replace it fairly easily. Look in the System Folder on any OS 9.1 or later Install CD; you'll find it in the Apple Menu Items folder. Just copy it to your hard drive.

  • Problem with unix "foreach" command

    Hi,
    I am facing a problem with unix command "foreach". I trying to process files using unix foreach command. When running the script with 500 or 1000 files. It is running fine. But when I am trying to the script with 2000+ files. Its throwing an error "Arguments too long".
    below is the syntax I am using in the script:
    foreach name (*)
    end
    Could anybody help me on this issue.
    Thanks in Advance.
    Manasa.

    UNIX/Linux systems expand wildcards onto the command line before invoking the
    individual commands. In effect, the shell rewrites the command line you give
    substituting the wildcard expansion. There is a limit to how long this command
    line can get.
    For example, suppose you have two files ("foo" and "bar") in your directory.
    The line:
    foreach name (*)
      echo $name
    endgets rewritten to:
    foreach name (foo bar)
      echo $name
    endand then the shell starts interpreting your script. So if you have many, many
    files, the rewritten line becomes:
    foreach name (f1 f2 f3 ... f10927)
      echo $name
    endso chances are the "foreach" line simply gets too long. To avoid problems do
    it this way; it avoids any problems based on how many files you have:
    ls | while read name
    do
      echo $name
    doneThis way the shell never exceeds its line length limitations because the
    wildcard is never expanded.
    Cheers

Maybe you are looking for