Folder permissions to delete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Folder permissions to delete
# 1  
Old 08-18-2011
Folder permissions to delete

I am using the below command to delete files from directories and subdirectories
Code:
find /test/abc/xyx -type f -mtime +7 -exec rm -f {} \;

there are some subfolders in xyx for which i don't have permission to delete.

Is there a way i can check the permission of the folder first and then delete the files.
Thanks in advance

Last edited by Franklin52; 08-19-2011 at 03:05 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 08-18-2011
find can't react differently depending on what folder it's inside. You could make a big complicated program to find writable directories and delete every file inside them, or just ignore the errors with 2> /dev/null.

There are lots of methods of finding things with certain permissions with find, but what functions you have depends on your system. What is your system? What is your shell?
# 3  
Old 08-18-2011
i am new to unix...trying to learn things...

system is linux and shell ksh by default..
# 4  
Old 08-18-2011
Just so that I am clear, are you trying to delete folders? I am asking because rm -f won't work on folders.
# 5  
Old 08-18-2011
If you have GNU find that makes things a lot simpler, it supports -maxdepth to prevent recursion.

Code:
# Find every writable directory inside /path/to/base
find /path/to/base -type d -writable |
while read DIR
do
        # Print all files inside writable directories.
        find "$DIR" -mindepth 1 -maxdepth 1 -type f

        # feed the list into xargs, which turns it into rm -f file1 file2 file3 ...
done | xargs echo rm -f

Remove the 'echo' from xargs once you've tested that it really does what you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

2. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

3. Ubuntu

Folder permissions

Hi Team, I want to set permissions to one folder in such a way that the user can write files or create folder inside that but should not able to delete it. Basically reason behind this is i am using Pidgin Messenger. There is a directory of logs in which, when user chat its store his logs.... (2 Replies)
Discussion started by: paragnehete
2 Replies

4. Red Hat

Need to compare two folder / FS permissions

Hi, Need to compare two folders / File systems permissions & time stamps including sub folders and files. Kindly let me know if any commands available. Regards :: VM (1 Reply)
Discussion started by: novaothers
1 Replies

5. UNIX for Dummies Questions & Answers

Permissions of the folder var/www

what should be the permissions of the folder var/www in my ubuntu ? I need it to be safe and at the same time I need ftp users to be able to edit it. I was wondering if I should create a group with all permissions and add ftp users to this group in unix. what's the standard way to do it ?... (4 Replies)
Discussion started by: aneuryzma
4 Replies

6. Shell Programming and Scripting

mkdir: copying a folder's permissions

Hi, I wanted to know how to create a folder using mkdir and then have it copy the permissions from another specified folder on the system. For example if I did this: mkdir /Volumes/USBSTICK/System How can I make it copy the permissions from the /System folder ? Thanks (4 Replies)
Discussion started by: pcwiz
4 Replies

7. Shell Programming and Scripting

delete all the files in folder a which exist in folder b

Hi , I need a script which basically deltes all files in folder a which are alreasy present in folder b say folder a has files abc.txt pqr .txt and b has abc.txt pqr.txt rmr.txt then file abc.txt and pqr.txt from a should be deleted (6 Replies)
Discussion started by: viv1
6 Replies

8. Shell Programming and Scripting

i want to write a script to test the folder permissions

Hi All, I want a script to test folder permissions.( to alert me if a folder /abc/xyz does not have 775 permissions). i want to test /abc/xyz is having 775 permissions or not if not it has to alert me. Please help me ASAP Thanks in advance (4 Replies)
Discussion started by: rajesh212512
4 Replies

9. Shell Programming and Scripting

How to generate nested folder permissions

Hi expert, I would like to know how to generate file and folder ( including nested subfolder and files) permissions under oracle directory ? (8 Replies)
Discussion started by: skully
8 Replies

10. Windows & DOS: Issues & Discussions

folder permissions

I work for a big company and all the people within my unit share a common drive to save documents to. I am listed in the group(AMS group) that has access rights to folders within this drive. but i'm trying to restrict access to a confidential folder so that only I can access it. when I set the... (0 Replies)
Discussion started by: shed
0 Replies
Login or Register to Ask a Question