How to search all subdirectories?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to search all subdirectories?
# 1  
Old 05-13-2005
Question How to search all subdirectories?

Dear All,

I want to write the Unix command that searches through all subdirectories, finds the files named ''core'' and deletes them.

I will very much appreciate your help.

David
# 2  
Old 05-13-2005
What about

find /somedir -type f -name 'core' -exec rm {} \;
# 3  
Old 05-15-2005
But what happens when your chief exec has a legitimate file called "core" in his or her home directory that contains their core budget proposals for the year?

Far safer to do something like....
Code:
find /some/path/here -name "core" -type f -exec file {} \; | 
	awk -F: '/core file/ {print $1}' | xargs -t rm

You might need to change the awk depending on your OS

If you keep seeing a core file dumped in the same place time after time (and you can't fix the application thats generating itself directly), just
Code:
>/path/to/core
chmod 400 /path/to/core

This will truncate the core file to 0 bytes, and then make it read only - now when the core dumps, it won't be able to overwrite this file and the core file will remain at 0 bytes. Sloppy but it works...

Cheers
ZB
# 4  
Old 05-15-2005
Quote:
Originally Posted by zazzybob
But what happens when your chief exec has a legitimate file called "core" in his or her home directory that contains their core budget proposals for the year?
That's hilarious ...... though I guess this will not occur because they only use Windows, I think, and this doesn't work on Windows. Smilie

That's all for the joke.

I will not use this command myself, as I have disabled all core dumps on all machines I work on. I seldom use dangerous automatic commands like this but if I am to use one I will always confirm the list of files to be deleted with a

find /somedir -type f -name 'core'

first and verify the files listed before I will actually run that command, for safety sake.
# 5  
Old 05-15-2005
Quote:
Originally Posted by zazzybob
But what happens when your chief exec has a legitimate file called "core" in his or her home directory that contains their core budget proposals for the year?
For one thing, the chief exec had better not make an error that causes a coredump. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use ls or find for search of subdirectories?

(5 Replies)
Discussion started by: jhsinger
5 Replies

2. Shell Programming and Scripting

Search subdirectories and find and print total files

Hi All, I have a folder name lets say path/to/folder/CUSTOMER and under this i have several folders and each of these subfolder have serveral subfolders and so on and at some point i will have a folder name called "FTP_FILES" . I need to search for these folders named "FTP_FILES and then... (10 Replies)
Discussion started by: Kevin Tivoli
10 Replies

3. Shell Programming and Scripting

Find command to search files in a directory excluding subdirectories

Hi Forum, I am using the below command to find files older than x days in a directory excluding subdirectories. From the previous forums I got to know that prune command helps us not to descend in subdirectories. Though I am using it here, not getting the desired result. cd $dir... (8 Replies)
Discussion started by: jhilmil
8 Replies

4. UNIX for Dummies Questions & Answers

How to search & list subdirectories with the given file name

Question: How to search & list subdirectories with the given file name? For example: The directory structure looks like; /Builds/DEV/Build_RL01/DDL/ a_tbl_cre.sql ...... /Builds/DEV/Build_RL01/DML/ a_upd.sql .... .... Requirements: 1. I need to find subdirectory DML which is... (0 Replies)
Discussion started by: Siva SQL
0 Replies

5. Shell Programming and Scripting

diff different subdirectories

I have 2 directories a/ and b/, they have different subdirectories, how to diff with missing file, or missing subdirectory and if i have in a/ directory "a/ACD/DEF" DEF is a file, but in b/ directory "b/ACD/DEF is a SUBDIRECTORY, how to diff it, thanks my solution for directories, ... (7 Replies)
Discussion started by: knajta
7 Replies

6. Shell Programming and Scripting

search in all subdirectories for a file containing a certain string

Hello, how can I search a directory AND all its subdirectories for a file containing a certain string? My directories contain too many sql-files and I want to know whcih one of them write into the table "customer"? Can anyone help me? Thanks in advance (1 Reply)
Discussion started by: ABE2202
1 Replies

7. UNIX for Dummies Questions & Answers

search for files in subdirectories

Hi! I want to find files located in subdirectories. I have tried ls -R | grep myfile but this won't tell me where the file is, only that it is there. Any one have a better idea? Thanks, --Euclid (3 Replies)
Discussion started by: euclid3628800
3 Replies

8. Shell Programming and Scripting

search files in a directory and its subdirectories

Hello my friends, I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories? So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
Discussion started by: Net-Man
1 Replies

9. UNIX for Dummies Questions & Answers

looping through subdirectories

Hi, How to loop through all the subdirectories in a directory, merge the files present in it to a single file in that subdirectory itself and remove the original files? Please advise. (5 Replies)
Discussion started by: er_ashu
5 Replies
Login or Register to Ask a Question