We help IT Professionals succeed at work.

unix permissions

cgray1223
cgray1223 asked
on
Hello,

I copied over a directory (LATEST) into a directory that I created on a linux server.  I now want to delete the LATEST directory and all directories below it, but I'm getting a permission denied.  Is there any way to delete these directories or does my user id lack sufficient privileges to do so?

drwxrwxr-x  3 colgray eng 4096 Nov  1 16:00 LATEST
dr-xrwxr-x  4 colgray eng  4096 Nov  1 16:00 bin
dr-xrwxr-x  2 colgray eng 12288 Nov  1 16:00 doc
dr-xrwxr-x  2 colgray eng  4096 Nov  1 16:00 include
dr-xrwxr-x  2 colgray eng  4096 Nov  1 16:00 lib
dr-xrwxr-x  2 colgray eng  4096 Nov  1 16:00 mapi
dr-xrwxr-x  2 colgray eng  4096 Nov  1 16:00 ref_agent

Comment
Watch Question

CERTIFIED EXPERT

Commented:
The command to do it would be:

rm -rf LATEST

The directory is owned by user colgray.  If that is not the user that you are logged in as, then you would need to be either:

1)  root

or

2)  Logged in as a user in the group "eng" (since the folder is also group writable)  You can type "id" to find out what groups you are in.

Author

Commented:
that is the user I'm logged in with.  When I try that command I get permission denied
CERTIFIED EXPERT

Commented:
Are you sure there's not stuff inside that directory that doesn't belong to colgray?

Try "ls -lRt LATEST" and see if you see files owned by other users.
CERTIFIED EXPERT

Commented:
It is not the permission of LATEST that matters.  It is the permission of the folder that holds LATEST.  What is the permission of the folder where LATEST is located?


ls -ld ..

CERTIFIED EXPERT

Commented:
@farzanj:
You are of course correct that permissions on the parent folder override, but the author says that "I copied over a directory (LATEST) into a directory that I created on a linux server."  If the author created the folder, and copied the folder LATEST into it, then the author should technically own that parent  directory.
You could try

$ rmdir LATEST

just to see what error message it produces (and tell us).
you must check the permission of parent directory

$ ls -ld .

Author

Commented:
$ ls -ld . returned drwxrwxr-x  3 userName eng 4096 Nov  1 16:00 dirname
$ rmdir LATEST returned rmdir: `LATEST': Directory not empty

The problem is pointed out by xterm, when I run $ ls -lRt LATEST I get a ton of files and directories, below are some examples

-r--rwxr--  1 colgray eng   7067 Nov  1 16:00 tree.html
dr-xrwxr-x  4 colgray eng  4096 Nov  1 16:00 bin
dr-xrwxr-x  2 colgray eng  4096 Nov  1 16:00 lib

I did a cp -R when copying over, so did it maintain the permissions from the location I copied it from?  Any ideas on how to remove all directories and files under the LATEST directory?



Assuming you are the coldgray user :
First type : chmod -R u+rw LATEST
and then : rm -rf LATEST
CERTIFIED EXPERT

Commented:
It sounds like the parent directory permissions may have changed after you copied the files?

>  $ ls -ld . returned drwxrwxr-x  3 userName eng 4096 Nov  1 16:00 dirname

So, did you purposely change what shows as "userName" and "dirname" above before posting this?

Author

Commented:
yes, the actual parent directory that contains the LATEST dir (one I'm trying to delete) is exactly below, ignore that first bullet.


$ ls -ld . yields - drwxrwxr-x  3 colgray eng 4096 Nov  1 16:00 .
CERTIFIED EXPERT

Commented:
Can you please do the commands below and paste the full output here?
pwd
rm -rf LATEST

Open in new window

Author

Commented:
$ pwd
/aut/ew/colgray
$ rm -rf LATEST
rm: cannot remove `LATEST/toolkit/bin/Linux/RefAgent.sh': Permission denied
rm: cannot remove `LATEST/toolkit/bin/Linux/RefAgent': Permission denied
rm: cannot remove `LATEST/toolkit/bin/Linux/MgmtApiTest.sh': Permission denied
rm: cannot remove `LATEST/toolkit/bin/Linux/MgmtApiTest': Permission denied
rm: cannot remove `LATEST/toolkit/bin/WinXP/RefAgent.exe': Permission denied
rm: cannot remove `LATEST/toolkit/bin/WinXP/MgmtApiTest.exe': Permission denied
rm: cannot remove `LATEST/toolkit/include/EnergyWiseApi.h': Permission denied
rm: cannot remove `LATEST/toolkit/include/EnergyWise.h': Permission denied
rm: cannot remove `LATEST/toolkit/include/EnergyWiseLog.h': Permission denied
rm: cannot remove `LATEST/toolkit/include/EnergyWiseSdk.h': Permission denied
rm: cannot remove `LATEST/toolkit/include/EnergyWiseUtil.h': Permission denied
rm: cannot remove `LATEST/toolkit/include/platform_types.h': Permission denied
rm: cannot remove `LATEST/toolkit/lib/CiscoEnergyWiseApi.dll': Permission denied
rm: cannot remove `LATEST/toolkit/lib/CiscoEnergyWiseSdk.dll': Permission denied
rm: cannot remove `LATEST/toolkit/lib/libCiscoEnergyWiseApi.so.1.3': Permission denied
rm: cannot remove `LATEST/toolkit/lib/libCiscoEnergyWiseApi.so.1': Permission denied
rm: cannot remove `LATEST/toolkit/lib/libCiscoEnergyWiseApi.so': Permission denied
rm: cannot remove `LATEST/toolkit/lib/libCiscoEnergyWiseSdk.so.1.3': Permission denied
rm: cannot remove `LATEST/toolkit/lib/libCiscoEnergyWiseSdk.so.1': Permission denied
rm: cannot remove `LATEST/toolkit/lib/libCiscoEnergyWiseSdk.so': Permission denied

Author

Commented:
the permissions on those files look like

-r-xrwxr-x  1 colgray eng    132 Nov  1 16:00 RefAgent.sh

Author

Commented:
OHUPE's suggestion worked:


-r-xrwxr-x  1 colgray eng    132 Nov  1 16:00 RefAgent.sh

Author

Commented:
sorry the suggestion was to:

Assuming you are the coldgray user :
First type : chmod -R u+rw LATEST
and then : rm -rf LATEST
CERTIFIED EXPERT

Commented:
Yep, that would do it.  I had a feeling something inside the directory was causing it, but couldn't see it until you pasted that output - and yes, OHUPE's suggestion should do what you need.

Author

Commented:
xterm, so what is chmod -R u+rw LATEST really doing, blowing away all the permissions that were previously there?
CERTIFIED EXPERT
Commented:
The -R means recursive which goes down into every folder inside LATEST

the u part means only for the user part of the ownership of each file (aka dRWXrwxrwx, the capitalized part is the user's, the middle 3 letters are the groups, and the last 3 letters are for everybody)

and finally the rw, means read/write (the x is execute, but that is not needed for deletions)

So you're saying:
"For every file or folder inside LATEST, make USER permissions READ/WRITE" with that command.
it's making sure you've got the read and write permission on each dirs and files before trying to delete it.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.