2: Command Line Basics
October 25, 2023
Objective: The goal of this lab exercise is to familiarize yourself with the fundamental concepts and practical function of the command line interface. By the end of this exercise, you will be able to create, edit, filter, and delete files and folders using command line utilities.
Creating, Editing, Filtering, and Deleting Files and Folders
This lab exercise focuses on fundamental operations performed on files and folders through the command line interface.
You will learn how to do the following:
How to create directories
Navigate the file system
Create and edit files
Filter file contents based on search criteria
Delete files and folders
These skills form the basis of effective file management and manipulation, which enable geospatial professionals to efficiently organize, modify, and clean their data and software projects using the command line.
Creating and Navigating Directories
First, you will focus on creating and navigating directories using the command line interface.
Please open your Terminal application and follow along.
Change to your home
directory
home
directoryCreate a new directory called gisc605
and change into it
gisc605
and change into itNavigate back/up a directory level
Creating Files
Next, you will focus on creating and employing files using the command line interface.
Create an empty new file in `lab2`
Create a new file in `lab2` with some data in it
Listing Files and Directories
Before you learn about editing and filtering, let's cover how to display the contents of directories and files using the command line interface.
List contents of a directory
List contents of a file
Editing and Searching Files and Folders
Next, you will learn how to edit and filter files using the command line interface.
Edit a file with nano
Note: This will open the file in the nano text editor. You can also use this command to create a new file, i.e.
nano lab2/yetanothernewfile.txt
Make any desired changes to the file using the keyboard.
To save the changes and exit nano, press
Ctrl + O
(the letter "O," not zero). You'll be prompted to confirm the filename, so you can simply pressEnter
to save the changes.Finally, exit nano by pressing
Ctrl + X
.
Edit a file with vim
Once the file is open in Vim, you can navigate using the arrow keys or the
h
,j
,k
, andl
keys (vim's navigation keys). Move the cursor to the location where you want to make changes.To enter insert mode, press the
i
key. This allows you to make edits to the file.Make the necessary changes to the file.
Once you have finished editing, press the
Esc
key to exit insert mode and return to command mode.To save the changes and exit Vim, type
:wq
(write and quit) and press Enter. This command will save the changes made to the file and exit Vim.If you want to discard the changes and exit without saving, you can type
:q!
instead of:wq
. This will forcefully quit Vim without saving any changes.
Search a directory (and all its subdirectories) for a file
Note: Running this command will search for the file "newfile.txt" within the directory and display the path if it exists. If the file is present, you'll see the output similar to
/path/to/gisc605/lab2/newfile.txt
.
Search the current directory (and all its subdirectories) for a file
Search a file for specific content
Search all files in a directory for specific content
Search all subdirectories in a directory for specific content
Deleting Files and Folders
Delete a file
Delete a directory
Working with Files and Directories
Make a copy of a file
Move a file to a new directory
Move a file and rename a file
Make a copy of a directory
Move a directory
Installing packages
Install tree with apt
Run the tree tool in the current directory
Save the outputs of tree into a text file
Windows only
Open a WSL directory with Windows File Explorer
Deliverable
10 points total
Last updated