I am creating a script with below commands in solaris
name=$(date +"%y-%m-%d")
mkdir /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/$name
find /cms/Oracle/Middleware/dib_common/Advices/EMAIL/ -type f -mtime +30 -exec mv {} /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/$name \;
tar -zcvf /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/${name}.tar.gz /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/${name}
find /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/ -mtime +60 -name "*.tar.gz" -exec rm {} \;
-maxdepth
is giving below error.
-bash-4.4$ find /cms/Oracle/Middleware/dib_common/Advices/EMAIL/ -type f -mtime +30 -maxdepth 1 -exec mv {} /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/$name \;
find: bad option -maxdepth
find: [-H | -L] path-list predicate-list
-bash-4.4$
Even -path
is not working.
Is there any workaround here.
My requirement is i want to find files from below directory only and not any subdirectory
/cms/Oracle/Middleware/dib_common/Advices/EMAIL/
Below is working for me now . Just to update -not is also not available option in my environment.
find /cms/Oracle/Middleware/dib_common/Advices/EMAIL/. ! -name . -prune -type f -mtime +30 -exec mv {} /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/"$name" \;
The find command:
find path/to/the/dir -type f -maxdepth 1
can be substituted with:
find path/to/the/dir/. -not -name . -type d -prune -o -type f
The find
command interprets the sequence above as:
path/to/the/dir
recursively.As of the described example, please try to modify the line:
find /cms/Oracle/Middleware/dib_common/Advices/EMAIL/ -type f -mtime +30 -maxdepth 1 -exec mv {} /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/$name \;
as:
find /cms/Oracle/Middleware/dib_common/Advices/EMAIL/. -not -name . -type d -prune -o -type f -mtime +30 -exec mv {} /cms/Oracle/Middleware/dib_common/archive/Advices/EMAIL/"$name" \;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.