Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
CSCI 1302
CSCI 1302

Front Matter

  • Copyright
  • Dedications
  • Acknowledgments

Tools:

  • 1. The Unix Environment
    • 1.1. Introduction
    • 1.2. The Prompt
    • 1.3. Required Setup
    • 1.4. Terminals
    • 1.5. Logging In
    • 1.6. Summary of Commands
  • 2. Unix Commands
    • 2.1. Navigating the File System
    • 2.2. Time-saving Tips
    • 2.3. Getting Help
    • 2.4. Inspecting Files
    • 2.5. New Directories
    • 2.6. Moving and Removing
  • 3. The Emacs Text Editor
    • 3.1. Introduction
    • 3.2. Control and Meta
    • 3.3. Open / Create File
    • 3.4. Basic Commands
    • 3.5. Customize Emacs
    • 3.6. Built-in Emacs Tutorial
  • 4. Javadoc and API Documentation
    • 4.1. Introduction
    • 4.2. Getting Started
    • 4.3. Generating the API Documentation Website
    • 4.4. Hosting the API Documentation Website
    • 4.5. Troubleshooting Tips
    • 4.6. Writing Javadoc Comments
    • 4.7. FAQ
  • 5. UML
    • 5.1. Introduction to UML
    • 5.2. UML Class Diagrams
    • 5.3. UML Software and Tools
  • 6. Interpreter Scripts
    • 6.1. What is an Interpreter Script?
    • 6.2. Bash Scripts
  • 7. Maven
    • 7.1. Maven Introduction
    • 7.2. Creating a Project
    • 7.3. Updating the POM
    • 7.4. Using Maven

Java:

  • 1. Reference Variables
    • 1.1. Introduction
    • 1.2. Variables
    • 1.3. Reference Type Examples
    • 1.4. Reference Types and Assignment Values
  • 2. Packages
    • 2.1. Introduction
    • 2.2. Setting up the Environment
    • 2.3. Default Package
    • 2.4. Named Package
    • 2.5. Code Dependencies
    • 2.6. Further Important Notes
  • 3. Exceptions
    • 3.1. Introduction
    • 3.2. Exception Messages
    • 3.3. Avoiding Exceptions
    • 3.4. Handling Exceptions (Try-Catch)
    • 3.5. Regarding Scope
    • 3.6. Checked vs. Unchecked Exceptions
    • 3.7. Multiple Catch Blocks
    • 3.8. Explicitly Throwing Exceptions & Exception Propagation
    • 3.9. Review Questions - Exceptions
  • 4. Command-Line Arguments
    • 4.1. Introduction
    • 4.2. String[] args
    • 4.3. Command-Line Arguments Tutorial
  • 5. Interfaces
    • 5.1. Introduction
    • 5.2. Interface Example
    • 5.3. Setting up the Environment
    • 5.4. Declaring an Interface
    • 5.5. Implementing an Interface
    • 5.6. Using an Interface
    • 5.7. Common Functionality among Disparate Classes
  • 6. Varargs
    • 6.1. Getting Started with Varargs
    • 6.2. The printf Method
  • 7. Inheritance
    • 7.1. Introduction
    • 7.2. Setting up the Environment
    • 7.3. Person Example (Refactoring Existing Code)
    • 7.4. What is Inherited?
    • 7.5. Animal Example
    • 7.6. Method Overrides
    • 7.7. Abstract Classes
    • 7.8. Inheritance and Polymorphism
  • 8. ADTs and Lists
    • 8.1. Introduction to Linked Lists
    • 8.2. Introduction to ADTs
    • 8.3. The List Interface (ADT)
    • 8.4. List ADT - Examples with Both Implementations
    • 8.5. Linked List Get Operation
    • 8.6. Linked List Add Operation
    • 8.7. Conclusion
  • 9. Visibility
    • 9.1. Introduction
    • 9.2. Public and Private Visibility
    • 9.3. Package Private Visibility
    • 9.4. Protected Visibility
    • 9.5. Summary of Visibilities
  • 10. Generics
    • 10.1. Introduction to Generics
    • 10.2. Wrapper Classes
    • 10.3. Setting up the Environment
    • 10.4. Creating the Shipping Container Class
    • 10.5. Introduction - Generic Methods
    • 10.6. Generic Methods
    • 10.7. Generic Methods - Video Example
  • 11. Lambda Expressions
    • 11.1. Introduction
    • 11.2. Functional Interfaces
    • 11.3. Example: Named Class vs. Lambda Expression
    • 11.4. How to Create Lambda Expressions
    • 11.5. More Examples
  • 12. JavaFX
    • 12.1. Getting Started
    • 12.2. Compiling JavaFX Applications
    • 12.3. High-Level Walkthrough
    • 12.4. Mid-Level Walkthrough
    • 12.5. Events and Event Handlers
    • 12.6. JavaFX 17 Bookmarks and Notes
  • 13. JavaFX Custom Components
    • 13.1. Getting Started
    • 13.2. Creating a Custom Component
  • 14. Threads
    • 14.1. Quick Introduction
    • 14.2. Thread Terminology
    • 14.3. The Thread Class
    • 14.4. Daemon Threads
    • 14.5. JavaFX Application Thread
  • 15. JSON
    • 15.1. Introduction to JSON
    • 15.2. JSON Objects
    • 15.3. Serializing to JSON in Java
    • 15.4. Parsing JSON in Java
    • 15.5. Adding Gson to a Project
  • 16. HTTP
    • 16.1. Introduction to HTTP
    • 16.2. Java’s java.net.http Library
    • 16.3. Complete Examples
  • 17. Recursion
    • 17.1. Introduction
    • 17.2. Infinite Recursion
    • 17.3. Problems and Sub-problems
    • 17.4. Recursive Countdown
    • 17.5. Recursive Count Up
    • 17.6. Recursive Factorial
  • 18. Algorithm Analysis
    • 18.1. Introduction
    • 18.2. Algorithm Analysis Steps
    • 18.3. Example Problems
    • 18.4. Space Complexity Analysis

