Two questions on find with rm command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Two questions on find with rm command
# 8  
Old 06-26-2015
-delete should be even faster than -exec rm -f {} +
I suggest to first print
Code:
find /u01/product/11.2.0/rdbms/audit -name '*.aud' -mtime +20 -print

then print and delete
Code:
find /u01/product/11.2.0/rdbms/audit -name '*.aud' -mtime +20 -print -delete

--
Your assumptions are correct.
If you want to test how often a command is run then test with -exec echo {} +.
Code:
find / -xdev -exec echo {} + | tr -cd ' \n' | awk '{print NR". invocation with",length,"args"}'

You will find that it can run one echo with several hundred arguments. (Several thousands on most Unix OS.)

Last edited by MadeInGermany; 06-26-2015 at 12:49 PM.. Reason: test command added
This User Gave Thanks to MadeInGermany For This Post:
# 9  
Old 06-26-2015
Although it isn't in the standards, many mv utilities have a -v (verbose) option that will print the names of file being deleted as they are processed. So:
Code:
find /u01/product/11.2.0/rdbms/audit -name '*.aud' -mtime +20 -exec rm -fv {} +

will show you how quickly it is progressing. And, if you change that to:
Code:
cd /u01/product/11.2.0/rdbms/audit
find . -name '*.aud' -mtime +20 -exec rm -fv {} +

it will run a lot faster because with shorter pathnames, rm can be given more files to process on each invocation.

Even if you use -delete instead of -exec rm ..., it will run faster if you're in the directory you're processing since each unlink(pathname) call performed by find or rm won't have to search the root, u01, product, 11.2.0, and rdbms directories to find each file it wants to remove.
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 06-27-2015
Thank You MadinGermany, Don
# 11  
Old 06-27-2015
Quote:
Originally Posted by John K

I ran an ls command from within find using \; and + variants as shown below.
Both seems to return same results. If \; variant is slow , then why do people even use it ?
People use it if external utilities cannot accept multiple arguments or if they need to parse line by line in while / for loops.

Also, a good advice is to organize your files in directories.
Having millions of files in one directory will never be fast.

Hope that clears things out.
Regards
Peasant.
This User Gave Thanks to Peasant For This Post:
# 12  
Old 06-27-2015
There are also some commands where an argument must be specified after the argument that names a file. With \; you can place command args after the selected path:
Code:
find dir(s) primaries -exec cmd earlier args {} later args \;

but with +, the argument specifying the pathname(s) must be at the end:
Code:
find dir(s) primaries -exec cmd earlier args {} +

For example, the standard mv utility does not have a -t destination option. So on systems that don't have that extension, you can't use find directly to move multiple files to a single destination directory in a single invocation of mv. You have to move one file at a time:
Code:
find . -type f -name 'a*' -exec mv {} directoryA \;

or create an intermediary script to set the desitination directory appropriately:
Code:
find . -type f -name 'a*' -exec mv_back directoryA {} +

where the mv_backshell script is something like:
Code:
#!/bin/ksh
dest="$1"
shift
mv "$@" "$dest"

Are we having fun yet?
This User Gave Thanks to Don Cragun For This Post:
# 13  
Old 06-28-2015
If you fear that the long running find steals too much i/o bandwith then you can use ionice (works like nice but is focused on i/o)
Code:
ionice -c 2 -n 7 find ...

This User Gave Thanks to MadeInGermany For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

9. 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
Login or Register to Ask a Question