Introduction
File operations are a cornerstone of Linux system management. Whether you’re creating, viewing, or searching for files, the tools available are both powerful and versatile. This article provides an overview of essential Linux commands such as touch
, cat
, less
, and find
, with practical examples to help you master reading the files.
touch
: Create Empty Files or Update Timestamp
The touch
command is often used to create empty files or update the timestamps of existing files. It’s a straightforward way to prepare files for editing or scripting.
Create an Empty File
This creates an empty file named example.txt
in the current directory.
touch example.txt
Update a File’s Timestamp
This updates the last modified timestamp of existing_file.txt
.
touch existing_file.txt
Create Multiple Files at Once
touch file1.txt file2.txt file3.txt
This creates three empty files in the current directory.
cat
: View File Contents
The cat
command is used to display the contents of a file, concatenate files, or even create simple files.
View a File’s Content
cat example.txt
Combine Multiple Files
cat file1.txt file2.txt > combined.txt
This merges file1.txt
and file2.txt
into a new file called combined.txt
.
Create a File With Content
cat > newfile.txt
Type the content, press Ctrl+D
to save.
less
: View Large Files
The less
command allows you to view large files one page at a time, making it ideal for files that exceed the terminal’s scrollback buffer.
View a File Page by Page
less largefile.log
Use the arrow keys to navigate.
Search for a Term Within the File
Press /
followed by the search term while inside less
, e.g., /error
.