how to remove inner files without removing child folders

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat how to remove inner files without removing child folders
# 1  
Old 04-09-2010
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 all the files from folder a (test.sql, test2.txt and temp.jpeg) without removing folders b and c.


Thanks in advance.

Kashif.
# 2  
Old 04-09-2010
use the find command and check to make sure it is a normal file, then exec rm {}

Advanced techniques for using the UNIX find command
# 3  
Old 04-09-2010
Just to provide you command:

find /<your>/<directory> -type f -exec rm -f {} \;

Enjoy!

Regards,
-Artur.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Removing empty folders

Hello, I have a folder that contains all my music. Recently, I started using a different media player, and I let it manage my music folder. It has sorted all my music neatly in folders by artist and album. However, all the old folders that the songs used to be in are still there, yet they are... (2 Replies)
Discussion started by: emveedee
2 Replies

4. Shell Programming and Scripting

Some manipulations with files and folders. (loop, find, create and remove)

Hello! I need to realize such task. 1. In my user's home dir I have folder1; 2. In folder1 I have some (various count) subfolders with random names; 3. In these subfolders I have one file anyname.pdf (various name in each subfolder) and file content.txt (constant name in each subfolder) ##... (7 Replies)
Discussion started by: optik77
7 Replies

5. 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

6. 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

7. UNIX for Dummies Questions & Answers

copy all files and folders and cjange or remove ownership

So tried: cp -r -p test1/ user@machine:///srv/www/vhosts/domain.co.uk/httpdocs/backup/ but this didn't work either :( Anyone able to help with this? Many thanks Mr M (3 Replies)
Discussion started by: misterm
3 Replies

8. UNIX for Dummies Questions & Answers

Remove help removing to files

I have 2 files that cannot be remove with rm -f or rm. Can someone help with removing these files: -rwxrwxrwx 1 o571897c test 0 Dec 27 14:14 -type -rwxrwxrwx 1 o571897c test 0 Dec 27 14:15 -exec (3 Replies)
Discussion started by: wereyou
3 Replies

9. Shell Programming and Scripting

removing old files except configuration files and folders

Dear all, I want to remove files older than 2 months in the /home/member directory. But except the configuration files (like .bash_profile .config/ .openoffice/ .local/ .kde/ etc..) I have tried with the command find . -mtime +60 -wholename './.*' -prune -o -print -exec mv {} \; but it... (1 Reply)
Discussion started by: jamcalicut
1 Replies

10. UNIX for Dummies Questions & Answers

Removing old folders

All Please help me to remove old files. For example /usr/exp/ - inside this Apr 02 - dir02 Apr 03 - dir03 Apr 04 - dir04 Apr 05 - dir05 Apr 06 - dir06 Apr 07 - dir07 Apr 03 - file03 I want to delete all the folders 2 days before created.Not the fil03 even though it is 2 days old. ... (1 Reply)
Discussion started by: DeepakXavier
1 Replies
Login or Register to Ask a Question