Computing.Net > Forums > Programming > Detect & move Multiple files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Detect & move Multiple files

Reply to Message Icon

Name: chris.smith
Date: February 6, 2009 at 04:12:25 Pacific
OS: RHEL4
CPU/Ram: P4 2.8GHz
Product: Hewlett-packard / Dc7100u
Subcategory: General
Comment:

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 logs

But get an error saying too many arguements. Any help would be greatly appreciated



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: February 6, 2009 at 09:56:19 Pacific
Reply:

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' ]


0

Response Number 2
Name: chris.smith
Date: February 13, 2009 at 02:37:09 Pacific
Reply:

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.log

I 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.


0

Response Number 3
Name: klint
Date: February 13, 2009 at 15:15:45 Pacific
Reply:

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.


0

Response Number 4
Name: Mechanix2Go
Date: February 13, 2009 at 21:21:54 Pacific
Reply:

oops! wrong OS


0

Response Number 5
Name: klint
Date: February 16, 2009 at 02:49:27 Pacific
Reply:

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)


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

SETX DOS command issue Help with Time maths



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Detect & move Multiple files

C++ multiple files editing www.computing.net/answers/programming/c-multiple-files-editing/16526.html

Moving multiple files using batch www.computing.net/answers/programming/moving-multiple-files-using-batch/17447.html

Ren multiple files in DOS www.computing.net/answers/programming/ren-multiple-files-in-dos/19273.html