Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

This creates a text file named pkg.list that contains the list you want. You
can open it with a text editor to confirm this. Then you can use this file as
input to dpkg, perhaps on another system on which you want exactly the
same software to be installed:


Click here to view code image
matthew@seymour:~$ sudo dpkg --set-selections < pkg.list


This tells dpkg to mark for installation any of the items in the list that are not
already installed on the second system. One more quick command (included
here for completeness of the example, even though it has nothing to do with
redirection), and these will be installed:


Click here to view code image
matthew@seymour:~$ sudo apt-get -u dselect-upgrade


Earlier in the chapter you saw an example of using cat to display several
files simultaneously. This example can be modified slightly to redirect the
output into a file, thereby making a new file that includes the contents of the
previous two, using the order in which they are listed:


Click here to view code image
matthew@seymour:~$ cat myfile.txt myotherfile.txt > combinedfile.txt


If you want to append information to the end of a text file, rather than replace
its contents, use two greater-than signs, like this:


Click here to view code image
matthew@seymour:~$ echo "This is a new line being added." >> file.txt


If you want to suppress the output that you do not want to keep from a
process, so that it does not get sent to standard output or saved, send it instead
to a special location called the Null Device, like this, where
verboseprocess is an example of a process that produces lots of output:


Click here to view code image
matthew@seymour:~$ verboseprocess > /dev/null


Add the power of redirection to the information in the next section, and you
will begin to understand the potential and the power that a command-line-
savvy user has and why so many who learn the command line absolutely love
it.


stdin, stdout, stderr, and Redirection


When a program runs, it automatically has three input/output streams opened

Free download pdf