![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| If statement not working | Hazmeister | Shell Programming and Scripting | 6 | 12-13-2007 04:33 AM |
| korn shell to bash - statement not working | brdholman | UNIX for Dummies Questions & Answers | 5 | 10-15-2007 09:49 AM |
| Find cmd not working as expected | Vishal123 | Shell Programming and Scripting | 6 | 08-29-2007 02:11 AM |
| how to find in which shell i am working.. | pineapple | Shell Programming and Scripting | 2 | 04-01-2007 10:56 PM |
| find command not working | jabrady | UNIX for Advanced & Expert Users | 7 | 10-04-2005 12:45 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi guys:
I am trying to delete multiple files in a folder with different names. Below is the script that I was trying, but it doesn't work ************************** #!/bin/ksh DATE=`date '+20%y%m%d'` DEL_DIR=<dir where files have to be deleted> let DATE2=$(($DATE - 2)) let DATE1=$(($DATE -1)) DELFILE_1=abc1.txt.$DATE1* DELFILE_2=abc1.txt.$DATE2* DELTAR=cdr.$DATE2.tar find $DEL_DIR -name $DELFILE_2 -exec rm -f '{}' \; find $DEL_DIR -name $DELTAR -exec rm -f '{}' \; ************************** The files I am looking to delete are: abc.<todays date minus 2>.tar ex: abc.20051212.tar abc1.txt.<date-2><some numbers> ex: abc1.txt.20051212010101 The error message I get is when I run the find command(s) : find: paths must precede expression Usage: find [path...] [expression] The find statement works when on the command line but not in the script. I also used the following command line which gave the same error message when run from the script but not on the command line find $DEL_DIR -name $DELFILE_2 |xargs rm -f I also tried using the If statement as shown below but it doesn't delete the files if [[ -a $DELFILE_2 ]]; then rm -f $DELFILE_2 fi fi [[ - a $DELTAR ]]; then rm -f $DELTAR fi The server is running redhat linux 4 Your help is appreciated. Thanks, -Gm Last edited by geomonap; 12-14-2005 at 05:49 PM.. |
|
||||
|
Actually the issue is not that find command is not working. I am able to run the find command successfully on the command line but not in the script. When I use it in the script, it gives me the following error message:
find: paths must precede expression Usage: find [path...] [expression] Also, the if statement doesnot work if I find multiple files with the following characteristics: abc1.txt.$DATE2* How can i successfully look for files "abc.txt.$DATE2* and delete them. On the command line I can use the find command and delete these files but the same command doesn't work in the script. -George |
|
|||||
|
geomonap, do stuff like:
echo DELFILE_2= $DELFILE_2 just before your find statement so you can see what is happening. And I doubt that you are running the same find command from your command line. Instead, you are probably replacing the variables with what you think they should contain. Your whole problem is probably garbage in your variables. |
|
||||
|
perderabo:
I ran the that entire part of the script on the command line, and I was successful. the actual files look like this: abc1.txt.2005121303000 abc1.txt.2005121303001 abc1.txt.2005121409001 abc1.txt.2005121503081 So I need to filter and delete all the files that have 20051213 in them which signifies that it is 2 days older. I don't want to delete them on the basis of the mtime cause the mtime can change. -George |
![]() |
| Bookmarks |
| Tags |
| linux, mtime |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|