The file system

The file system provides a structured way to name and organize files, typically using a hierarchical directory structure. Below there are some of the basic commands to move around.

Change Directory

Use cd to navigate between directories:

  • cd directory_name: Move into a specific directory
  • cd ..: Move up one directory level
  • cd ~: Go to home directory
TipLocation abbreviations
  • ~ tilde, your home folder (also $HOME)
  • . dot, your current working folder
  • .. dot dot, one folder up or back from here
  • - dash, the folder you were most recently in
  • / root, the folder containing the whole file system
  • if we type cd alone it will always take you back to your $HOME

List Directory Contents

The ls command lists files and directories in the current location. Common options include:

  • ls -a: List all files, including hidden ones
  • ls -l: Long listing with details like permissions and timestamps
us01234@myMacBook course-cli % ls                                     
README.md       answers         data            requirements.txt
_extensions     appendix        index.qmd       style.scss
_quarto.yml     assets          pages
us01234@myMacBook course-cli % ls -a                                    
.               .gitignore      appendix        requirements.txt
..              README.md       assets          style.scss
.DS_Store       _extensions     data
.git            _quarto.yml     index.qmd
.github         answers         pages

You can also use list filtering for specific file names or patterns.

us01234@myMacBook course-cli % ls -la *.txt
-rw-r--r--@ 1 gx18744  staff  15 26 Sep 02:06 requirements.txt                                   
TipSpecial characters
  • * wildcard (any characters): ls *.txt
  • ? wildcard (single character): ls file?.txt
  • [] character set wildcard: ls file[123].txt
  • {} brace expansion: echo {1..5}
NoteExercise

Create a handful of empty files with different names and cases:

touch File1.txt file2.txt File3.TXT file4.csv FILE5.txt notes.md

Now use wildcards to answer the following:

  1. List all files that end in .txt, regardless of case. (Hint: ls is case-sensitive by default — you may need to check each case separately, or use [Tt] inside a character set.)

  2. List only the files that start with an uppercase F.

  3. List only the files that start with a lowercase f.

  4. Using a single command with ?, list every file whose name is exactly fileN.txt, where N is one digit (e.g. file2.txt, file4.txt — but not File1.txt or File3.TXT).

  5. Using {} brace expansion, create two new empty files in one line: report_draft.md and report_final.md.