DevOps Tutorial · Linux and the Shell · Lesson 4 of 25
Linux Files and Directories
Navigate and manage the Linux file system from the shell: paths, directories, files and finding things.
Why Linux?
Almost every server, container and CI runner runs Linux. You'll use its shell to debug containers, write pipeline steps and automate tasks.
Essential commands
| Command | Does |
|---|---|
pwd |
print the current directory |
ls -la |
list files, including hidden ones, with details |
cd path |
change directory (cd .. up, cd ~ home, cd - back) |
mkdir -p a/b/c |
create directories, including parents |
cp, mv, rm |
copy, move/rename, delete (rm -r for directories; there is no undo) |
cat, less, head, tail -f |
show files; tail -f follows a growing log |
find . -name "*.log" |
find files by name, size, age |
du -sh *, df -h |
disk usage of directories; free space per file system |
mkdir -p app/config app/logs
echo "port=8080" > app/config/app.conf
echo "started" > app/logs/app.log
echo "request ok" >> app/logs/app.log # >> appends, > overwrites
find app -type f | sort
echo "---"
cat app/logs/app.log
Output
app/config/app.conf app/logs/app.log --- started request ok
Run this on your computer — see “Get Started” for setup.
Important directories
/etc configuration, /var/log logs, /var/lib application data (Docker keeps images in
/var/lib/docker), /tmp temporary files, /home users' files, /usr/bin programs, /proc live information
about processes and the kernel.
mkdir logs
for i in 1 2 3; do head -c $((i * 40000)) /dev/zero > "logs/app.$i.log"; done
du -k logs/* | sort -n
echo "largest:"
find logs -type f -size +60k | sort
Output
40 logs/app.1.log 80 logs/app.2.log 120 logs/app.3.log largest: logs/app.2.log logs/app.3.log
Run this on your computer — see “Get Started” for setup.
Test yourself
Which command follows a log file as new lines are written?
cat app.logtail -f app.logless -n app.logfind app.log
Show answer
Answer: tail -f app.log
tail -f keeps the file open and prints new lines as they arrive.