Appendices:

  • Glossary
  • References
Back to top

2.1. Navigating the File System¶

In the previous tutorial, you experienced the pwd (print working directory) command and were provided a brief introduction to absolute paths. In Unix, a directory file or directory is the same concept as a folder in other operating systems; that is, in most cases the words “directory” and “folder” are interchangeable. Your current working directory is the directory in which you are currently executing commands. There are other directories, and in Unix, they are all organized under a top-most directory called /, representing the root of the file system. The macOS and Linux operating systems organize their file systems the same way. If you are coming from a Windows background, then it is reasonable to compare / to the C: drive.

For this part of the tutorial, we are going to assume that you have some specific files in your home directory. To make sure that you have these files, you should execute the command below. The command may take a few seconds to run as it involves downloading some files from the Internet. You don’t need to memorize or understand the command below; you just need to execute it to proceed with the tutorial.

curl -s -L https://git.io/fjbdg | bash
../../_images/nav-prep-demo.svg

2.1.1. ls, ls PATH, tree PATH¶

To list the files in your current working directory, use the ls (list) command. It is common for ls to differentiate between directories and regular files in its output using different colors.

ls
../../_images/ls-demo.svg
  • How many directories and regular files are in your home directory?

The ls (list) command is not limited to the current working directory. You can tell ls to list the files in some other directory by supplying a path to that directory as a command-line argument.

ls cs1302-unix
../../_images/ls-path-demo.svg
  • The paths used in the examples above are relative paths. Instead of describing the traversal path starting from /, they describe the traversal path starting from the current working directory. The ls command also works with absolute paths. What is the command to list the files in your home directory using an absolute path?

While ls is nice and probably one of the most used Unix commands of all time, it doesn’t let us see the whole picture without us issuing repetitive ls commands. To see the bigger picture, use the tree command, which lists the contents of a directory in a tree-like format. If this command doesn’t work for you, please go back and make sure you have completed the previous tutorial and all the required setup steps.

tree cs1302-unix
../../_images/tree-path-demo.svg

Test Yourself

  • Which files are contained in the cs1302 directory?

  • What about the books directory?

Command

Description

ls

List contents of the current working directory.

ls PATH

List contents of the last directory in the provided PATH (e.g., c in a/b/c or /a/b/c).

tree PATH

List contents of the last directory in the provided PATH and its subdirectories, in a tree format.

2.1.2. ls -l, ls -lh¶

By default, the ls command displays the contents of a directory using its “simple” output format. A “long” output option can be specified by supplying a -l as a command-line argument. In addition to the name of each file, additional information is included in the “long” output format, as described below in the next few examples.

ls -l cs1302-unix/books
../../_images/ls-long-demo.svg

Mode

User

Group

Size

Timestamp

Name

-rw-r--r--.

1

mepcott

myid

1276233

Feb 28 10:45

moby_dick.txt

-rw-r--r--.

1

mepcott

myid

799645

Feb 10  2021

pride_and_prejudice.txt

-rw-r--r--.

1

mepcott

myid

607430

Jun  9 12:45

sherlock_holmes.txt

ls -l cs1302-unix
../../_images/ls-long-demo2.svg

Mode

User

Group

Size

Timestamp

Name

drw-r-xr-x.

2

mepcott

myid

85

Aug 17 17:39

books

drw-r-xr-x.

4

mepcott

myid

46

