1.3 Navigation and Inspection Commands
When learning Linux commands, do not chase flashiness first. The useful foundation is being able to quickly answer: where am I, what files exist, what is inside them, and what is happening?
Directory navigation
pwd
ls
ls -la
cd /path/to/dir
cd ..
cd ~ls -la is common: -l shows details, and -a shows hidden files. Hidden files usually start with ., such as .bashrc or .gitignore.
Viewing files
| Command | Best use |
|---|---|
cat file | Print a short file |
less file | Page through a long file |
head file | Read the first lines |
tail file | Read the last lines |
tail -f app.log | Follow new log output live |
wc -l file | Count lines |
file name | Detect file type |
For logs, tail -f is very common. It stays open and keeps refreshing, so press Ctrl+C to stop it.
Finding files and help
find . -name "*.log"
grep -R "ERROR" .
which python
man grep
grep --helpfind searches by path and filename; grep searches inside text; man and --help are the most reliable local manuals.
Practice terminal observation again
Use the lab below to repeat pwd, ls, cd, and cat. Notice which commands only inspect and which commands change the directory tree.
Command safety levels
- Green:
pwd,ls,cat,head,tail,grep; mostly inspection. - Yellow:
mkdir,touch,cp,mv; creates or moves content. - Red:
rm,chmod,chown,kill,sudo; can have strong effects.
When you see an unfamiliar command, ask: which level is it? What will it change? Is there a read-only way to inspect first?