how can i remove files with extension in many folders


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how can i remove files with extension in many folders
# 1  
Old 12-13-2008
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 can i set permission to all sub folders for 755 and all files to 644
# 2  
Old 12-13-2008
for each in `find server/ -name "*" -print`
do
if [ -f $each ]
then
#set all files to 644
chmod 644 $each
else
#set all directory to 755
chmod 755 $each
fi
done
## Regards Avinash.... A Real Angry Man
# 3  
Old 12-13-2008
really thanks

but what about the first half of my 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
# 4  
Old 12-14-2008
The answer given by avi.skynet will perfectly work fpr all the files with .php through the file system. If you want to specify to your directory and subdirectory only then give the directory path instead of "/" in the find command.

For answering your question no 1, you need to set -depth = 1 to find command. So it will list the files only in main directory not in subdirectory.
# 5  
Old 12-14-2008
Quote:
Originally Posted by siba.s.nayak
The answer given by avi.skynet will perfectly work fpr all the files with .php through the file system. If you want to specify to your directory and subdirectory only then give the directory path instead of "/" in the find command.

For answering your question no 1, you need to set -depth = 1 to find command. So it will list the files only in main directory not in subdirectory.

can you explain more please with an example
# 6  
Old 12-15-2008
Hi,
Keep everything same, just change the line "for each in `find server/ -name "*" -print`"
as followes

For only main directory
for each in `find . -maxdepth 1 -name "*.php"`

For directory and subdirectory,
for each in `find . -name "*.php"`
# 7  
Old 12-15-2008
after find i need to remove it
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash to remove find and remove specific extension

The bash below executes and does find all the .bam files in each R_2019 folder. However set -x shows that the .bam extension only gets removed from one .bam file in each folder (appears to be the last in each). Why is it not removing the extension from each (this is $SAMPLE)? Thank you :). set... (4 Replies)
Discussion started by: cmccabe
4 Replies

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

3. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

4. Shell Programming and Scripting

List files with *.i extension in a directory and all its subdirectories + 30days old then remove

I need to write a script to : list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
Discussion started by: lena keung
2 Replies

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

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

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

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

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

10. UNIX for Dummies Questions & Answers

string search in folders with particular multiple file extension

Hi, I am newbie in UNIX so please excuse for my questions. Is there a a way to search for string in files within folder and sub folder in particluar file extensions. Ex. search for ABC in folder 'A'(including it's sub folders) in html, xml files. Thanks, Ani (2 Replies)
Discussion started by: anikanch
2 Replies
Login or Register to Ask a Question