A A A
logo2




Redirections



Each process is assigned a standard input stream (STDIN) and standard output stream (STDOUT). Input stream is associated with wpisywanymi by the user, and output from the terminal screen. There is also an error stream (STDERR). Redyrekcja or otherwise redirect the stream. We have the following designations:

> - change to the standard output file
>> - Inserted into the file
< - change to the file standard entry
>!- redirect to a file regardless of whether there is
>&- Change stream error


Display the file to standard output stream can be recovered with cat.


owi@laptop:~$ cat /etc/passwd


Display the file to standard output stream can be recovered with cat.


owi@laptop:~$ cat /etc/passwd >


Using ">", you can redirect the standard output stream of the file. Just write a cat > file name , that information was later entered into the file transmitted.


owi@laptop:~$ cat > nazwapliku


Using ">", you can also combine two files. Just write a cat nazwapliku1 nazwapliku2 > nazwapliku3 to information from pliku1 and pliku2 have been combined into one file named file3.


owi@laptop:~$ cat nazwapliku1 nazwapliku2 > nazwapliku3


Mark ">>" to append to a file informacji. To add data to a file probably should write a cat >> filename [enter] ... data. This command may be useful to add more data without a lost past.


owi@laptop:~$ cat >> nazwapliku


Possible means of transmission is also a result of the program to a file. An example might be to date. This command displays the current date and time. To save the current date in the file, you can use redirection.


owi@laptop:~$ date > nazwapliku


Redirectons can connect with each other for example, the data in the program will be downloaded from the file dane1. A result of the program, which will be zpaisany to pliku1.


owi@laptop:~$ program < dane1 > plik1


You can also redirect the file to any device:


owi@laptop:~$ cat nazwapliku > /dev/audio






Pipes



Pipes are a way of communication between processes. This communication is a result of the transfer process at the entrance of one another. Unix pipes symbolizes the "|". If you want to view a file, and then Count how many there is a line. You can use the pipe:


owi@laptop:~$ cat nazwapliku1|wc -l

First, you see file1, and then counted lines. Thus pipes are nothing less than the function call chain. Of course, you can use more functions at once, eg:


owi@laptop:~$ who|sort|cut -f1 -d" "|uniq|wc -l

This example shows how to use a pipeline to view the number of logged users. First, information is displayed on the subscribers, then they are sorted alphabetically. The next step is to select only the removal of logins and repeated. Finally, it was just counting the line.




Autor: Aleksandra Przybyło
aleksandraprzybylo@gmail.com