script with multiple line of find, error find: missing argument to `-exec'

General support questions
Post Reply
reedone816
Posts: 4
Joined: 2018/10/17 11:27:15

script with multiple line of find, error find: missing argument to `-exec'

Post by reedone816 » 2018/10/17 11:41:25

hello, i'm new to linux, and just trying to create script.
i have create script to delete files in several folders that is older than x days, so i create it like this:

Code: Select all

#!/bin/bash
find /pathtofolder/* -type f -mtime +7 -exec rm {} \;
find /pathtofolder/* -type f -mtime +7 -exec rm {} \;
the result is error:

Code: Select all

find: missing argument to `-exec'
find: missing argument to `-exec'
can anyone help?

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: script with multiple line of find, error find: missing argument to `-exec'

Post by TrevorH » 2018/10/17 14:08:21

Use -delete instead of -exec rm {} \;

And you probably don't want the * on the end of the path either, find already traverses all subdirectories unless you tell it not to.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

reedone816
Posts: 4
Joined: 2018/10/17 11:27:15

Re: script with multiple line of find, error find: missing argument to `-exec'

Post by reedone816 » 2018/10/18 02:40:07

Code: Select all

find /path to folder/ -type f -mtime +7 -delete;
find /path to folder/ -type f -mtime +7 -delete;
created error: command not found

btw it works when i run the command perline directly in the terminal, but error when in the script

tunk
Posts: 1205
Joined: 2017/02/22 15:08:17

Re: script with multiple line of find, error find: missing argument to `-exec'

Post by tunk » 2018/10/18 09:59:23

Does it work without the semicolon? Or maybe use the full path of find, /usr/bin/find.

reedone816
Posts: 4
Joined: 2018/10/17 11:27:15

Re: script with multiple line of find, error find: missing argument to `-exec'

Post by reedone816 » 2018/10/19 02:45:15

removing the semicolon produce error: 'usr/bin/find: unknown predicate `-delete

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: script with multiple line of find, error find: missing argument to `-exec'

Post by TrevorH » 2018/10/19 08:01:06

What is the output from rpm -q centos-release and from uname -a ?
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

reedone816
Posts: 4
Joined: 2018/10/17 11:27:15

Re: script with multiple line of find, error find: missing argument to `-exec'

Post by reedone816 » 2018/10/22 03:22:54

nevermind, I found the issue, it is the $'\r' error, after i use bash -x command.
this seems to happen because i create the script in windows using notepad++.
to fix that i need to convert it to linux format using menu: Edit -> EOL conversion -> Unix/OSX format.

thanks to the quick responses.

Post Reply