Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to check if any log files exist and if so move them to a different directory. The problem is that the filename is only diferenciated by the date (commonname_YYMMDD.log) and there may be a few months worth of logs.
I have tried the following:-
if [ -e commonname_*.log ] then
mv commonname_*.log logsBut get an error saying too many arguements. Any help would be greatly appreciated

When it tries to evaluate
if [ -e commonname_*.log ]
the Shell first expands the wildcard to produce a space-separated list of all the individual files. Since the -e expression only requires one filename, that's too many arguments. You need to prevent expansion either by escaping the * or enclosing in 'quotes':
if [ -e commonname_\*.log ]
or
if [ -e 'commonname_*.log' ]

Unfortunately neither of these seem to work.
I tried it with a directory as follows:-
NothisFile.txt
File_20090210.log
File_20090211.log
File_20090212.logI need to search the folder for existance of log files and if they exist then move them for safe storage.
Neither of the examples prove true and mine expands, as you said, so has too many arguements.

Sorry, I misled you. The if [ -e file ] statement doesn't accept wildcards. I can't think of a good way of testing if a file exists. There must be, so I hope someone who is more experienced at bash scripting will step in.

No, M2, Chris is using the right OS, Red Hat Enterprise Linux, great choice, it's just a pity Bash scripting doesn't give you the same expressive power as Windows bat scripting ;-)
(ducks for cover from flying projectile memory sticks)

![]() |
SETX DOS command issue
|
Help with Time maths
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |