Linux Standard Output

Standard Output With Linux

Linux uses three standard program communication streams; STDIN, STDOUT and STDERR. The three streams represent standard input, standard output and standard error. The tutorial will detail standard output.  

With Linux, you can create a new file with an editor, or, you can redirect output into a file.

 Nano Sample

1) Create the file with nano
root@vps [~]# nano myfile.txt
2) Write text
3) Save file
^O
4) Exit nano
^X

 Standard Output Method To Create a File

1) Use > to redirect output to a file called myfile.txt
root@vps [~]# echo "New text goes here" > myfile.txt

Furthermore, with output streams, you can run a Linux command and output the results into a file

Sample #1
1) 
root@vps [~]# echo $PATH > test2.txt
root@vps [~]# cat test2.txt
/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin

Sample #2
root@vps [~]# ls -lt > test3.txt
root@vps [~]# cat test3.txt
total 4576
drwxr-x--- 15 root root    4096 Dec 25 08:25 ./
-rw-r--r--  1 root root       0 Dec 25 08:25 test3.txt
-rw-r--r--  1 root root     157 Dec 25 08:23 test2.txt
  Adding Standard Output to a File
To add a new lines to a file,
1) Type the following commands.
root@vps [~]# echo "New line" >> test2.txt
root@vps [~]# cat test2.txt
/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin
New line
root@vps [~]#