Sponsored Content
Top Forums UNIX for Dummies Questions & Answers [SOLVED] Delete files and folders under given directory Post 302552387 by ramse8pc on Friday 2nd of September 2011 04:50:11 PM
Old 09-02-2011
[SOLVED] Delete files and folders under given directory

I have a requirement to delete the files and folders under a given directory.
my directory structure is like this..
HTML Code:
Data
|
A(Directory)
	|_PDF(Directory)----pdf files
	|_XML()Directory --xml files		
	|--files
|
B(Directory)
	|_PDF(Directory)----pdf files
	|_XML()Directory --xml files		
	|--files
|
C(Directory)
	|_PDF(Directory)----pdf files
	|_XML()Directory --xml files	
	|--files
	
|
n directories and sub directories
I need to delete the files and folders underneath A(Directory),B(Directory),C(Directory) ... N(Directory) and not the directories it self.
Directory should be there.Basically Data and underneath directories should remain. But all sub-directories should be empty.

i tried like this but it deletes all the directories and folders under given
directory
HTML Code:
find $folderPathTodelete -mindepth 1 -delete

Appreciate if anybody can help me with this.

Thanks
-Ramse

---------- Post updated at 04:50 PM ---------- Previous update was at 04:29 PM ----------

It's working when i changed mindepth to 2. :-)
Code:
find $folderPathTodelete -mindepth 2 -delete


Last edited by radoulov; 09-04-2011 at 11:03 AM.. Reason: Marked as solved.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

delete all folders/files and keep only the last 10 in a folder

Hi, I want to write a script that deletes all folders and keep the last 10 recent folders. I know the following: ls -ltr will sort the folders from old to recent. ls -ltr | awk '{print $9}' will list the folder names (with a blank line at the beginning) I want to get the 10th folder from... (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

2. Shell Programming and Scripting

delete files and folders older than 3 days

find /basedirectory -type f -mtime +3 >> /tmp/tempfile find /basedirectory -type d -mtime +3 >> /tmp/tempfile mailx -s "List of removed files and folders" myemail@domain.com < /tmp/te mpfile rm /tmp/tempfile find /basedirectory -type f -mtime +3 -exec rm {} \; find /basedirectory -type d... (7 Replies)
Discussion started by: melanie_pfefer
7 Replies

3. Shell Programming and Scripting

Compare files in two folders and delete missing ones

I do not know much about shell scripting so I am at a loss here. If someone can help me, that would be great! I have two directories /dir1 /dir2 I need to delete all files from /dir1 and that does not have a correspondent file in /dir2. It should NOT check file suffixes in /dir2 . Why?... (20 Replies)
Discussion started by: kaah
20 Replies

4. UNIX for Dummies Questions & Answers

Delete folders and files in it - UNIX

I need to delete a folder and files in it of yesterdays and simply put this in cron. Folder name - "2010-03-2010" File name - "eprod_06_23.dmp" and "eprod_06_23.exp" Actually this folder and file is been created by a script which takes a backup of DB everyday.Thats why it creates folder and file... (3 Replies)
Discussion started by: j_panky
3 Replies

5. Shell Programming and Scripting

delete folders with no mpgs or nuv files

I need some help writing a simple script that will delete all subfolders that contain no mpg or nuv files, if they have anything else or are empty the folder should be deleted I got this far but I'm pretty hopeless foo=0 if then foo=1 fi if then foo=1 fi if then echo found... (9 Replies)
Discussion started by: mrplow
9 Replies

6. Shell Programming and Scripting

Loop folders, delete files, copy new ones

Folks, I am hopeful that you may be able to help me out with writing a script that can be run nightly (as cron?) to loop through all subfolders within the "/media" directory, delete all of the files in each of them, and then copy in all of the files from the "/home//sansa" directory to each of... (6 Replies)
Discussion started by: acraig
6 Replies

7. Shell Programming and Scripting

Delete multiple folders in a directory which are two weeks old

I need help. I have to delete multiple directories inside a directory that are two weeks old. Example: Today is July 09, 2012 Folder1 > folder1 (created June 4, 2012) -- should be deleted > folder2 (created June 2, 2012) -- should be deleted > folder3 (created... (4 Replies)
Discussion started by: jasperux
4 Replies

8. Shell Programming and Scripting

Copy the files in directory and sub folders as it is to another directory.

How to copy files from one directory to another directory with the subfolders copied. If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*. I do not want to create sub folders in folder2. Can copy command create them automatically? I tried cp -a and cp -R but did... (4 Replies)
Discussion started by: santosh2626
4 Replies

9. Shell Programming and Scripting

Script to delete folders and files from a prompt

Hi Everyone, I work for GE Money IVR as a DB analyst and the environment on which I work is Solaris 5.0 server and Oracle 11g. I got a project in which I have to clean up the folders and files which are not used in DB. I copied an existing script and edited it, dont know this is the... (5 Replies)
Discussion started by: habeeb506
5 Replies

10. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

hi, i have a requirement to delete all the files from all the directories except some specific directories like archive and log. for example: there are following directories such as A B C D Archive E Log F which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Discussion started by: Little
7 Replies
cddrec(1)						      General Commands Manual							 cddrec(1)

NAME
cddrec - Read Directory Record from CD-ROM directory SYNOPSIS
/usr/bin/cddrec [-s number] [-b] file OPTIONS
Specifies the File Section for which the Directory Record is to be read. The numbering starts with one and can be any whole number. If this option is not used, the last file section of the named file is assumed. Copies the entire Directory Record from a CD-ROM in binary format to standard output. Names a file within the CD-ROM file hierarchy of a mounted CD-ROM File System. DESCRIPTION
The cddrec command reads the Directory Record associated with a file or directory on a mounted CD-ROM and lists its contents on standard output. The output is formatted in a table that contains the name of each field of the Directory Record and the corresponding contents of the entry as recorded on the CD-ROM. Note that the System Use field is not listed because it may contain non-printable characters. Users must have read permission for file in order to execute the command. EXIT STATUS
The following exit values are returned: The command was successful. The named file was not found, or was not within the CD-ROM hierarchy, or access permission was denied. The File Section indicated by file does not exist. SEE ALSO
Functions: cd_cdrec(3), cd_drec(3) cddrec(1)
All times are GMT -4. The time now is 04:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy