Skip to main content
Ctrl+K

space cameras and glaciers

  • about me
  • teaching
    • EGM101: skills toolbox
      • lectures
      • practicals
        • computation, summary statistics, and graphing in excel
        • summarizing and graphing data in spss
        • correlation and regression in spss
        • hypothesis testing using spss
      • additional resources
    • EGM310: introduction to gis and remote sensing
      • lectures
      • additional resources
    • EGM702: photogrammetry and advanced image analysis
      • lectures
      • practicals
        • software setup
        • dem processing using micmac
        • dem differencing
        • introduction to google earth engine
        • change detection in earth engine
        • classification in earth engine
      • additional resources
    • EGM703: advanced active and passive remote sensing
      • lectures
      • practicals
        • urban heat islands
        • hyperspectral image analysis
        • SAR image processing
        • InSAR Processing
        • SAR image interpretation and flood mapping
      • additional resources
    • EGM722: programming for gis and remote sensing
      • setup
        • setting up github
        • installing git
        • installing github desktop
        • forking the repository
        • cloning the repository
        • setting up conda/anaconda
        • setting up a conda environment
        • configuring jupyter
        • pycharm
        • installing packages with pip
      • lectures
      • practicals
        • intro to python
        • debugging exercise
        • mapping with cartopy
        • conflict resolution (using git)
        • vector data using shapely and geopandas
        • interactive maps with folium
        • raster data using rasterio
        • searching + downloading satellite data using earthaccess
        • zonal statistics using rasterstats
        • more fun with geopandas
      • help! something went wrong!
        • git troubleshooting
        • python troubleshooting
      • programming project
        • creating a new github repository
        • environment.yml
        • EGM722: A how-to Guide
      • additional resources
    • unis glaciology (AG-325)
      • mapping glacier area change
      • dem differencing and geodetic mass balance
    • programming skills for phd researchers (using python)
      • setup
        • setting up github
        • installing git
        • installing github desktop
        • forking the repository
        • cloning the repository
        • setting up conda/anaconda
        • setting up a conda environment
        • configuring the jupyterlab terminal
        • pycharm
      • lectures
      • exercises
        • introduction to version control using git
        • starting a new project
        • introduction to python using jupyterlab
        • debugging code
        • plotting data using seaborn
        • working with pandas dataframes
        • basic statistical analysis using python
        • linear regression using python
      • additional resources
    • programming skills for phd researchers (using R)
      • setup
        • setting up github
        • installing git
        • installing github desktop
        • forking the repository
        • cloning the repository
        • setting up conda/anaconda
        • setting up a conda environment
        • configuring jupyterlab
      • lectures
      • exercises
        • introduction to version control using git
        • starting a new project
        • introduction to R using jupyterlab
        • debugging code
        • plotting data using ggplot2
        • transforming data
        • basic statistical analysis using R
        • linear regression using R
      • additional resources
    • a crash course in machine learning (using python) – under development
      • setup
      • lectures
      • exercises
        • what is machine learning?
        • training, testing, and validation
        • feature design and engineering
        • measuring model performance
      • additional resources
    • introduction to high performance computing
      • setup
      • the unix shell
        • in the beginning was the command line
        • navigating on the command line
        • working with files
        • input/output
        • shell scripts
      • high performance computing
        • atlas
        • transferring data
        • vulcan
      • additional resources
    • undergraduate dissertation projects
      • mapping glacier changes over time
      • detection of supraglacial lakes and timing of drainage
      • mapping harmful algal blooms using satellite remote sensing
      • flood detection and monitoring using remote sensing
      • detection and mapping of wildfires
      • urban heat islands
  • google earth engine
    • gee tutorials
      • getting started
        • adding and exporting images
        • spectral signatures
        • image collections and vectors
        • manual mapping (digitizing)
        • band maths
        • zonal statistics
      • image classification
        • unsupervised classification
        • pixel-based classification
        • object-based classification
      • change detection
        • visual analysis of changes
        • band maths and thresholding
        • repeat classification
        • change vector analysis
        • time series analysis
      • image enhancement
        • image filtering
        • pansharpening
        • edge detection
        • spectral unmixing
        • principle component analysis
      • advanced topics
        • creating an animation
    • sample exercises
  • ongoing and past research projects
    • deplete and retreat (DaR)
  • selected writing samples
    • source magazine (summer 2022)
  • github projects
  • Repository
  • Suggest edit
  • Open issue
  • .rst

navigating on the command line

Contents

  • the filesystem
  • where am i?
  • navigating the filesystem
  • pathnames
    • absolute pathnames
    • relative pathnames
  • creating a new directory
  • file and path names
  • notes

navigating on the command line#

Now that we’ve had chance to use the shell a bit, let’s see how we can use it to interact with, and navigate, the filesystem.

the filesystem#

We should probably start, however, by discussing what “the filesystem” actually means. In effect, it’s how the operating system stores and retrieves data. Most operating systems have a hierarchical directory structure - that is, the filesystem is organized like an upside-down tree, starting from a single “root” folder. On Unix-like systems, the root directory is /.

Most Unix-like filesystems have a top-level directory structure that looks something like this:

a diagram showing the top-level directory structure of a unix filesystem


