Recursion list for rm -R in find


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Recursion list for rm -R in find
# 1  
Old 06-27-2013
Recursion list for rm -R in find

In the following command:
Code:
find / -ctime +3 -exec rm -R {}\;

how is the recursion list built for the actual rm ?

F'rinstance; I had a case where a user typed this as root using '/' instead of '.' so everything in the root level was going to be traversed. They hit <ctrl>C before too much was deleted but this leaves me with the task of figuring out what was deleted. The only files I am positive that were removed were from /opt and I haven't found anything missing from /bin

So, how does the kernel decide what directories get hit first since it doesn't appear to be alphabetical?
# 2  
Old 06-27-2013
Quote:
Originally Posted by port43

F'rinstance; I had a case where a user typed this as root using '/' instead of '.'

. . .

So, how does the kernel decide what directories get hit first since it doesn't appear to be alphabetical?
Oh boy. That F'rinstance caught me off guard. Smilie Reminds me of the public service announcement that shows at root's log in in SUSE.

I don't have an answer for you, but I've always been curious. I've thought it was alphabetical before . . . but always get frustrated when batch file operations never finish at Z. I thought I noticed "find" going roughly alphabetical along equal directory depths (I know it focuses on lower depths first), starting with lower-case and then upper - but I know it's not that entirely either - I really don't know. It has to be completely predictable though whether it's defined explicitly in the code or not . . . I'd love to see someone shed some light on it.
# 3  
Old 06-27-2013
find finds things in arbitrary order, just the order they're stored in the directory entries on disk -- which is completely arbitrary. It's very difficult to say where this command started.

Last edited by Corona688; 06-27-2013 at 07:23 PM..
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 06-27-2013
I'm not sure what functions the rm command uses but I used to use readdir() and remove() in my old C programming days I had to start with an array or linked list and I usually started it with a bubble sort, which meant alphabetically. I was hoping to catch someone who might have some insight on how rm is coded. Then again, it's probably different depending on the OS. BTW, this issue is with AIX.

Last edited by port43; 06-27-2013 at 09:32 PM..
# 5  
Old 06-27-2013
As Corona688 already said, the order in which rm processes files found in a directory is unspecified. All implementations of rm that I've seen will process them in the order that you would see if you used the command:
Code:
ls -f

for each of the operands that find passes to rm. I suppose some implementation of rm could waste time sorting its operands, but most UNIX systems don't want reduce performance by performing unneeded functions before calling a function equivalent to unlink() or rmdir() depending on the type of the file being removed.

But, the important thing (if you don't want to destroy your system) is to kill any command that tries to recursively remove files from root as soon as possible!
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 06-27-2013
Thanks Corona688 and Don Cragun. I never thought about the wasted resources of processing files in a specific order. Smilie

Makes sense though since we should be accountable for our own use of rm without prompting. I too have been caught in the, "Oh crap!" <ctrl>C myself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

2. Shell Programming and Scripting

script recursion

Can someone please explain me why the following script calls it self recursively: #!/bin/bash echo Called $0 while this not: #!/bin/bash echo Called $($0) Thanks (6 Replies)
Discussion started by: superpointer
6 Replies

3. Programming

C Recursion (explain)

Hi, Question: how come the output is like that? Can explain to me abit. I am learning C. Thanks! #include <stdio.h> #include <string.h> void printit(char line_of_char, int index); int main() { char line_of_char; int index = -1; strcpy(line_of_char, "This is a string."); ... (5 Replies)
Discussion started by: seede
5 Replies

4. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

5. Programming

Recursion

I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language. (5 Replies)
Discussion started by: joshighanshyam
5 Replies

6. Shell Programming and Scripting

diffrence in non recusion and recursion

Hi, If i have given to write a prog for factorial in C using recursion and without recursion which one is better in what condition and why ? thanks (2 Replies)
Discussion started by: useless79
2 Replies

7. Shell Programming and Scripting

Help Help Help in recursion

Hello every body. I am trying to find the factorial using the following code. But it is giving the syntax error. I tried very much but in vain. Thanks in advance for helping me factorial() { if then y=`expr $1 - 1` x=$(( $1 \* factorial $y ))... (6 Replies)
Discussion started by: murtaza
6 Replies

8. Shell Programming and Scripting

recursion too deep

I am running a korn shell script which has a recursive function. The script ran for 117 iterations and ended up with the following error "recursion too deep". what should be done to avert this? Thanks in advance Swamy p.s. I am on UNIX MPRAS V4 (3 Replies)
Discussion started by: swamy455
3 Replies

9. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies

10. Shell Programming and Scripting

recursion

I'm using the UNIX csh and i wish to use recursion to nav my way up (or down as it is) a given folder. My little test script is called "r" and takes a folder as argv (or $1) #!/bin/tcsh -f set allFiles = `ls -A $argv` cd $argv while ($#allFiles) if (-d... (1 Reply)
Discussion started by: gsjf
1 Replies
Login or Register to Ask a Question