Remove file and folders Script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove file and folders Script
# 1  
Old 07-25-2011
Remove file and folders Script

Hi
I am trying to modify a script that will remove files and folders under a set directory on my server.
I am using the following

Code:
find /home/test/HM/  -type d -exec rm -rf {} \; 2>/dev/null

This removes the files in the HM folder but it also removes the HM folder which i do not want to happen.

Any help appreciated

Treds

Last edited by radoulov; 07-25-2011 at 12:05 PM.. Reason: Tags fixed.
# 2  
Old 07-25-2011
Code:
rm -rf /home/test/HM/*

# 3  
Old 07-25-2011
HTML Code:
I am setting this in a cron to run nightly not from command line.
will adding the * after HM in the script i had work?

Treds
# 4  
Old 07-25-2011
I believe it should. This is the last field and it can't contains * as the cron symbol.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script for enter folders and join file

Hello everyone. I have a dlink cam that save recordings splitted for hours. Each hour folder contain a lot of small avi files. Repository has the following directories structure: \_20140101/ \_ 01 \_a.avi \_b.avi \_ 02 \_c.avi ... (3 Replies)
Discussion started by: setterx
3 Replies

2. OS X (Apple)

Remove leading spaces from file names and folders

Hi All, I have a vexing issue with leading spaces in file names. Basically, we're moving tons of data from our ancient afp file share to Box.com and Box forbids leading spaces in files or folders. The HFS file system seems to be perfectly fine with this, but almost all other Unix file systems... (1 Reply)
Discussion started by: prometheon123
1 Replies

3. Shell Programming and Scripting

zipping files then remove the folders

Hi, i am using the below script to zip the files with respect to their timestamp of the files.It is working fine. For example lets take I have two files in this directory /path/folder1 with the timestamp as this month and previous month. When i run this script first time it is creating two... (7 Replies)
Discussion started by: velava
7 Replies

4. Shell Programming and Scripting

Script to remove folders by date created

Hi All I require to generate a script that deletes folders and sub directoires from a set period after creation. So have folder X on a daily basis i have job folders being created folder name 1234568. What i need to do is keep this folder pruned. So say 7 days after creation of the job folder its... (4 Replies)
Discussion started by: treds
4 Replies

5. Shell Programming and Scripting

Remove all folders within another folder except the lastest 1, 2 or 3.

I am using this command to remove all files and folders older than 24 hours; find /databackup/dbs/* -maxdepth 0 -type d -mtime +0 -exec rm -rf {} \; However, if/when backups to this folder fail and are not updated, it will completely destroy any backups we have in that folder. What can I add... (14 Replies)
Discussion started by: damang111
14 Replies

6. Shell Programming and Scripting

how to remove inner files without removing child folders

Hi, I want to write a command to remove all the files from a folder and inner child folder without removing the child folders of parent folder. like I have folder like this... Code: folder a/b/c file a/test.sql file a/b/test2.txt file a/b/c/temp.jpeg now I want to remove... (5 Replies)
Discussion started by: mkashif
5 Replies

7. Red Hat

how to remove inner files without removing child folders

Hi, I want to write a command to remove all the files from a folder and inner child folder without removing the child folders of parent folder. like I have folder like this... folder a/b/c file a/test.sql file a/b/test2.txt file a/b/c/temp.jpeg now I want to remove all... (2 Replies)
Discussion started by: mkashif
2 Replies

8. Shell Programming and Scripting

Shell script to check if any file exists in 4 folders

Hi All, working on AIX 5.3. Requirement is: Shell script in ksh to check if any file exists in 4 folders as below: 1. /FILE/INB/INT1 2. /FILE/INB/INT2 3. /FILE/INB/INT3 4. /FILE/INB/INT4 Thanks a lot for your time! a1_win. (3 Replies)
Discussion started by: a1_win
3 Replies

9. UNIX for Dummies Questions & Answers

how can i remove files with extension in many folders

hello i have 2 question if i have 1 folder and under this folder many many sub folders and in every folders many files with man extension like *php * jpg * gif i need to remove all *php files 1- from tha main folder only 2- from tha main folder and all sub folders the second how... (6 Replies)
Discussion started by: ateya
6 Replies

10. Shell Programming and Scripting

Script To dlete PDF file s and Folders

Hi We have to delete PDF files and Folders older than five days .Can anyone help with the shell script Regards Ved (10 Replies)
Discussion started by: ved123
10 Replies
Login or Register to Ask a Question