rm command issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers rm command issue
# 15  
Old 02-01-2012
Error

Quote:
Originally Posted by gary_w
Please see my edit above. And please just do a
Code:
-print

before doing the
Code:
rm

to make sure find is finding what you expect!
Not sure how does that help !!!

See my output of the command you shared.

Code:
bash> find /tmp/rsserver2/* -type d -print -o -type f -mtime +7 -print -exec rm -f {} \;
/tmp/rsserver2/rsserver4
bash> ls
rs.out          rs.out00001.gz  rsserver4
bash> find /tmp/rsserver2/* -type d -prune -o -type f -mtime +7 -print -exec rm -f {} \;
bash> find /tmp/rsserver2/* -type d -prune -o -type f -mtime +7 -print -exec rm -f {} \;
bash> cd /tmp/rsserver2/
bash> ls -ltr
total 587632
drwxr-xr-x   2 i392154  webgrp       316 Jan 31 10:51 rsserver4
-rw-r--r--   1 i392154  webgrp   286749123 Jan 31 12:21 rs.out
-rw-r--r--   1 i392154  webgrp   14105548 Jan 31 12:21 rs.out00001.gz
bash> cd rsserver4
bash> ls
rs.error        rs.out          rs.out00001.gz

Am I still failing something ? I wish we have some solution as this is command situation most of us face.
# 16  
Old 02-01-2012
Quote:
find /apps/server -type f -mtime +7 -exec rm -f {} \; &
Bit worried about the "&" here and the lack of a "-name \*\.txt" parameter. The "&" backgrounded the process. Perhaps you actually have umpteen attempts running in background? That might explain the "No such file or directory" errors you are seeing.
Code:
ps -ef|grep "find"|grep -v "grep"

One possible reason for chronic performance is if the directory file itself is ridiculously large. Sometimes after a serious clean-up you need to re-make the directory.
Deleting large numbers of files can be slow on mirrored disc systems and on old and slow computers.


Btw: This command from post #15 is terrifying:
Quote:
find /tmp/rsserver2/* -type d -print -o -type f -mtime +7 -print -exec rm -f {} \;
The first "-print" should probably have been "-prune". In post #15. listing the files in the subdirectory without the timestamps doesn't tell us much! It always helps to mention what you think is wrong.
How about:
Code:
ls -laR /tmp/rssserv2


Last edited by methyl; 02-01-2012 at 10:36 AM..
# 17  
Old 02-01-2012
Good points Methyl. There may have been some confusion regarding my comment to do a -print before doing a rm to make sure the find is finding what you expect before removing anything. And lets not background the process, to eliminate that being an issue. So to combine suggestions, do this to restrict to the top level directory then:
Code:
find /apps/server/* -type d -prune -o -type f -name "*.txt" -mtime +7 -print

Before doing this:
Code:
find /apps/server/* -type d -prune -o -type f -name "*.txt" -mtime +7 -exec rm -f {} \;

to verify what find is finding first.

Tip to save a process: instead of this:
Code:
ps -ef|grep "find"|grep -v "grep"

do this:
Code:
ps -ef|grep "[f]ind"

which matches the string but not itself.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with awk command

I am new to unix.I have a requirement to get few fields from the log file as below. Log app9/cc-gr_base.log.2017-07-19.gz: hostname 1500523166993 NA:NA:NA http-nio-8080-exec-56 INFO Points balance from MIS for user with userId: 19651069, first name: DEREK RICHARD and last name: BOUDREAU is... (3 Replies)
Discussion started by: nextStep
3 Replies

2. Shell Programming and Scripting

Command issue

I am on Linux LXLE. I been trying to change directories and opens folders and files. 1. I cd /home file 2. then user (/home/teak/) Then I try to open the Document file, wouldn't it be /home/teak/doument? . It responds not a directory. So how would I open the document file, or not... (3 Replies)
Discussion started by: teak
3 Replies

3. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

4. Shell Programming and Scripting

issue in mail command

I have used the mail command from the command line for sending mail from one machine to anther machine. Example: mail -s "Test" thillaselvan@xxx.co.in Testing But the mail is not getting received. I have checked the logs in the following file. tail -f /var/log/exim4/mainlog It is... (0 Replies)
Discussion started by: thillai_selvan
0 Replies

5. Shell Programming and Scripting

Issue with command tr.

Hi, I am using tr command like below: cat file_name | tr -c "" "" > output_file When i run my script from command mode, it is working fine. I scheduled my job in autosys. When the job runs at specified I am getting below Error: tr: when translating with complemented character... (5 Replies)
Discussion started by: Karteek
5 Replies

6. Shell Programming and Scripting

Issue with WC command

I am trying to show out the character count of a file if greater than 500 characters. When I do the -m its show the size of the file and not the characters in the file. Where am I getting confused? Or is -c and -m the same thing? Code is below if ; then echo "Char... (3 Replies)
Discussion started by: tvb2727
3 Replies

7. Shell Programming and Scripting

dd command issue

dd if=/dev/zero of=/var/images/abc.img bs=1M count=0 seek=2097152 dd: truncating at 2199023255552 bytes in output file `/var/images/abc.img': File too large The dd commad fails here saying its truncating if I try same command with less value for seek it works dd if=/dev/zero... (3 Replies)
Discussion started by: amol28kulkarni
3 Replies

8. UNIX for Dummies Questions & Answers

WC command Issue

Hello Guys... I am a newbie to Unix. I am having a requirement, Like in a file, I want to count the number of characters, I used wc -c and wc -m, But both are giving the byte count instead of character count. Please help me guys... Its very very urgent. Really appreciate ur help.. ... (5 Replies)
Discussion started by: mraghunandanan
5 Replies

9. UNIX for Dummies Questions & Answers

cp command issue.

All, I have files in directory,when i try to overwrite those files it gave operation not permitted error. I am using same group user (ina2) while overwritng this file. Sample file : -rw-rw-r-- 1 ina1 indev 316 Jun 06 13:44 ONCTEST.dat Error: cp: /proj/out/ONCTEST.dat: Operation... (4 Replies)
Discussion started by: sai_nj
4 Replies

10. HP-UX

Tar command issue

I made tar file having file names more character( up to 50). When i extract file in Linux it extracts fine.. but in HPUX all file name which are more than 24 are trimed to 24 characters. i m using "tar -xvf xx.tar" i read some O and N option for New posix and Old but didnt got. :confused: ... (2 Replies)
Discussion started by: ajayyadavmca
2 Replies
Login or Register to Ask a Question