Difference between revisions of "CLI I/O Redirection"
(class not currently offered) |
|||
(6 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | This class is not currently offered. [[User:Laurel|Laurel]] 21:40, 31 July 2010 (UTC) | ||
+ | |||
+ | == Introduction == | ||
+ | The Command Line Interface (CLI) provides three types of input/output (I/O) flow. | ||
+ | |||
+ | # stdin = "Standard In;" input passed to a command | ||
+ | # stdout = "Standard Out;" output from a command | ||
+ | # stderr = "Standard Error;" error output from a command | ||
+ | |||
+ | This means that there are two types of output from any command stdout and stderr. It also means that you can separate them. | ||
+ | |||
+ | == Commands == | ||
+ | |||
+ | == Abbreviations == | ||
+ | |||
+ | === stdio === | ||
+ | < = Send to | ||
+ | |||
+ | === stdout === | ||
+ | 1> = Redirect stdout, overwrite specified file | ||
+ | 1>> = Redirect stdout, append specified file | ||
+ | |||
+ | === stderr === | ||
+ | 2> = Redirect stderr, overwrite specified file | ||
+ | 2>> = Redirect stderr, append specified file | ||
+ | |||
+ | == Examples == | ||
+ | In this example the user is attempting to list the contents of two directories, '/' and '/dirdoesnotexist/'. The '/' directory is valid and the command will succeed to list its contents. The '/dirdoesnotexist/' directory does not exist, as its name implies, and the command will fail to list its contents. Notice in the output there is both the text for the success and the failure. | ||
+ | |||
+ | diskless241@gimpy:~$ ls / /dirdoesnotexist | ||
+ | ls: /dirdoesnotexist: No such file or directory | ||
+ | /: | ||
+ | bin cdrom etc initrd initrd.img.old lib64 media opt root selinux sys usr vmlinuz | ||
+ | boot dev home initrd.img lib lost+found mnt proc sbin srv tmp var vmlinuz.old | ||
+ | |||
+ | If we redirect the stdio to /dev/null we will no longer see it on the screen. We will be left with only the stderr on the console. | ||
+ | |||
+ | diskless241@gimpy:~$ ls / /dirdoesnotexist 1> /dev/null | ||
+ | ls: /dirdoesnotexist: No such file or directory | ||
+ | |||
+ | Inversely, if we redirect the stderr to /dev/null we will no longer see it on the screen. We will be left with only the stdio on the console. | ||
+ | |||
+ | diskless241@gimpy:~$ ls / /dirdoesnotexist 2> /dev/null | ||
+ | /: | ||
+ | bin cdrom etc initrd initrd.img.old lib64 media opt root selinux sys usr vmlinuz | ||
+ | boot dev home initrd.img lib lost+found mnt proc sbin srv tmp var vmlinuz.old | ||
+ | |||
+ | == Quiz == | ||
+ | |||
+ | == Instructor Notes == | ||
+ | This class needs some quiz questions. | ||
[[Category:CLI Quizes]] | [[Category:CLI Quizes]] | ||
[[Category:Classes]] | [[Category:Classes]] |
Latest revision as of 13:40, 31 July 2010
This class is not currently offered. Laurel 21:40, 31 July 2010 (UTC)
Introduction
The Command Line Interface (CLI) provides three types of input/output (I/O) flow.
- stdin = "Standard In;" input passed to a command
- stdout = "Standard Out;" output from a command
- stderr = "Standard Error;" error output from a command
This means that there are two types of output from any command stdout and stderr. It also means that you can separate them.
Commands
Abbreviations
stdio
< = Send to
stdout
1> = Redirect stdout, overwrite specified file 1>> = Redirect stdout, append specified file
stderr
2> = Redirect stderr, overwrite specified file 2>> = Redirect stderr, append specified file
Examples
In this example the user is attempting to list the contents of two directories, '/' and '/dirdoesnotexist/'. The '/' directory is valid and the command will succeed to list its contents. The '/dirdoesnotexist/' directory does not exist, as its name implies, and the command will fail to list its contents. Notice in the output there is both the text for the success and the failure.
diskless241@gimpy:~$ ls / /dirdoesnotexist ls: /dirdoesnotexist: No such file or directory /: bin cdrom etc initrd initrd.img.old lib64 media opt root selinux sys usr vmlinuz boot dev home initrd.img lib lost+found mnt proc sbin srv tmp var vmlinuz.old
If we redirect the stdio to /dev/null we will no longer see it on the screen. We will be left with only the stderr on the console.
diskless241@gimpy:~$ ls / /dirdoesnotexist 1> /dev/null ls: /dirdoesnotexist: No such file or directory
Inversely, if we redirect the stderr to /dev/null we will no longer see it on the screen. We will be left with only the stdio on the console.
diskless241@gimpy:~$ ls / /dirdoesnotexist 2> /dev/null /: bin cdrom etc initrd initrd.img.old lib64 media opt root selinux sys usr vmlinuz boot dev home initrd.img lib lost+found mnt proc sbin srv tmp var vmlinuz.old
Quiz
Instructor Notes
This class needs some quiz questions.