You are not logged in.

#1 2010-02-14 21:02:13

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

setting permissions - all files need to be 644/dirs 755 [SOLVED]

I have some files that are in a complex dir tree under:

/media/data
/media/data/project1
/media/data/project1/sub1
/media/data/project1/sub2
...
/media/data/project1/sub100
/media/data/project2
...etc. etc.

Basically, I need all the dirs to be 755 but all the files to be 644.  Obviously I can `chmod -R 755 /media/data` but how can cause all the files to be 644 while retaining the dirs as 755?

Last edited by graysky (2010-02-14 21:34:43)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2010-02-14 21:04:22

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: setting permissions - all files need to be 644/dirs 755 [SOLVED]

chmod 755 $(find /media/data -type d)
chmod 644 $(find /media/data -type f)

Offline

#3 2010-02-14 21:12:45

SemiBz
Member
From: Riga, Latvia
Registered: 2010-01-30
Posts: 80

Re: setting permissions - all files need to be 644/dirs 755 [SOLVED]

Allan wrote:
chmod 755 $(find /media/data -type d)
chmod 644 $(find /media/data -type f)
find /media/data -type d -exec chmod 755 {} ;\
find /media/data -type f -exec chmod 644 {} ;\

tongue

Last edited by SemiBz (2010-02-14 21:13:20)

Offline

#4 2010-02-14 21:13:59

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: setting permissions - all files need to be 644/dirs 755 [SOLVED]

Thanks Allan, that works partially.  Some of the files contain spaces and the chmod chokes on them.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2010-02-14 21:23:45

SemiBz
Member
From: Riga, Latvia
Registered: 2010-01-30
Posts: 80

Re: setting permissions - all files need to be 644/dirs 755 [SOLVED]

graysky wrote:

Thanks Allan, that works partially.  Some of the files contain spaces and the chmod chokes on them.

Shouldn't choke if used as a string ( {} ), which is why I quoted him with a more flexible command.

Offline

#6 2010-02-14 21:34:14

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: setting permissions - all files need to be 644/dirs 755 [SOLVED]

@SemiBz - Thanks!  I didn't even see your reply... we must have posted nearly simultaneously smile


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#7 2010-05-22 00:15:52

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: setting permissions - all files need to be 644/dirs 755 [SOLVED]

SemiBz wrote:
find /media/data -type d -exec chmod 755 {} ;\
find /media/data -type f -exec chmod 644 {} ;\

tongue

Oops... the ;\ should be \;

find /media/data -type d -exec chmod 755 {} \;
find /media/data -type f -exec chmod 644 {} \;

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#8 2010-05-22 00:49:16

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: setting permissions - all files need to be 644/dirs 755 [SOLVED]

graysky wrote:
find /media/data -type d -exec chmod 755 {} \;
find /media/data -type f -exec chmod 644 {} \;

Or

find /media/data -type d -exec chmod 755 {} +

which will be much faster (it groups the files into batches instead of chmodding them one at a time.

Offline

#9 2010-05-22 07:48:32

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: setting permissions - all files need to be 644/dirs 755 [SOLVED]

# recursive chmod
  $ chmod 700 **/(.) # Only files
  $ chmod 700 **/(/) # Only directories

If you have zsh

Offline

Board footer

Powered by FluxBB