when I run the following command in AIX (bash),
I get the following error.
Thats becasuse, its an empty directory. The same works, when there the directory is not empty. Even though the find deesnt have to rerun any result.
My full find command would look something like below.
I form the above find command during the script run time.
But for simplicity sake, I had given just the simple fine command in the example.
How to get it fixed?
Just give it the directory as an argument; not all of the files in the directory as separate arguments. I.e., change:
to:
and, you can get the same results with:
and, it will run a LOT faster if you use -exec command initial-args {} + to minimize the number of times you invoke rm:
These 2 Users Gave Thanks to Don Cragun For This Post:
The + collects arguments (up to a certain limit) and runs one (or few) rm -f arg1 arg2 ...,
while the ; each time runs the program with one argument rm -f arg1; rm -f arg2; ....
The + collects arguments (up to a certain limit) and runs one (or few) rm -f arg1 arg2 ...,
while the ; each time runs the program with one argument rm -f arg1; rm -f arg2; ....
This User Gave Thanks to deepakwins For This Post:
In a fastload teradata utility I am trying to delete the files which are older than 30days using the find and rm command as following.
find . -name 'xxx_*' -mtime +30 -exec rm -f {} \;
I expect it to delete all the files older than 30 days but sometimes it gives an error : find: bad status--... (3 Replies)
I have the following code in a script:
find . \( ! -name . -prune \) -name "cg*" -exec cp -p {} "${temp_dir}" \;
ret_stat=$?
I think the return status is only captured for the 'find' command and not for the 'cp' command. Is there a way to get the return status for the 'cp' command... (7 Replies)
Hello All,
I am trying to capture the exit status of find command and want to delete the files only when it is successful. But it is always returning me as success even if the pattern of that file doesn't exist in the current directory. please help, checked manual page but couldn't able to figure... (6 Replies)
My code to "Delete empty files from a directory entered in command promt"
#/bin/sh
echo "Enter directory"
read gh
for file in `ls $gh`
do
# to get the size of file
a=$( ls -l file | awk ' {print $7} ');
echo $a
if
then
echo "removing file "
rm file
fi
done (6 Replies)
I need to find empty files in a directory and write them into a text file. Directory will contain old files as well, i need to get the empty files for the last one hour only. (1 Reply)
Hi,
Want to log the output of command & check the exit status to find whether it succeeded or failed.
> ls abc
ls: abc: No such file or directory
> echo $?
1
> ls abc 2>&1 | tee log
ls: abc: No such file or directory
> echo $?
0
Tee commands changes my exit status to be always... (7 Replies)
Hi All,
I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both.
The value of $? is coming 0 in if part also and else part too.
#!/bin/ksh
if ]; then
echo "data"
# exit 0
echo "$?"
else... (4 Replies)
I am executing a find command in my script i.e
find $2 -type f -name '*.gif' -mtime +$1 -exec rm {} \;
how do i check that this command is executed properly.. i would lke t trap the errror and display my error message
kinly help.. this is an urgent issue. (1 Reply)
Hi,
I want to find the exit status of the last executed command in C Shell.
Tried $? but getting the error Variable syntax...$? does not seem to work in C shell..
is there any other command in C shell to find the exit status of last command?
Thanks in advance,
raju (1 Reply)