简体   繁体   中英

Maxdepth option not working find command in Solaris

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:

  1. Find the directory path/to/the/dir recursively.
  2. If the name is not "." and the type is "directory" then skip (-prune) it.
  3. Otherwise (-o) advance to the next condition.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM