how to remove same file in the dir and subs?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to remove same file in the dir and subs?
# 1  
Old 12-03-2006
how to remove same file in the dir and subs?

Hi all,

Let say I have abc.gif file in the dir:

A
A/Sub1
A/Sub2

This abc.gif file is located in each of the dir and its sub. I want to be able to remove it at once w/out going into each folder and remove it one at a time.

What is the command to do that? Thanks
# 2  
Old 12-03-2006
look into using 'find'
# 3  
Old 12-03-2006
I got:

removes all files named file.1

find . -name file.1 -exec rm '{}' ';'
# 4  
Old 12-04-2006
I do it as follows,

find /dir_name -name "kapil.txt" -exec rm -rf {} \;

Deletes "kapil.txt" from /dir_name and any sublevels of that directory tree.

Regards,

Kaps
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create file Dir and Sub Dir same time

Hi Guys , I want create files Dire and Sub Dire. as same time using variable. EX: x1="/hk/Pt/put/NC/R1.txt" x2="/hk/pt/Put/Ot/NC/RN.txt" And i want delete all after done with my script. Thanks (2 Replies)
Discussion started by: pareshkp
2 Replies

2. Solaris

remove a user without removing its home dir

HI all, I have wrongly given a wrong home directory to a user. This dir is very critical for my production environment(Can;t afford to lose it for a single minute) Now i want to delete that user, Whenever i try to delete user it tries to delete its home dir. Commnd i use: userdel ... (9 Replies)
Discussion started by: varunksharma87
9 Replies

3. UNIX for Dummies Questions & Answers

List directories, subs and files

Hi, I try to list all files in a folder, including all the subdirs (and their subdirs) and all files contained in each of these folders. I then print it to a simple txt file. I use ls -R -1 >test.txt This sort of does what I need, yet, the result is something like: It reasonably comes... (53 Replies)
Discussion started by: dakke
53 Replies

4. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

5. UNIX for Dummies Questions & Answers

Copying dir (and sub dir) file names from ftp server to txt file in diff server

Hey all, i want to copy only the file names from an ftp server (directory and all sub directory) to a text file in another server (non ftp), i.e. i want to recursively move through directories and copy only the names to a text file. any help is appreciated...thank you in advance (1 Reply)
Discussion started by: deking
1 Replies

6. Solaris

remove dir from inherit-pkg-dir

hi i configured zone and have 4 files /usr and /lib /platform /sbin from global zone and i want to exclude /usr/local from /usr any one has an idea ? (2 Replies)
Discussion started by: maxim42
2 Replies

7. Shell Programming and Scripting

Moving file(s) from dir to dir

Hi, I am fairly new to writing scripts. I am trying to write a script that moves either One or All of the files from one directory to another. I know how to make the actual command to do it, but i don't quite know how to add operators to it, ie -i or -a. I want -i to move one file from... (4 Replies)
Discussion started by: SirJoeh
4 Replies

8. Shell Programming and Scripting

copying a file from one dir to another dir

hi i have a script compareFiles() { find /tmp/Satya -type f | \ while read filename1 do echo "----------------------------------------$filename1" find /tmp/Satya -type f | \ while read filename2 do if diff $filename1 $filename2 then echo "Both files... (3 Replies)
Discussion started by: Satyak
3 Replies

9. UNIX for Dummies Questions & Answers

find and remove last week dir

hello all, I want to ask, how to find last week directory and then remove it.. I have a directory in path /home/backup/ and, inside backup dir, I have 6 dir : - 01_20080414 ( today date ) - 02_20080414 ( today date ) - 01_20080413 - 02_20080413 - 01_20080407 ( last week date ) -... (1 Reply)
Discussion started by: kunimi
1 Replies

10. UNIX for Dummies Questions & Answers

Using tar for current directory, but not subs

I know that I can type tar -cvf myfile.tar * to tar the current directory and all it's sub directories, but how do I tar ONLY the current directory and skip all the subdirectories? (3 Replies)
Discussion started by: beilstwh
3 Replies
Login or Register to Ask a Question