LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I messed up permissions and ownership (https://www.linuxquestions.org/questions/linux-newbie-8/i-messed-up-permissions-and-ownership-670729/)

digity 09-18-2008 01:11 AM

I messed up permissions and ownership
 
I copied over files from a FAT32 drive to a EXT3 drive and the permissions are all out of whack:

Code:

digity@bighouse:/media/morningside/workspace# ls -la
total 652288
drwxr--r--  12  999 root      4096 2008-09-01 12:07 .
drwxr--r--  12 root root      4096 1969-12-31 16:00 ..
drwxr--r--  2  999 root      4096 2008-06-16 16:51 backups
drwxr--r-- 119  999 root    65536 2008-09-03 16:56 downloads
-rwxr--r--  1  999 root 318191155 2008-06-13 19:01 fonts.zip
drwxr--r--  3  999 root      4096 2007-11-28 03:48 found photos
-rwxr--r--  1  999 root 348377092 2008-06-13 20:19 Fully Collected Fonts Library.zip
drwxr--r--  2  999 root      4096 2008-04-21 07:31 incomplete
-rwxr--r--  1  999 root    361366 2008-07-21 07:29 inventory-mint.zip
drwxr--r--  2  999 root      4096 2007-11-15 11:16 itunesexports
drwxr--r--  9  999 root      4096 2007-10-19 20:21 Music
drwxr--r--  2  999 root      4096 2008-06-10 03:34 playlists
-rwxr--r--  1  999 root    217088 2000-10-16 06:30 SpaceMonger.exe
drwxr--r--  15  999 root      4096 2007-10-25 00:34 UNSORTED Music
drwxr--r--  2  999 root      4096 2007-11-15 17:37 zune backgrounds
drwxr--r--  4  999 root      4096 2008-05-19 18:37 Zune Media

what are the commands and syntax I need to enter to:

[1] get groups and others able to open all sub-folders/directories
[2] read & write permissions for digity for all files & folders recursively (which i'd imagine would be the group)
[3] get root (user/owner) only read & write permissions for all files recursively

Mr. C. 09-18-2008 01:20 AM

Code:

cd /media/morningside/workspace
find . -type d -print0 | xargs -0 chmod go+rx  # directories are readable by all
# if you want files owned by root
find . -type f -print0 | xargs -0 chmod 600    # files read/write, root only
chown -R root .                        # to provide root ownership

I don't know what you mean my "digity" - is this a user?

jschiwal 09-18-2008 01:42 AM

The fat32 filesystem can't contain Linux permissions & ownership, so the entire partition is mounted with all files having the same ownership and permissions. The same goes for all the directories. These permissions are determined when you mount the partition. Anyway, you can simply use chown to change the ownership and chmod to change the permissions. The find command can search for only directories or only files and apply a command to what it finds. You can use the "-R" recursive option to chown to change the groups and ownership of all of the files at once.

Code:

cd /media/morningside/workspace
sudo chown <yourusername>:<yourgroup> * -R
find ./ -type d -exec chmod ug=rwx \;
find ./ -type f -exec chmod ug=rw  \;


chrism01 09-18-2008 01:58 AM

There is also a recursive (-R) option to chmod.

Mr. C. 09-18-2008 09:36 AM

Quote:

Originally Posted by chrism01 (Post 3284082)
There is also a recursive (-R) option to chmod.

Right, but it is indiscriminate between files and directories. The OP wants directories with one set of permissions, and another set for files.

This is so common, I have some bash functions dchmod and fchmod to perform the actions:

Code:

function dchmod {
    [ $# -lt 2 ] && { echo usage: dchmod perms dir [...]; return 1; }
    rchmod d "$@"
}
function fchmod {
    [ $# -lt 2 ] && { echo usage: fchmod perms dir [...]; return 1; }
    rchmod f "$@"
}

function rchmod {
    [ $# -lt 3 ] && { echo usage: rchmod d|f perms dir [...]; return 1; }
    fileordir="$1"; shift
    perms=$1; shift;
    if which gfind > /dev/null ; then
        gfind "$@" -type $fileordir -print0 | xargs -0 chmod $perms
    else
        find "$@" -type $fileordir -exec chmod $perms {} \; -print
    fi
}

GNU find is named gfind on my system; season to taste for your distro.

digity 09-18-2008 05:18 PM

thanx everyone! i essentially found a solution elsewhere that is exactly what jschiwal recommended.

everything is working beautifully now!

thanx again folks!

Mr. C. 09-19-2008 12:33 AM

Sadly, I hadn't noticed your member name was digity. Sorry.

fosopip 09-19-2008 12:43 AM

being a noon to this wonderous stuff these commands are all strange to me but hope to master some of them, nice to see te help given by members on the board

digity 12-07-2008 06:02 PM

Quote:

Originally Posted by digity (Post 3284968)
thanx everyone! i essentially found a solution elsewhere that is exactly what jschiwal recommended.

everything is working beautifully now!

thanx again folks!

to be clear I used exactly...

for folders/directories:
Code:

sudo find ./ -type d -exec chmod ug=rwx {} \;
for files:
Code:

sudo find ./ -type f -exec chmod ug=rw {} \;
I needed to use sudo, you may not


All times are GMT -5. The time now is 04:35 AM.