Dualo
Bash / Shell Scripting

Shell basics — navigation & files

The core commands you use every day: moving around the filesystem, listing, reading, copying, and inspecting files.

1 min read

Four commands cover 80% of daily navigation: pwd (where am I?), cd (go somewhere), ls (what's here?), tree (what's in here, nested?). Your current directory is the starting point for every relative path you type.

cd foo enters foo. cd .. goes up one level. cd (no argument) jumps to your home directory. cd - bounces back to the previous directory — handy after a long cd into a deep tree.

File manipulation staples: cp src dst copies, mv src dst moves or renames, rm file deletes, mkdir dir creates a folder, touch file creates an empty file (or updates its timestamp). Add -r (recursive) to cp/rm when working on directories.

Reading files: cat file dumps it all, less file paginates (press q to quit, /term to search), head -n 20 shows the first 20 lines, tail -n 20 the last. tail -f logs follows a live log.

The rule of least surprise: rm has no trash. rm -rf / famously nukes the disk. Double-check arguments, especially with wildcards and sudo. Modern advice: alias rm to rm -i or use trash-cli for daily work.

Grounded on https://tldp.org/LDP/Bash-Beginners-Guide/html/

Next up

Pipes & redirections

Connect the output of one command to the input of another (`|`), or send it to a file (`>`, `>>`). The core composition tool of Unix.