Aug 17 17:39

notes

-rw-r--r--.

1

mepcott

myid

9

Aug 17 17:39

README.md

You don’t need to understand most of the columns in a long listing produced by ls -l at this point in time. The takeaway is that adding a command-line argument like -l changes the behavior of ls without needing to ask the user for any additional input.

You can supply -h as a command-line argument to ls -l to enable the display of human-readable units for file sizes. Many Unix programs like ls allow you to combine single character (short) options into a single command-line argument when entering the command at the shell prompt. All three examples below produce the same output.

ls -l -h cs1302-unix/books
ls -h -l cs1302-unix/books
ls -lh cs1302-unix/books
../../_images/ls-long-human-demo.svg

Test Yourself

  • What command can be used to see the sizes of the files in a directory?

  • What is second way to accomplish the same task using the same options?

Command

Description

ls -l

ls uses long listing format

ls -l -h

ls uses long listing format with human-readable size units

2.1.3. cd PATH, cd -, cd ~, cd¶

So far, you know how to list the files in your home directory, your current working directory, and other directories; however, all of the examples so far have utilized absolute or relative paths in a way that kept you in your home directory. It’s time for that to change, or rather it’s time for your current working directory to change. This can be done using the cd (change directory) command.

As you navigate to various directories in this section, try typing pwd and ls in each directory. Note how the output of each command changes as you change directories. That’s because commands are always executed in the context of the current directory.

cd cs1302-unix
../../_images/cd-path-demo1.svg
cd notes/cs1302
../../_images/cd-path-demo2.svg

If you to change to the directory you were last in prior to your current working directory, then supply - (minus sign) as a command-line argument to cd.

cd -
../../_images/cd-minus-demo.svg

On most Unix systems, ~ (tilde) is an alias for the absolute path of your home directory. While you can use it with cd to change directly to your home directory, it’s more commonly used to change to directories nested under your home directory.

cd ~/cs1302-unix
../../_images/cd-tilde-demo.svg

If you use the cd command without supplying any command-line arguments, then it changes to your home directory. How convenient!

cd
../../_images/cd-solo-demo.svg

Test Yourself

  • What two commands (or variations of the same command) can always be used to take you to your home directory?

  • How can you tell if a path is absolute or relative?

  • How can you convert a relative path to an absolute path (and vise-versa)?

Command

Change to

cd

home directory

cd -

last previous working directory

cd a/b/dest

dest, assuming a is in the current directory and a/b/dest is a valid relative path

cd /a/b/dest

dest, assuming /a/b/dest is a valid absolute path

cd ~/a/b/dest

dest, assuming a is in your home directory and ~/a/b/dest is a valid path

2.1.4. ls -a, cd ..¶

The default behavior of ls is to ignore files starting with . (hidden files). To force ls to not ignore hidden files, supply the -a (all) option as a command-line argument.

ls -a
../../_images/ls-all-demo.svg

Every directory on a Unix system has two special hidden files named . and ...

File

Description

.

path alias for the directory itself

..

path alias for parent of the directory (parent directory)

Remember, the default behavior of ls is to list the contents of the current working directory. If we supply . as a path to ls, then it does the same thing.

ls .
../../_images/ls-dot-demo.svg

You can supply .. as a path for ls to list the contents of the current working directory’s parent (i.e., its parent directory).

ls ..
../../_images/ls-dotdot-demo.svg

You can supply .. as a path to cd to change to go up one directory; that is, change to the parent directory.

cd ..
../../_images/cd-dotdot-demo.svg

You can even go up two directories using ../...

cd ../..
../../_images/cd-dotdot2-demo.svg

Command

Description

ls -a

ls shows hidden files (those that start with .)

ls .

ls lists the contents of . (current directory); same as ls with no arguments

ls ..

ls lists the contents of .. (parent directory)

cd ..

cd changes working directory to .. (parent directory; “up one”)

cd ../..

cd changes working directory to ../.. (parent of parent directory; “up two”)

Test Yourself

  • What is the difference between . and ..?

  • How can you leverage .. to go up a directory tree by three directories (i.e., instead of up by one or up by two) using a single command?

Next
2.2. Time-saving Tips
Previous
2. Unix Commands
Copyright © 2024-present , and the University of Georgia.
Made with Sphinx and @pradyunsg's Furo
The content and opinions expressed in this work do not necessarily reflect the views of nor are they endorsed by the University of Georgia or the University System of Georgia.
Submit Feedback
On this page
  • 2.1. Navigating the File System
    • 2.1.1. ls, ls PATH, tree PATH
    • 2.1.2. ls -l, ls -lh
    • 2.1.3. cd PATH, cd -, cd ~, cd
    • 2.1.4. ls -a, cd ..