Full-Access Members Only
Sorry, this lesson is only available to Server Academy Full-Access members. Become a Full-Access member now and get instant access to this and many more premium courses. Click the button below and get instant access now.
There are no resources for this lesson.
Reading File Contents
cat (Concatenate and Display)
cat command is used to display the contents of a file. It can be used to view the entire content of a file at once.
less (Pager Commands)
less are pager commands that allow you to view large files one screen at a time. They provide navigation options for reading through files.
more filename.txt less filename.txt
tail (View Start/End of Files)
tail are used to view the beginning and end of files, respectively. They are often used to display a portion of a file.
head -n 10 filename.txt # Display the first 10 lines tail -n 20 filename.txt # Display the last 20 lines
-f option will cause the tail command continuously displays the latest content of a file in real-time. It's particularly useful for monitoring log files as they receive new entries.
tail -f /var/log/syslog
Ctrl + C to exit the command.
grep (Search Text in Files)
grep command is used to search for specific text patterns in files. It is a powerful tool for text-based searching.
grep "pattern" filename.txt
Below is an example of searching the syslog file in /var/log for all events that happened at 14:17:
grep "14:17:" /var/log/syslog
In this lesson, you learned how to manipulate files on a Linux/Unix system, covering essential commands for creating, reading, and modifying files. We covered a lot of commands so this is a short recap of what we covered:
- cat: Display file contents.
- more and less: View large files with navigation.
- head and tail: View the start and end of files.
- grep: Search for patterns in a file or output
Great job getting through this lecture..I'll see you in the next one!
Server Academy Members Only
Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.