Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    command to get certain line


    Hi guys.

    I want to do a scripting..

    # ls -l /tmp/MC* | wc -l
    ls: cannot access /tmp/MC*: No such file or directory
    0

    How do I get the line with 0? I need it for a condition.

    I tried to google around for sed or cut command but unfortunately I did not find any hint.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,837
    Use find instead of ls, as it wont throw an error in case nothing is found and you also can set much more accurate filters (e.g. -type f)
    e.g.
    Code:
    find /tmp -type f -name "MC*" | wc -l
    You must always face the curtain with a bow.

  3. #3
    Code:
    find /tmp -type f -name "MC*" | wc -l
    Great! thanks a lot.

  4. $spacer_open
    $spacer_close

Posting Permissions

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