I present to you a compilation of the most useful Linux commands for File Content Operations
Pipes and I/O Redirections
Redirect command output to a new file
Use the >
operator to send the output of a command to a new file.
command > output_file.txt
Append command output to an existing file
Use >>
to append the output to a file without overwriting it.
command >> output_file.txt
Redirect command input
Use <
to take input from a file instead of standard input.
command < input_file.txt
Redirect standard output and error output to a file
Use &>
to capture both types of output in a single file.
command &> output_file.txt
Pipe: direct output of one command as input to another
Use |
to connect two commands, where the output of the first becomes the input of the second.
command1 | command2
Show file content
Show content of a file
Use cat
to view the entire content of a file.
cat file
Show content of a file starting from the end
Use tac
to display the content in reverse order.
tac file
Scroll line by line through the file
Use more
to read the file in segments.
more file
Scroll forward or backward in the file
Use less
for more flexible navigation through the file’s content.
less file
Show the first two lines of a file
Use head
with the number of lines you want to display.
head -2 file
Show the last two lines of a file
Use tail
to see the last lines of a file.
tail -2 file
Show the last lines of a file in real-time (follow)
Use tail -f
to monitor changes in real-time.
tail -f file