Find the answer to your Linux question:
Results 1 to 6 of 6
I am in a test environment (of shell scripts - that's just something I had lying around) trying to clean out the contents of files. The overall reasoning behind this ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2006
    Posts
    43

    Exclamation ambiguous redirect issues


    I am in a test environment (of shell scripts - that's just something I had lying around) trying to clean out the contents of files. The overall reasoning behind this is:

    If I have an abundant amount of log files that are taking up large amounts of space; I do not want to delete the log files, I would only want to delete the contents of the log files.

    The command I ran was:

    Code:
     cat /dev/null > ./*
    That gave me an error ... So then I tried:

    Code:
    cat /dev/null > ./*.sh
    Same error:

    bash: ./*.sh: ambiguous redirect


    Anyone know why?
    Thanks.

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    its ambiguous redirect coz you are not redirecting to single file.





    casper
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Just Joined!
    Join Date
    Jan 2006
    Posts
    43
    Quote Originally Posted by devils_casper
    its ambiguous redirect coz you are not redirecting to single file.
    How could i remove the contents of all the files then? Not the files themselves .. but the contents. .. Any ideas?

  4. #4
    Just Joined!
    Join Date
    Jan 2006
    Posts
    43
    Alright - Figured it out.

    I have a little BASH script (if you could call it that). It's actually just one line of code - but it works. To clear out a directory of log files, WITHOUT deleting the actual log file - meaning just clear the contents of each log file run this line of code (presuming you are in the directory that the log files are in (./* - could actually be "/var/log/"):

    Code:
    for i in ./*; do >$i
    If the logs were in /var/log - run:

    Code:
    for i in /var/log/*; do >$i

    Thanks

  5. #5
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    ahaa ! i am glad you sorted out yourself...... i was going to post same 'loop' solution...





    casper
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  6. #6
    Just Joined!
    Join Date
    Jul 2010
    Posts
    1
    This would be quite faster to execute. It does break when you have too many files.

    : | tee *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •