Solved

Using Terminal to Delete Contents of User's Docs Folder

Posted on 2004-08-06
4
412 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
iCloud Drive was introduced after iOS 8 was launched last year. This drive is Apple’s online storage device that lets users sync their files and access them from all their Apple devices.   There is a lot of data that is not automatically backed up…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now