![](https://csdnimg.cn/release/download_crawler_static/10972347/bga.jpg)
10 Chapter 1. Essential Unix Skills
UNIX system. In the course of this textbook, we will frequently want to indicate commands to by
typed into the terminal. Our format for doing so will be to represent the prompt with “»”, and to
usually indent commands on separate lines: for example, to exit a terminal, type
»exit
and the shell will close. Additionally, in this section of the text it will be useful to define a “typical”
series of nested directories, so that as we practice navigation, we can use self consistent examples.
For now lets use this typical tree: root/physics/user/sally/documents/homework/python/week1/
1.5.1 Changing Directories
There is a single command by which one can navigate the entire UNIX directory tree of any system,
and as there are several subtleties to it, we will discuss it in some detail. The command in question
is “cd”. The syntax “cd” is interpreted by the computer to mean “change directories”. Clearly
though, with just this command, it would be impossible for the computer to know where to change
directories to. Because of this, the command cd takes what is called an
argument
. An argument is a
part of the command necessary for it to function, but that is variable- the user can specify different
values for the argument within a certain set of possibilities. In this example, the “cd” command
takes as an argument a path location, for example in the command, // » cd /root/physics/sally //
/root/physics/sally serves as the argument to “cd”, it tells cd where to actually change directories to.
The majority of commands in UNIX have arguments, although there are a few exceptions.
So the question is, how can we efficiently use the cd command to navigate between directories in
UNIX? Luckily, the cd command has several built-in shortcuts that make navigating easier. However,
we would like to point out that these shortcuts only work in certain situations, which will be described
below. On the other hand, there is one surefire argument for cd which will always work; unfortunately
it is the most cumbersome. Below, we describe the various ways to phrase arguments for cd, the first
being the sure fire method.
1. The full path
: From any directory in a UNIX system, typing cd followed by a full path,
starting with the root directory, will take you immediately to the specified location. This is
possible because a full path is unique, and thus the computer knows exactly where you mean
to go.
2. A nested directory
: For example, if you are in the directory “/root/physics/sally/” and want
to cd into the homework directory, you can simply type
»cd homework
This may seem confusing at first, because there is no “/” before homework. Essentially, the
computer is interpreting your lack of a “/” to mean that the directory you are looking to cd into
is within the one you are currently in. (It will complain if you give a directory as an argument
that is not in the current one, if you use this syntax.
3. A secondary nested directory
: If you want to cd from a current location to two directories
deeper in the nesting system, you can start with the syntax from (2), but continue it into a
longer path, for example, if you were in “root/physics/sally/” and wanted to get into not just
“homework”, but all the way into “python” :
»cd homework/python
and further nested directories can be strung onto the end, if desired.
4. cd (space)
: defaults you to your username’s home directory. This will be different on
different systems, but on UGAstro it will take you to your username’s directory within the
home directory.