Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

find

chmod

why doesn't this work I am trying to change all files to 644 abd all -d to 755:

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

i get: find: missing argument to `-exec' thanks

like image 321
user1920187 Avatar asked Nov 02 '13 00:11

user1920187


People also ask

What does chmod 644 mean?

Permissions of 644 mean that the owner of the file has read and write access, while the group members and other users on the system only have read access. Issue one of the following chmod commands to reset the permissions on a file back to one of the likely defaults: chmod 600 ~/example.txt chmod 644 ~/example.txt.

How do I set permissions on 644?

Change Permissions Recursively Then use first command to chmod 755 for all directories and sub directories. The second command will change all the files permission to 0644 (chmod 644) under the directory tree. You can also change permission using xargs command to do this quickly.

What does chmod 755 mean?

755 means read and execute access for everyone and also write access for the owner of the file. When you perform chmod 755 filename command you allow everyone to read and execute the file, the owner is allowed to write to the file as well.

Which chmod is the best?

Usually 0644 is a good choice, which gives the owner read and write rights, but everybody else only read.


2 Answers

Piping to xargs is a dirty way of doing that which can be done inside of find.

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

You can be even more controlling with other options, such as:

find . -type d -user harry -exec chown daisy {} \; 

You can do some very cool things with find and you can do some very dangerous things too. Have a look at "man find", it's long but is worth a quick read. And, as always remember:

  • If you are root it will succeed.
  • If you are in root (/) you are going to have a bad day.
  • Using /path/to/directory can make things a lot safer as you are clearly defining where you want find to run.
like image 114
Phil Avatar answered Oct 31 '22 21:10

Phil


A good alternative is this:

find . -type f | xargs chmod -v 644 

and for directories:

find . -type d | xargs chmod -v 755 

and to be more explicit:

find . -type f | xargs -I{} chmod -v 644 {} 
like image 24
Seth Malaki Avatar answered Oct 31 '22 21:10

Seth Malaki