LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-18-2008, 01:11 AM   #1
digity
Member
 
Registered: Apr 2005
Posts: 105

Rep: Reputation: 15
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
 
Old 09-18-2008, 01:20 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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?
 
Old 09-18-2008, 01:42 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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  \;

Last edited by jschiwal; 09-18-2008 at 01:44 AM.
 
Old 09-18-2008, 01:58 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,371

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381
There is also a recursive (-R) option to chmod.
 
Old 09-18-2008, 09:36 AM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Quote:
Originally Posted by chrism01 View Post
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.
 
Old 09-18-2008, 05:18 PM   #6
digity
Member
 
Registered: Apr 2005
Posts: 105

Original Poster
Rep: Reputation: 15
thanx everyone! i essentially found a solution elsewhere that is exactly what jschiwal recommended.

everything is working beautifully now!

thanx again folks!
 
Old 09-19-2008, 12:33 AM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Sadly, I hadn't noticed your member name was digity. Sorry.
 
Old 09-19-2008, 12:43 AM   #8
fosopip
LQ Newbie
 
Registered: Jun 2008
Posts: 6

Rep: Reputation: 0
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
 
Old 12-07-2008, 06:02 PM   #9
digity
Member
 
Registered: Apr 2005
Posts: 105

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by digity View Post
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

Last edited by digity; 12-07-2008 at 06:03 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling: permissions, ownership of files ... JosephS Slackware 1 12-22-2007 01:04 PM
permissions and ownership on dir gabsik Linux - Software 4 02-05-2007 06:48 AM
Permissions & Ownership Really screwed slacard Other *NIX 1 04-03-2005 12:36 AM
Question about ownership/permissions infornography Linux - Newbie 7 07-28-2004 05:57 AM
write permissions / ownership bynaar Slackware 15 08-08-2002 04:25 AM


All times are GMT -5. The time now is 08:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration