Solved

Using Terminal to Delete Contents of User's Docs Folder

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to set Mac OSX to open windows on left side 5 49
Two apple errors plaguing me 6 71
iOS vulnerability (9.3.5) 5 88
Apple and applications running in the background 5 31
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…
A common question or need, when setting-up a new Mac for someone would be to make all of the applications, installed, available from the dock. Many people often do not realize an application is installed unless it is in the dock. Creating a custo…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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