Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Two questions on find with rm command Post 302948146 by bakunin on Friday 26th of June 2015 06:53:53 AM
Old 06-26-2015
Quote:
Originally Posted by John K
When you use -exec rm -rf {} \; , the rm command is executed for each file (making it slower) .
and when you use -exec rm -rf {} + , the rm command is executed once in a while (although the frequency of rm execution is not mentioned in man page).
This is basically correct. Notice that you can delete several files at once because rm takes not a single file name but a file list as an argument. Suppose you have 4 files, "a", "b", "c" and "d" you could use:

Code:
rm -f a b c d

and have them deleted in one call of rm. This is why a call like
Code:
rm -f *

works: the shell will expand "*" to such a list of files prior to even call rm and it will happily take it.

On the other hand, command lines have a limited length and the aforementioned "*" might make the command fail once there are too many file names it expands to. Furthermore, every command can only take so many arguments. You may want to try this (in a non-destructive way): execute

Code:
ls *

in the directory with the 1.6 million files of yours you will perhaps see either a "command line too long" or a "too many arguments" error. The same would happen with rm for the same reason.

So this is why creating such a list by find and then feed it to a program (regardless of this program being rm or something else) is a bad idea. This is why the command xargs was developed and for the same reason there is the "+" device in find. Both these are designed to cut a big, unmanageable list into smaller pieces and feed these pieces to a program, one at a time.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

unix command questions?

I read the description of the less command and I'm puzzled that it says you can go backwards while using more(1). I created a large file and when I run the more command on it I can move forward with the spacebar and move backward with the letter 'b'. Granted, the less command has more command... (2 Replies)
Discussion started by: wmosley2
2 Replies

2. Shell Programming and Scripting

Dummy questions about how to get the size of a directory by command

Hi, 'ls -ld' is no use .... I want to get the total size of a directory including subdir. Any advice? Thanks in advance (2 Replies)
Discussion started by: GCTEII
2 Replies

3. UNIX for Dummies Questions & Answers

I have a questions about mail command

Any possibility to send a mail to internal mail using mail command? i am using fedora7. Example: username@192.168.1.1 (1 Reply)
Discussion started by: btech_raju
1 Replies

4. UNIX for Dummies Questions & Answers

Questions on GREP command

Hi, Is it possible to display a specific number of lines starting from a line having a particular text using grep command? e.g. I have a text file with the contents below: AAA BBB CCC DDD EEE FFF I want to display 3 lines starting with the line having "BBB" to get the result below:... (11 Replies)
Discussion started by: stevefox
11 Replies

5. UNIX for Dummies Questions & Answers

command questions

Hi, can anyone answer the following questions? 1.How do you check for particular exception in a growing log file? 2.How do you terminate a long running process? What if there are multiple instances running? Thanks James (1 Reply)
Discussion started by: james94538
1 Replies

6. UNIX for Dummies Questions & Answers

More find command questions

Last week I was helped in finding certain filenames and removing them using the following command and it worked fine. find /path/to/files -name 'WQ*' -type f -exec rm -f {} \; This week, I need to find certain characters within a certain file. For example, I need to find scripts that... (2 Replies)
Discussion started by: NycUnxer
2 Replies

7. Solaris

2 questions regarding the WGET command

I'm using the "wget" command to get the date from Yahoo.com. So this is what I use on Solaris: /usr/sfw/bin/wget --timeout=3 -S Yahoo! This works well when my computer is linked to the Net. But when it's not, this command just hangs. I thought putting the timemout = 3 will make this... (2 Replies)
Discussion started by: newbie09
2 Replies

8. Shell Programming and Scripting

Questions about the crypt command

hi all, My aim is to encrypt a file using 'crypt' command. Which is the package I need to install to get this command work? (because it says, crypt: command not found ) I'm working on a NetBSD 3.1 machine.. please help (1 Reply)
Discussion started by: renjumc
1 Replies

9. UNIX for Dummies Questions & Answers

find command, "basic" questions

find $HOME \ ( \( -name ´*.bak´ -ctime +20 \) -o \ \( -size 0 -user kurs00 \) \) -exec rm -i {} \; -print this is the syntax, i know what -name, -ctime and so on means, but i don't know what the -o or the \\ or the () or the {} mean. Can someone please explain? I searched the internet, I... (4 Replies)
Discussion started by: Dr. Nick
4 Replies
All times are GMT -4. The time now is 05:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy