Find with rm command gives strange results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find with rm command gives strange results
# 1  
Old 07-06-2017
Find with rm command gives strange results

I want to remove any files that are older than 2 days from a directory. It deletes those files. Then it comes back with a message it is a directory. What am I doing wrong here?

Code:
+ find /mydir -mtime +2 -exec rm -f '{}' ';'
rm: /mydir is a directory


Last edited by Scrutinizer; 07-06-2017 at 03:48 PM.. Reason: code tags
# 2  
Old 07-06-2017
Quote:
The rm utility attempts to remove the non-directory type files specified on the command line
man rm
This is the default behaviour of rm..

You can add -type f to the find command so that it only finds files..

Last edited by Scrutinizer; 07-06-2017 at 03:59 PM..
# 3  
Old 07-07-2017
Do you tmpwatch available? That can help you tidy files away too.

You don't tell us your OS variant, so it may not be installed.


I hope that this helps,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Strange sort -r results

Hi Folks - I have this file that looks like this: outbox/logs/Client_1042.log outbox/logs/Client_941.log outbox/logs/Client_942.log outbox/logs/Client_943.log outbox/logs/Client_944.log And this is my code: #!/bin/bash _OUTBOX_BIN="outbox/logs/" _NAME="Client" _TEMP="temp.txt"... (9 Replies)
Discussion started by: SIMMS7400
9 Replies

2. Shell Programming and Scripting

Strange behavior of find and rm command

Hi I run the below command to find and delete *.xml files 90 or more days old. find . -type f -name '*.xml' -mtime +90 -exec rm {} \; find: stat() error ./Hello/2014_EMPTY.xml: No such file or directory ./Hello/2014_EMPTY_8011.xml: No such file or directory ..... .... If the file... (10 Replies)
Discussion started by: mohtashims
10 Replies

3. UNIX for Dummies Questions & Answers

Strange result using find command.

I created a file with the permissions of 776. When I ran the command find /root/Desktop -perm -644 -type f The created file shows up as part of the results. Doesn't -perm -mode mean that for global, only 4(read) and 2(write) can be accepted ? (2 Replies)
Discussion started by: Hijanoqu
2 Replies

4. Shell Programming and Scripting

ksh script find command not printing any results

Hello, Hitting a wall on this one. When at the command prompt it works fine: # find /home/testuser -name 'PAINT*canvasON.txt' /home/testuser/PAINT_canvasON.txt # pwd /home/testuser # ls -l PAINT*canvasON.txt -rw-r--r-- 1 root user 23 Feb 07 02:58 PAINT_canvasON.txt... (2 Replies)
Discussion started by: seekryts15
2 Replies

5. UNIX for Dummies Questions & Answers

Find command gave unexpected results

Hi, I recently executed a find command that caused unexpected permission changes and we had to do a full system restore. Can someone please explain what this command would do? find /staging/admin/scr * -exec chmod 755 '{}' + It caused file permissions inside / to be modified strangely. ... (1 Reply)
Discussion started by: poornima
1 Replies

6. Shell Programming and Scripting

Place 'find' results within TeX command

Hi, In an effort to collect all my .java-files and place them in a LaTeXfile (using the listings environment of latex), i tried to use ex. So what i have now is: find . -name "*\.java" > latex ex latex <<HERE %s/\(.*\)/\\lstinputlisting{\1} wq HERE So i try to escape the '\' with... (1 Reply)
Discussion started by: HannesBBR
1 Replies

7. UNIX for Dummies Questions & Answers

Strange Results

I am using th following to get the percentage and have never used bc before: percent=$(echo "scale=4;(34117/384000)*100" | bc) 8.884600 percent=$(echo "scale=2;(34117/384000)*100" | bc) 8.00 Why do I get the results of 8.00 instead of 8.88 when using a scale of 2. I only want 2 decimal... (2 Replies)
Discussion started by: mariaa33
2 Replies

8. Shell Programming and Scripting

edit results of a find command

Hi Purpose is to have a utility command to find and edit files . I tried a function like the following in my .profile file function vifind(){ find . -name $1 -print -exec vi {} \; } Is this correct? is there a better way to do it? I see this behaving a bit strange in case of AIX, and... (6 Replies)
Discussion started by: grep_whoami
6 Replies

9. Shell Programming and Scripting

Sending find command results to email

This is probably simple so forgive me... I just want to find all files in a folder created within the last 10 minutes... This is easy: # find /home/folder -cmin -10 If the find command locates any files created in the last ten minutes I want it to send an email alert. I just want to... (3 Replies)
Discussion started by: gardellap
3 Replies

10. AIX

Strange ls results..

Multipart question.. Can anybody explain why this happens : -rw-rw-r-- 1 fnsw fnusr 1531061 Feb 13 21:45 filename1.log -rw-rw-r-- 1 fnsw fnusr 1760706 Feb 10 22:10 filename2.log -rw-rw-r-- 1 fnsw fnusr 1525805 Aug 16 2005 filename3.log -rw-rw-r-- 1... (3 Replies)
Discussion started by: dbridle
3 Replies
Login or Register to Ask a Question