From the course: Learning Linux Shell Scripting
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Writing files - Linux Tutorial
From the course: Learning Linux Shell Scripting
Writing files
- [Instructor] The easiest way to write a file is to use redirection. Let's send the output of our reader script to a file. There are two similar ways to do this. From the command line type ./reader.sh, I'm gonna say names.txt and then we do a greater than sign and then the name of the file, output.txt and when we do that we don't see anything on the command line but if we show what's inside of output.txt, so we do cat output.txt, we can see the results of our saving the file. This method creates a file name output.txt. If it already exists, its contents are erased and our output is written to it. We could also do this which is ./reader/sh names.txt and this time we do two greater than symbols and output.txt. Note that there are two greater than signs. This is similar to the first command except it doesn't erase the contents of the output file. Instead, it adds the new text to the bottom of the file. If we show what's inside of this file, so we do cat output.txt, we can see that it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.