A guide to the Advanced tutorial: viewing parts of files with head, tail, and less, counting with wc, sorting with sort, visualizing structure with tree, and file metadata with chmod and stat.
This tutorial covers commands for inspecting files more precisely and working with file metadata. These show up constantly in real work: previewing logs, counting things, checking permissions.
Previewing files: head, tail, less
head -n 20 app.log # first 20 lines
tail -n 20 app.log # last 20 lines
less app.log # scrollable pager (q to quit)
head and tail are for quick peeks at the start or end of a file. less opens a file you can scroll through without dumping the whole thing to the screen, which matters for large logs.
tail is the go-to for logs because the newest entries are at the bottom. In real systems, tail -f follows a file as it grows.
Counting and sorting: wc, sort
wc -l names.txt # count lines
sort names.txt # sort lines alphabetically
wc counts lines, words, and characters; sort orders lines. These become powerful when combined with pipes, for example sort names.txt | wc -l.
Seeing structure: tree
tree # show the directory as a tree
tree draws the folder hierarchy visually, which is far easier to read than repeated ls calls when you want to understand a project's layout.
chmod +x script.sh # make a file executable
stat report.txt # show detailed metadata
chmod changes permissions (read, write, execute, and who they apply to). stat reports the full details of a single file, including precise timestamps.
Permissions are why a script "won't run" even though it exists. If you see a permission error, ls -l to check, then chmod +x to make it executable.