[NTLUG:Discuss] How to get mv to not report when there are no files?

Leroy Tennison leroy_tennison at prodigy.net
Wed Nov 7 00:22:50 CST 2007


Fred James wrote:
> Neil Aggarwal wrote:
> 
>> Hello:
>>
>> I have a cron job with this command:
>> mv /home/johnc/* /var/www/html/incoming
>>
>> If there is a file in the /home/johnc directory, I get
>> no output, but when the directory is empty, I get this
>> notification to the root email account:
>>
>> mv: cannot stat `/home/johnc/*': No such file or directory
>>
>> This job runs every 5 minutes so this is annoying.
>>
>> Is there a way to supress that output?
>>
>> Thanks,
>> 	Neil
>>  
>>
> Neil Aggarwal
> 
> mv /home/johnc/* /var/www/html/incoming 2> /dev/null
> ... redirects the stderr to /dev/null (the special file that never contains anything no matter how much you put into it).
> 
> On my system that would man null, for more information
> Regards
> Fred James
> 
>  
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
> 
I was going to reply naively

if [ -f /home/johnc/* ]; then ...

but fortunately I tested before I did.  The best I could come up with 
quickly was

for i in /home/johnc/*; do if [ -f "$i" ] mv ...

which leads to the question "Is there no wildcard file existence test in 
bash?"



More information about the Discuss mailing list