Help with delete cmd


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with delete cmd
# 1  
Old 07-31-2011
Help with delete cmd

Is there any command to know ,how many files are deleted when rm *. cmd was excuted.
I worte script which runs for 1 hours regularly and it is used to delete the .exe files but i need to know how many exe files are deleted regularly.

Please let me know the cmd

---------- Post updated at 05:56 AM ---------- Previous update was at 04:05 AM ----------

Is there any cmd to see how many files are deleted by excuting the cmd rm *
# 2  
Old 07-31-2011
not by executing rm *, but you can very easily count them, if you set up deleting from a loop:

Code:
cnt=0
for file in * ; do
  rm $file 
  $? && ((cnt++))
done

echo "$cnt files removed" >> log

Another solution would be running rm verbosely and capturing the output
Code:
rm -v * > log
cnt=`wc -l log`

The loop has an advantage of not being limited by number of files you are deleting -- every shell has a limit on how much of arguments it can take, so if you have tens of thousands of files and do 'rm *' it may complain about "Too many arguments".

Last edited by mirni; 07-31-2011 at 11:22 AM.. Reason: too many args
# 3  
Old 07-31-2011
Quote:
Originally Posted by mirni
Code:
rm -v * > log
cnt=`wc -l log`

Though, of course, you'll want to put the log in a different directory so it doesn't get swept up in the delete.
# 4  
Old 07-31-2011
Quote:
Originally Posted by KenJackson
Though, of course, you'll want to put the log in a different directory so it doesn't get swept up in the delete.
It won't. The asterisk will get expanded by shell before the command is run, when there is not logfile yet.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with cmd while using ps

Hi i am new to shell scripting and any help is really appreciated. my requirement is in, ps -e -o pid,uname,cmd how can i split and take only the cmd part from it. I tried awk but the issue is when the cmd is returning a lengthy command which itself has some spaces it is truncating the... (7 Replies)
Discussion started by: Jojo90
7 Replies

2. Linux

Env cmd

Hello, As a workaround for certain issue, I want to use SSH with a clean environment. I tried this: env -i ssh, but it returns: env -i ssh grep: ssh: No such file or directory As I'm a beginner, it would be great if you can suggest me, what is going wrong here. Thank you, (3 Replies)
Discussion started by: Joyb25
3 Replies

3. UNIX for Dummies Questions & Answers

Help with the find cmd

Hello, I'm having a trouble with the find cmd. I would like to find all the java versions on my systems. I have solaris 9 & 10 RHEL and SUSIE. java -version doesn't give all the versions on the server. So I am trying to use the find command to find them all find / -name java I would... (7 Replies)
Discussion started by: bitlord
7 Replies

4. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

5. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

6. UNIX for Dummies Questions & Answers

sed cmd

write the sed command for swapping the first and 2nd (fields)words in the following file input file cse1 rama 1223 cse2 raju 2453 cse3 sita 3523 i tried with this $sed 's/ \(*\)/ \(*\)/ \2,\1' myfile1 but not getting th required... (4 Replies)
Discussion started by: sankar_vitam
4 Replies

7. Shell Programming and Scripting

date cmd

Hi all, date +%d/%m/%Y This is the command that displays current date(18/09/2008). Now, is there a way that would give me yesterdays date..? or tomorrows date n things like that? (1 Reply)
Discussion started by: vijay_0209
1 Replies

8. UNIX for Dummies Questions & Answers

mv cmd

Hi All, How can I move only files to another destination using mv cmd in hp-ux. (2 Replies)
Discussion started by: mhbd
2 Replies

9. Programming

open cmd

if((LogFile=open(TempStr,O_CREAT|O_WRONLY|O_APPEND,0666))==-1) return(1); could someone explain me what the open() does here (2 Replies)
Discussion started by: bankpro
2 Replies

10. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question