2

Disclaimer: I am a total Linux amateur. Hi, I am currently setting up a PHPIPAM Server on CentOS 7. I am following this guide: https://hostadvice.com/how-to/how-to-install-phpipam-on-centos-7/ , which tells me to run the command: "

find . -type f -exec chmod 0644 {} ;

When I do so, the message:

find: missing argument for "-exec".

shows up. What can I do to get the command to work?

6

Ordinarily the ; acts as a separator between commands. However, for find -exec it needs to be provided as an actual parameter to the command itself (to indicate where the -exec option ends). To achieve that, it needs to be either quoted or escaped:

-exec ..... \;

-exec ..... ";"

-exec ..... ';'
  • 1
    He's missing the f as well. See my answer. – DavidPostill Jul 11 at 9:47
  • 1
    The f was present in the example found in the original website, while the ; escape/quoting is missing there as well. – grawity Jul 11 at 10:01
  • I think this worked. No error message. How can I check if it worked? – Franz Zehrer Jul 11 at 10:01
  • Well, a possible approach would be: 1) Look at the command you told find to run (which is "chmod 0644 <all files>"). 2) Figure out what the command does (it sets permissions 0644, aka rw-r--r--, for all files specified). 3) Use ls -l to look at the files and verify that they indeed have the permissions that chmod was supposed to set. – grawity Jul 11 at 10:29
  • You can also use find . -type f -ls to list all files with permissions, or find . -type f \( \! -perm 0644 \) -ls to find those which have unexpected permissions set. Or... you could run the original command again, but change chmod to chmod -v and make it verbose about what it's actually doing. – grawity Jul 11 at 10:31
5

When I do so, the message: 'find: missing argument for "-exec".' shows up

find . -type -exec chmod 0644 {} ;

You are missing a \ before the ; at the end of the line (which is missing in the link you quoted).

In addition, you haven't supplied an argument for -type.

Your command should be:

find . -type f -exec chmod 0644 {} \;

-type c File is of type c as listed below:

b block (buffered) special

c character (unbuffered) special

d directory

p named pipe (FIFO)

f regular file

l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype.

s socket

D door (Solaris)

Source find Man Page - Linux - SS64.com

  • Yes i forgot to write down the 'f' in here, I did write it in the command though. So that is not the problem, thank you anyway. The solution with either \; ';' or ";" seemed to work. – Franz Zehrer Jul 11 at 10:02
  • @FranzZehrer If you copied incorrectly, you should edit the question to show what you actually did. – Barmar Jul 11 at 19:22
  • It should have been obvious that this was a copying error. If he actually ran the command as posted, he would have gotten an error about in incorrect argument to -type, not a missing argument to -exec. – Barmar Jul 11 at 19:23
2

The other answers explain why the problem is happening, but there is another solution to the problem. You can use + instead of \; and then you don't have to worry about escaping the ;. For something like chmod over a large number of files, this will likely be somewhat faster, too. You would run it like this:

find . -type f -exec chmod 0644 {} +

They're not exactly identical, though. With + the find command is passing multiple files as separate arguments to a single invocation of chmod. A lot of programs can handle this just fine, but some can't. If a program you want to pass to -exec needs to take exactly 1 file argument at a time, then you have to use \; instead.

  • 1
    In addition, with + the {} must appear exactly once and be the last argument (i.e. just before +); while with ; it can be anywhere, many times or none. At least this is what POSIX says, some implementations of find may be more flexible. – Kamil Maciorowski Jul 12 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.