Interview Q&A / Linux & Shell
Linux & Shell interview questions
Permissions, processes, pipes and the commands you are expected to know cold.
Prefer rapid revision? Practise Linux & Shell short interview answers →
- How do you watch a log file grow in real time?
Use tail -f file to print the last lines and keep following new lines as they are written. tail -F also survives log rotation by reopening the file when it is replaced, and Ctrl+C stops it.
BeginnerQuick answer1 min read - How does the mv command work for both renaming and moving files?
mv changes a file's name or location. Within the same file system it only updates the directory entry, so it is instant even for huge files; across file systems it copies the data and then deletes the original.
BeginnerQuick answer1 min read - What does rm -rf do, and how do you avoid deleting the wrong thing?
rm -rf removes files and directories recursively and without prompting, and there is no recycle bin. Avoid accidents by checking with ls first, quoting variables, never running it as root casually, and using rm -i or trash tools where possible.
BeginnerQuick answer1 min read - What does the touch command do besides creating empty files?
touch updates a file's access and modification timestamps to now, and creates the file if it does not exist. You can also set a specific time with -t or -d, or copy another file's time with -r.
BeginnerQuick answer1 min read - When should you use less instead of cat?
cat dumps the whole file to the terminal at once, which suits short files and pipelines. less opens a scrollable pager that loads lazily, lets you search with / and quit with q, so it is the right tool for large files.
BeginnerQuick answer1 min read