Results 1 to 5 of 5

Thread: file streams other than #1 (stdout) and #2 (stderr)

  1. #1
    Join Date
    Oct 2013
    Beans
    97
    Distro
    Ubuntu 12.04 Precise Pangolin

    file streams other than #1 (stdout) and #2 (stderr)

    Hello guys,

    Is it possible for a command to output data on filestreams other than #1 (stdout) and #2 (stderr)?

  2. #2
    Join Date
    Jan 2009
    Location
    Belgium (Ghent)
    Beans
    481
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: file streams other than #1 (stdout) and #2 (stderr)

    Look to the man-pages of command: tee
    Code:
    man tee
    For the compleet documentation use the command:
    Code:
    info coreutils 'tee invocation'
    example:
    Code:
    sudo apt-get update | tee update.log
    That command create a file with the name update.log and put there every output in that file.
    Last edited by heir4c; October 10th, 2013 at 03:15 PM.
    Dutch speaking; understand English, writing is a bit difficult. Member of: http://forum.ubuntu-nl.org
    be Open be Free be Ubuntu Reg. User #485479
    Ubuntu 13.10 Saucy Salamander - Ubuntu 14.04 Trusty Tahr

  3. #3
    Join Date
    Oct 2013
    Beans
    97
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: file streams other than #1 (stdout) and #2 (stderr)

    Thank you for your reply.

    If i understand correctly, tee simply takes the stdout #1 from the command that is pipelined into it, and outputs it again as stdout #1, but also copies it into a text file.

    But that does not completely answer my question. My question is, can a shell command output text on filestreams other than #1 and #2. So that you have something like this:

    Code:
    command 1> /dev/null 2> /dev/null
    or simply
    Code:
    command &> /dev/null
    but where text is still printed on your terminal.
    Last edited by sha1sum; October 10th, 2013 at 05:49 PM.

  4. #4
    Join Date
    Apr 2012
    Beans
    7,064

    Re: file streams other than #1 (stdout) and #2 (stderr)

    something like this maybe?

    Code:
    $ cat file
    stuff
    $ cat file >/dev/null
    $
    $ exec 3>&1                    # open file descriptor 3 and attach current 'value' of file descriptor 1 to it
    $ cat file >/dev/null >&3      # redirect output to file descriptor 3
    stuff
    $ 
    $ exec 3>&-                    # close file descriptor 3
    $ cat file >/dev/null >&3      # redirected output doesn't appear (stream is closed)
    -bash: 3: Bad file descriptor
    see http://www.tldp.org/LDP/abs/html/io-redirection.html

  5. #5
    Join Date
    Jan 2009
    Location
    Belgium (Ghent)
    Beans
    481
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: file streams other than #1 (stdout) and #2 (stderr)

    And if you use a double >> than you can add output at the end of a file that already have data inside.
    I don't know many about this, but I remember that of a little Linux-course I followed.
    Dutch speaking; understand English, writing is a bit difficult. Member of: http://forum.ubuntu-nl.org
    be Open be Free be Ubuntu Reg. User #485479
    Ubuntu 13.10 Saucy Salamander - Ubuntu 14.04 Trusty Tahr

Bookmarks

Posting Permissions

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