You seem to want to truncate the mailboxes for all users. You can't do this by calling :
from find
as :
is not an external utility (it's a shell built-in utility). Using true
instead of :
would have worked since that is commonly available as an external command, but...
You also can't use a redirection in the command executed via -exec
since that redirection would be acted upon by the shell at the time when the find
utility first starts (not once for each found file).
Your command is essentially the same as
find /var/spool/mail/ -regextype sed -regex "^.*[^/]$" -exec : \; >{}
i.e., it will create a file called {}
into which the standard output stream of find
is redirected.
Instead, you may do something like
find /var/spool/mail -type f -exec sh -c '
for pathname do
: >"$pathname"
done' sh {} +
As a "one-liner":
find /var/spool/mail -type f -exec sh -c 'for pathname do : >"$pathname"; done' sh {} +
Or, if all mailboxes are immediately beneath /var/spool/mail
,
for pathname in /var/spool/mail/*; do
: >"$pathname"
done
As a "one-liner":
for pathname in /var/spool/mail/*; do : >"$pathname"; done
In both of these variations, the :
utility is correctly invoked and the redirection will happen for each found pathname (any regular file in or below the given search path).
Related:
truncate
, perhaps. – muru Sep 08 '19 at 14:39find /var/spool/mail/ -regextype sed -regex "^.*[^/]$" -exec truncate -s 0 {} \;
is the best solution. – Ωmega Sep 08 '19 at 14:52:
is only part of the issue. The redirection is the other part. – Kusalananda Sep 08 '19 at 15:59:
in the first place (not in bash, anyway). You can just do> file
and that will empty it. There's no need to do: > file
. So even less of a duplicate since the:
is essentially irrelevant here. – terdon Sep 08 '19 at 21:03