misal open log file cli (/var/log/motion/motion.log)
1. Using cat
The cat command is used to display the entire content of a file.
Note : If the file is large, this might flood your terminal with text.
2. Using less
The less command allows you to scroll through the file interactively, which is useful for large files.
- Use the arrow keys or Page Up/Page Down to navigate.
- Press
q to exit.
3. Using tail
The tail command shows the last few lines of the file, which is useful for monitoring recent activity.
To continuously monitor new entries in real-time, use the -f option:
- Press Ctrl + C to stop monitoring.
4. Using head
The head command displays the first few lines of the file.
5. Using grep to Filter Content
If you're looking for specific keywords or patterns in the log file, you can use grep.
For example, to find all lines containing the word "error":
To make the search case-insensitive, add the -i flag:
6. Using vim or nano for Editing
If you need to edit the file or view it with syntax highlighting, you can use text editors like vim or nano.
Using vim:
Using nano:
7. Checking Permissions
If you encounter a "Permission denied" error, you may need to use sudo to access the file, as log files often require elevated privileges.
For example:
Or:
Summary
- Use
cat for quick viewing of the entire file. - Use
less for interactive scrolling. - Use
tail for monitoring recent or live updates. - Use
grep for filtering specific content. - Use
vim or nano if you need to edit the file.
Let me know if you need further assistance!