Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 866.5k
  • 205
  • 1.8k
  • 2.3k
Formatting
Source Link
jasonwryan
  • 74.9k
  • 35
  • 204
  • 232

I am looking to have a script delete files that are older than 90 days in certain directories. As in, there are 8 directories that have different paths to them.

I can run the find command on one directory as such: find /directory1/dir2/dir3/dir4/ -mtime +90 | wc -l

find /directory1/dir2/dir3/dir4/ -mtime +90 | wc -l 

That command will give a result like 6401.

But I have 8 directories that need to be looked through. How could I build a list of directories as a variable. I have:

variable

DIRLIST=/directory1/dir2/dir3/dir4/ /directory1/dir2/dir3/dir5/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir7/

command

find $DIRLIST | wc -l

variable DIRLIST=/directory1/dir2/dir3/dir4/ /directory1/dir2/dir3/dir5/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir7/ command find $DIRLIST | wc -l 

The output gives me something along the lines of:

nameofscript.sh[2]: /directory1/dir2/dir3/dir5/: 0403-006 Execute permission denied.

nameofscript.sh[2]: /directory1/dir2/dir3/dir5/: 0403-006 Execute permission denied.

Its strange because when I call that directory alone in the find command, the command works, so I know its not actually a permspermissions issue.

Any help would be greatly appreciated. Thank you!

I am looking to have a script delete files that are older than 90 days in certain directories. As in, there are 8 directories that have different paths to them.

I can run the find command on one directory as such: find /directory1/dir2/dir3/dir4/ -mtime +90 | wc -l

That command will give a result like 6401.

But I have 8 directories that need to be looked through. How could I build a list of directories as a variable. I have:

variable

DIRLIST=/directory1/dir2/dir3/dir4/ /directory1/dir2/dir3/dir5/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir7/

command

find $DIRLIST | wc -l

The output gives me something along the lines of:

nameofscript.sh[2]: /directory1/dir2/dir3/dir5/: 0403-006 Execute permission denied.

Its strange because when I call that directory alone in the find command, the command works, so I know its not actually a perms issue.

Any help would be greatly appreciated. Thank you!

I am looking to have a script delete files that are older than 90 days in certain directories. As in, there are 8 directories that have different paths to them.

I can run the find command on one directory as such:

find /directory1/dir2/dir3/dir4/ -mtime +90 | wc -l 

That command will give a result like 6401.

But I have 8 directories that need to be looked through. How could I build a list of directories as a variable. I have:

variable DIRLIST=/directory1/dir2/dir3/dir4/ /directory1/dir2/dir3/dir5/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir7/ command find $DIRLIST | wc -l 

The output gives me something along the lines of:

nameofscript.sh[2]: /directory1/dir2/dir3/dir5/: 0403-006 Execute permission denied.

Its strange because when I call that directory alone in the find command, the command works, so I know its not actually a permissions issue.

Any help would be greatly appreciated.

Source Link
Simply
  • 11
  • 1
  • 2

How to set up a pre-defined variable with multiple directory paths to use with the find command

I am looking to have a script delete files that are older than 90 days in certain directories. As in, there are 8 directories that have different paths to them.

I can run the find command on one directory as such: find /directory1/dir2/dir3/dir4/ -mtime +90 | wc -l

That command will give a result like 6401.

But I have 8 directories that need to be looked through. How could I build a list of directories as a variable. I have:

variable

DIRLIST=/directory1/dir2/dir3/dir4/ /directory1/dir2/dir3/dir5/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir6/ /directory1/dir2/dir3/dir7/

command

find $DIRLIST | wc -l

The output gives me something along the lines of:

nameofscript.sh[2]: /directory1/dir2/dir3/dir5/: 0403-006 Execute permission denied.

Its strange because when I call that directory alone in the find command, the command works, so I know its not actually a perms issue.

Any help would be greatly appreciated. Thank you!