Solved

Using Terminal to Delete Contents of User's Docs Folder

Posted on 2004-08-06
4
426 Views
Last Modified: 2010-04-14
I need to use terminal a UNIX command to delete the contents of a directory, but need to do it recursively through a parent directory...

I have done this with a specific document in the past, using...

find [path] -name "[nameofdocument]" -delete
(find /Users -name "afpDelete*" -delete)... is specifically what I used

This time, however, I want to delete the contents of a directory.
Specifically, I want to go through the Users folder (/Users/) and find the Documents (/Users/[user]/Documents/] folder for each user and delete the contents of their documents folder.

Any ideas? Can't really find what I need in man pages.  Oh, by the way, I am using bash.

Thanks in advance for any input!
0
Comment
Question by:nonesuch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 30

Expert Comment

by:weed
ID: 11737091
Do you need to delete every users docs at once, or one user at a time?
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 250 total points
ID: 11737576
Try:

for f in `/bin/ls -1dp /Users/* | grep '/$'` ; do rm -rf "${f}Documents/*"; done;

But why would you want to delete all your users' data from just a single directory?
Normally I would not ask such things, however this has a high potential for malicious
use.  I can imagine a case for removing all the data for a single user or even all the
data for all users, but deleting the contents of only the Documents folder for all users
seems ... odd.

0
 
LVL 3

Author Comment

by:nonesuch
ID: 11738508
This is for users who need a "fresh" Documents folder once a year.  They are students and get an archive of their Documents  on CD at the end of the school year.  The following Fall, they need an "empty" Docs folder in order to work more efficiently.  If there are documents that they want from the previous year, they can either get them from their CD or they can login to our archive server and pull stuff in.  This was supposed to happen on a student by student basis in their final visit to the lab, however, the lab instructor forgot and that put us in our current position.  School starts next week... we are in a bind to get this done and my terminal skills aren't all that smooth.

Thanks for the input, I will give this a test try via echo.  Rest assured that this won't be used maliciously.

Also, as I ponder your rather elegant solution, I am certain that there would also be a way to pass a list of short names (in other words, a list of home folder names) and have it only "do" this to those folders.  Any ideas?
0
 

Expert Comment

by:mrblackhat
ID: 11813630
rm -rf /username

From the documents folder.  That will remove 'rm' files -recursively 'r' -without prompting you 'f'.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create a default user profile for Mac OS X 10.7/10.8 Create a user account on OS X that will be a template for every other user of that computer. I usually call it “profile” and make it an administrator account for the time being. 1. Install a…
A lot of new and distinct gadgets are making their appearance every other day. The latest gadget that has wooed the attention of all gadget lovers and non gadget lovers alike is the Smartwatch. This tiny gadget is capable of offering live access to …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question