Bash - Write/Read Content of a new File

#!/bin/bash # Create new file touch somefile.txt # Write to file echo "This is new text" > somefile.txt # Read contents cat somefile.txt # Or for larger files `less` with `-F -X` will act like `cat` # Note: to exit `less` use `q` less -F -X somefile.txt # Or for reading the last few lines of file # Note: `tail -f` to continuously read contents of file tail somefile.txt

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.