06-06-2008
stop unix find on a directory structure after finding 1st occurrence
Hi,
Has anyone tried to restrict Solaris 10 unix find on a large directory structure based on time to stop running after finding the first occurrence of a matching query. Basically I'm trying to build up a usage map of user workspaces based on file modification (week/month/3 months/year etc) and I know if I can get find to stop after finding something modified in the last year in the very first directory instead of running to the bottom getting all files the program would run a lot faster:
Excerpt:
week=Yes; month=Yes; month6=Yes; year=Yes; year2=Yes
if [[ -z `find "${DIR}/${j}" -mtime -730` ]];then
week=No; month=No; month6=No; year=No; year2=No
else
if [[ -z `find "${DIR}/${j}" -mtime -365` ]];then
week=No; month=No; month6=No; year=No
else
if [[ -z `find "${DIR}/${j}" -mtime -180` ]];then
week=No; month=No; month6=No
else
if [[ -z `find "${DIR}/${j}" -mtime -30` ]];then
week=No; month=No;
else
if [[ -z `find "${DIR}/${j}" -mtime -7` ]];then
week=No;
fi
fi
fi
fi
fi
Thanks in advance,
John
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Does anyone know of a good Internet source that explains the directory structure of Unix/Linux??
Thanks
Gregg (2 Replies)
Discussion started by: gdboling
2 Replies
2. UNIX for Dummies Questions & Answers
Hi all
Is it possible to copy a structure of a directory only.
e.g.
I have a file with the following entries that is a result of a find :-
/dir1/dir2/file.dbf
/dir1/dir2/dir3/file1.dbf
/dir1/file.dbf
I want to copy these to a directory and keep the structure however starting at a new dir... (8 Replies)
Discussion started by: jhansrod
8 Replies
3. UNIX for Advanced & Expert Users
Hi,
I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub folder is source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (4 Replies)
Discussion started by: srmadab
4 Replies
4. UNIX for Dummies Questions & Answers
Hello,
I just want to ask the following use of find command:
1. how can I find files only to the current directory?
2. how can I find files to directories and all subdiretories (are this include soft links?) but will not go to other mountpoints that is under that mountpoint.
Im combining... (1 Reply)
Discussion started by: james_falco
1 Replies
5. UNIX for Dummies Questions & Answers
Hi,
I'm new here so hello to everyone...i'm also new to linux/unix but got my first dedicated server about 2 weeks ago and have been using ssh to configure it on ubuntu linux.
I have a question about something i can't work out....if i use ftp to transfer files ( php, html, javascript files... (2 Replies)
Discussion started by: elduderino
2 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I want to list all the last directories from mentioned base path.
for eg: If i have a base path say /base/base1/
How can i get the path till last node in tree like directory structure of unix by applying any command.
so that i will get following output.
... (7 Replies)
Discussion started by: Shiv@jad
7 Replies
7. Shell Programming and Scripting
I'm using this now:
find /some/path/with/sourcefiles -type f -size -7M -exec /bin/cp -uv {} /some/path/ \;
but it doesn't preserve the directory structure, also I've tried it with
find /some/path/with/sourcefiles -type f -size -7M -exec /usr/bin/rsync -auv {} /some/path/ \;
but that doesn't... (9 Replies)
Discussion started by: unclecameron
9 Replies
8. UNIX for Dummies Questions & Answers
Hi All,
im a new guy if it comes to Unix. I am trying to auto categorize Nzbget downloads the most basic way. I already manage to find files within the directory i'm at and move them with if check to a certain dir. Unfortunately this command is restricted to the directory i'm at and does not... (2 Replies)
Discussion started by: RoxXxoR
2 Replies
9. UNIX for Dummies Questions & Answers
Hi there, I'm trying to pull all my flacs out of my Music collection. I can do it with following command
find b/ -name *.flac -exec mv {} flac/ \;
which works great except it moves all the flac files to the flac folder. I want it to recreate the original folder the flacs were found in and mv... (8 Replies)
Discussion started by: fistikuffs
8 Replies
10. UNIX for Dummies Questions & Answers
Hi everyone, I'm a new member at the forum I mistakenly posted this elsewhere too.
I have a file like this: field 2 values are either 0 or negative. file test4:
100815 -20
118125 0
143616 0
154488 0
154488 0
154488 -6
196492 -5
196492 -9
196492 -7
27332 0... (5 Replies)
Discussion started by: meet77
5 Replies
LEARN ABOUT PHP
mb_strrpos
MB_STRRPOS(3) 1 MB_STRRPOS(3)
mb_strrpos - Find position of last occurrence of a string in a string
SYNOPSIS
int mb_strrpos (string $haystack, string $needle, [int $offset], [string $encoding = mb_internal_encoding()])
DESCRIPTION
Performs a multibyte safe strrpos(3) operation based on the number of characters. $needle position is counted from the beginning of
$haystack. First character's position is 0. Second character position is 1.
PARAMETERS
o $haystack
- The string being checked, for the last occurrence of $needle
o $needle
- The string to find in $haystack.
o $offset
- May be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an
arbitrary point prior to the end of the string.
o $encoding
-The $encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used.
RETURN VALUES
Returns the numeric position of the last occurrence of $needle in the $haystack string. If $needle is not found, it returns FALSE.
CHANGELOG
+--------+---------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------+
| 5.2.0 | |
| | |
| | Added the optional parameter $offset. |
| | |
+--------+---------------------------------------+
NOTES
Note
The $encoding parameter was moved from the third position to the fourth in PHP 5.2.0. For backward compatibility, $encoding can be
specified as the third parameter, but doing so is deprecated and will be removed in the future.
SEE ALSO
mb_strpos(3), mb_internal_encoding(3), strrpos(3).
PHP Documentation Group MB_STRRPOS(3)