07 Creating and Reading Files
- Creating Files with
touch
touch <filename>
creates an empty file.- Can create multiple files at once by listing filenames.
- Updates timestamps if the file already exists.
- Writing to Files with
echo
and>
echo "text" > file.txt
writes text to a file.- Overwrites existing content unless
>>
is used to append.
- Viewing File Contents
cat <filename>
displays the full file content.less <filename>
allows scrolling through content interactively.head <filename>
andtail <filename>
show the first or last lines of a file.
- Editing Files with
nano
nano <filename>
opens a simple text editor in the terminal.- Use
Ctrl + X
to exit,Y
to save changes, andN
to discard.
- Reading and Searching Inside Files
grep "word" <filename>
finds lines containing a specific word.grep -i "word" <filename>
makes the search case-insensitive.grep -r "word" <directory>
searches recursively in a directory.
Next in Playlist: 08 Editing with Nano or Vi