masoud atyabi
masoud atyabi

Reputation: 1

How write Bash script to find files then move them?

I want to find files then move them, how can I do in in a Bash script?

find $PATH -type f -newermt "1 day ago" -exec gzip {} \;

Then:

find $PATH -type f -newermt "1 day ago" -exem mv {} \;

Try to add these lines in Bash script but I don't know how.

Upvotes: 0

Views: 130

Answers (1)

Arnaud Valmary
Arnaud Valmary

Reputation: 2325

May be you want to split PATH variable content before use it, like this:

find ${PATH//:/ } -type f -newermt "1 day ago" -exec gzip {} \;

Warning about your second command: find $PATH -type f -newermt "1 day ago" -exem mv {} \;. The option is -exec, not -exem.

mv command accept 2 file arguments. You pass only one.

Before execute your commands, you could place an echo command just after -exec option.

Upvotes: 1

Related Questions