The Windows filesystem is similar, but with one major difference: on Windows, different storage devices have their own “tree” (e.g., C:\, D:\, and so on). On Unix-like systems, there is a single “tree”, and each storage device is mounted (attached) to the tree at a different location.

where am i?#

When we are working in the shell, we are always in a single directory: the current working directory. To find out what that directory is, we can use the pwd (“print working directory”) command:

pwd
the output of the pwd command in the bash shell


In our filesystem tree diagram, we are here:

a tree diagram showing the location of bob's home folder


Most of the time, when you first log in or open a terminal, you will be in your home directory. On Linux systems, this directory is usually located here:

/home/<your username>

Every user account is given a home directory - very often, this is the only directory where “regular” (non-administrator) users are allowed to write files.

Note

In OSX, your home directory is usually located at /Users/<your username>. In Windows 10 and 11, it is located at C:\Users\<your username>.

navigating the filesystem#

To change the working directory in the shell, we use the cd (“change directory”) command, along with the pathname of the directory we want to move to. For example, to change from our home directory to Documents, we would type:

cd Documents

In our tree diagram, we are now here:

a tree diagram showing the location of the Documents folder


By itself (i.e., without including a pathname), cd will return us to our home directory. If you type the following:

cd

you should see that you are returned to your home directory (feel free to check this using pwd).

pathnames#

When working with pathnames, there are two ways that we can specify them: as absolute pathnames, or as relative pathnames.

absolute pathnames#

Absolute pathnames start with the root directory (remember, on Unix-like filesystems, this is /) and follow the tree through every branch until it reaches the specified file or directory. For example, the absolute path to my Documents folder is:

/home/bob/Documents

That is, we start at the root directory (/), then move to the home directory, then the directory corresponding to my username (bob), then the Documents directory.

Using an absolute pathname, then, we can navigate from the Documents directory back to our home directory by specifying the absolute pathname to our home directory:

cd /home/bob

relative pathnames#

Relative pathnames, on the other hand, start in the current working directory. This brings us to two important notations that are used to represent relative positions in the file tree: . and ...

In a relative pathname, . refers to the directory itself, and .. refers to the parent directory (the directory immediately above it in the hierarchy).

So, if we are in the Documents folder and we want to go back to our home folder using a relative pathname, we can do so by specifying the pathname to our home directory, relative to the Documents directory:

cd ..

As before, you should see that this has returned you to your home directory, which you can check using pwd.

creating a new directory#

Now that we know a bit more about how to navigate the filesystem from the command line, we can create a new directory, using the mkdir command.

Before you jump straight in, though, we’ll use the --help option to show information about how to use the command:

mkdir --help
the output of mkdir --help shown in the bash shell


Here, as before, we see that we have (optional) options - remember that the square brackets indicate that these are not required for the program to run. We also have a required input, DIRECTORY, indicated by the lack of square brackets. This makes sense, as we can’t exactly tell the computer to create a new directory without also telling it what to call the directory.

So, let’s use mkdir to create a new directory called “foo”:

mkdir foo

Now, use ls to list the contents of the current directory - you should see your new directory, foo, listed along with the previous contents:

the output of mkdir foo and ls, showing the new directory created

file and path names#

Before we move on to using the shell to work with files, we’ll focus on a few different rules for file and directory names.

  • To start with, filenames (like commands) are case sensitive - this means that Foo and foo are two different files/directories.

  • Filenames that begin with a period (.) are hidden - we will look at this more a bit later, but in practice this means that by default, ls will not actually list these files.

  • File extensions are typically not super-important on Unix-like systems: you can name files any way that you like, because the operating system has other ways of identifying the file type. That said, some applications may still use file extensions to identify/work with files, so it’s usually still a good idea to use them in practice.

  • File and directory names cannot include / - as we have seen, this character is used for delimiting directories in the filesystem, which means it can’t show up in the middle of a filename.

  • As a general rule, it’s a good idea to only use alphanumeric characters (letters and numbers), periods (.), dashes (-), and underscores (_) in file and directory names.

By far the most important rule for file and directory names in Unix-like systems, though, is this one1:

a meme of Edna Mode from the Incredibles, with the caption "no spaces!"


Remember: spaces are used as delimiters between parts of a command. For example, try the following command:

mkdir my new folder

You might think that this will create a new directory, “my new folder”, in the current working directory, right?

Not quite - we can see what actually happens using ls:

don't use spaces in file and directory names!


As you can see, this command has created three new directories: my, new, and folder. Because mkdir allows for multiple inputs, it sees each “word” in the directory name as a separate directory.

In the long run, it is safer and much less unpredictable to use underscores or dashes to represent spaces.

notes#

1

Strictly speaking, it is possible to use spaces in file and directory names. That said, it makes things far more difficult to manage, because you always have to be on the lookout for rogue spaces entering your commands unnoticed. As with capes, it is better to be safe than sorry.

previous

in the beginning was the command line

next

working with files

Contents
  • the filesystem
  • where am i?
  • navigating the filesystem
  • pathnames
    • absolute pathnames
    • relative pathnames
  • creating a new directory
  • file and path names
  • notes

By Bob McNabb

© Copyright 2025, Bob McNabb. Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0).