[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Using Terminal to Delete Contents of User's Docs Folder

Posted on 2004-08-06
4
Medium Priority
?
432 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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Even though Mac OS X has been around for many years now, certain well-liked and eminently useful software apps never made the jump from Mac OS 9 to Mac OS X. Ever used Word Perfect for Mac? Version 3.5 was the last version, built for Mac OS 9. Who c…
Set up iPhone and iPad email signatures to always send in high-quality HTML with this step-by step guide.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

656 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