Moving Around the Filesystem
pwd, ls, cd, and paths
The first thing to master is knowing where you are and moving where you want. Everything else builds on this.
The three core commands
pwd # print working directory - where am I?
ls # list files in the current directory
ls -l # long listing: permissions, size, date
ls -la # also show hidden files (names starting with .)
cd reports # change into the reports directory
cd .. # go up one level
cd ~ # go to your home directory
cd - # go back to the previous directoryAbsolute versus relative paths
An absolute path starts from the root and always means the same place: /home/you/project/spm. A relative path is from where you are now: reports/timing.rpt means the reports folder inside the current directory. Knowing which you are using saves endless "file not found" confusion.
| Symbol | Means |
|---|---|
| / | The root of the whole filesystem |
| ~ | Your home directory |
| . | The current directory |
| .. | The parent (one level up) |
press Tab to auto-complete file and directory names as you type. It is faster and prevents typos. Press the Up arrow to recall previous commands. These two habits alone make you noticeably quicker in the shell.
Linux is case sensitive and spaces matter. Reports and reports are different directories, and a file named my file (with a space) must be written as "my file" or my\ file. Most tools and scripts avoid spaces in names for exactly this reason.