You are not logged in.

#1 2008-04-27 18:12:31

jonesy
Member
Registered: 2008-04-27
Posts: 2

linux redirection basic help?

Im trying to do a few task involving redirection of linux.  I am using fedora linux, it that matters.  These are the task that I am trying to accomplish:

1) redirect results of a command to a text file then also redirect to another command
2) redirect input from a text file to a command
3) append result of a command to a text file without destroying the contents
4) redirect error message of a command to a text file
5) suppress the error message from a command


I really appreciate any help I can get

Offline

#2 2008-04-27 18:23:50

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: linux redirection basic help?

(All of these are specific to bash.)

1)

$ /path/to/command | tee /path/to/file | /path/to/other/command

2)

$ /path/to/command < /path/to/input/file

3)

$ /path/to/command >> /path/to/output/file

4)

$ /path/to/command 2> /path/to/error/file

5)

$ /path/to/command 2> /dev/null

Note that ">" and "2>" can be combined on a single command.  You can also redirect both stdout and stderr using "@>".  You're probably best off reading the "REDIRECTION" part of the bash manpage.

Last edited by tam1138 (2008-04-27 18:25:51)

Offline

#3 2008-04-27 18:33:32

jonesy
Member
Registered: 2008-04-27
Posts: 2

Re: linux redirection basic help?

wow, this is really helpful, yea I will check man thanks. I think I might have mistyped number 1).  What I meant to say was redirect results of a command to a text file.  Then try to do that same function but redirect result to another command.  Im kinda new but I believe it would be this:

$ /path/to/command |  /path/to/other/command

^^^ code to redirect results of command to another command

this was going off what you posted, correct me if Im wrong

Offline

#4 2008-04-27 19:08:45

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: linux redirection basic help?

Ah.

Redirect command output to text file:

$ /path/to/command > /path/to/file

Redirect command output to another command's input (which is to say "you're right"):

$ /path/to/command | /path/to/other/command

Simultaneously redirect command output to file and to another command's input:

$ /path/to/command | tee /path/to/file | /path/to/other/command

Also, welcome to Arch!

Last edited by tam1138 (2008-04-27 19:09:36)

Offline

Board footer

Powered by FluxBB