Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would expect most people with much experience in Linux/Unix to do so routinely. I cannot imagine a day going by without using some kind of commandline redirection of standard IO. Its use is part of the fundamental style of Linux/Unix text-mode tools; a set of small tools each doing one thing well, and connecting to solve bigger real world problems.
do any of you use linux redirect commands for redirecting standard input , output, stanard error....and pipe commands?
Yes indeed. The more knowledge you have of using redirection and pipes, you can filter out results and extract any info you want and you can create custom commands. Linux is powerful.
Yes indeed. The more knowledge you have of using redirection and pipes, you can filter out results and extract any info you want and you can create custom commands. Linux is powerful.
okay,,,i just used the cat command to combine the text of 2 files in the home directory......trying to learn a few things, sometimes just does not sink in to my dense brain fast
ronss,
redirection can input the result of one command into the next command. That can be taken to the next command and so on. The output is normally sent to the screen but can be sent also to a file as well, with the tee command or just to file.
At a simple level it is useful to make a copy of the results of command enquiries,e.g.,
dmesg > file.txt
or you can get the results displayed by a program:
dmesg | less
that would make it easier to read but it is not recorded.
or,
you could do:
dmesg | tee dm1.text | less
This would make and copy to a file while sending to a program that displays the results on the screen in a way that more readable, see man less.
okay,,,i just used the cat command to combine the text of 2 files in the home directory......trying to learn a few things, sometimes just does not sink in to my dense brain fast
I was going to give you examples of doing this but the others did a good job of doing this.
However, there is another redirection that is important. It is the double right arrows. The double right arrows allows you to append data to an existing file. For example, if you did something like this
Code:
cat file1 file2 > newfile
Now, lets say you want to add data from file3 to newfile without erasing it. You do it like so
Code:
cat file3 >> newfile
Am example of using pipes to extract any info from a program's output
Here's an example of command line chaining that is taking the output of one command and piping it to another.
Code:
seq -w 1 39 | sort -R | head -5 |sort -n | fmt
02 09 30 34 37
This will produce 5 random numbers from 1 through 39
I hope this and the other members insight of pipes and redirection has help you. If you need more info just ask or google shell scripting pipes and redirection for additional tutorials.
Read the solutions to problems posted in these forums. A fairly high percentage of solutions to commandline-oriented problems will make some use of IO redirection by the shell.
Allow me to speak to the broader subject of standard input and output.
Understanding and making use of the concept of standard IO (and not just in commandline-based applications) is one thing that distinguishes a Windows-work-alike user from a Linux/Unix expert, IMHO. The concept is not complex or difficult, but is under-emphasized by most training material that I've seen. It is an elegant glue that binds together small pieces in order to make bigger systems.
In some cases, it simplifies the creation of more substantial framework systems. For instance, the xinetd daemon leverages the use of stdio by having all of it's sub-member components simply read standard input and write standard output. Because it connects to those sub-components through stdio, it becomes trivial for the writers of those components to gain network access, even though they don't know anything about the network machinery that is in use. Similarly for WWW CGI application writing. The web server just listens for the CGI's standard output data, and forwards it to the client browser. All of the networking is handled by the server, and the CGI application writer is free to focus on the application, knowing that the network machinery is being managed by the component most suited for the task.
Did you know that the concept has been present (in a limited form) on MS OS's since the very early days of MS-DOS?
thanks all .....will take a look at the threads, and do a bit command work..didn,t believe i would get this much response to my question..but thats cool..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.