02 Navigating Files and Directories - ryandkuster/EPP_575_RNA_25 GitHub Wiki
The part of the operating system responsible for managing files and directories is called the file system. It organizes our data into files, which hold information, and directories (also called ‘folders’), which hold files or other directories.
Let's investigate some directories and files on our personal computers. Open up your terminal and run the command pwd
(aka 'print working directory').
Input:
pwd
Output:
/Users/<your_username>
Your home directory path may look different from mine. On Linux/Mac, the home directory will be /home/<username>
with forward slashes. The home directory path on Windows will be C:\Users\<username>
, separated by backward slashes.
Let's see the contents of our current directory (/home/<username>
):
ls -F
The -F
is an option or a flag, which tells ls
to provide additional classifiers to files and directories.
- Directories will have a trailing
/
- Links will have a
@
- Executables (scripts) will have an
*
Commands like ls
have many different options users can utilize - depending on your environment, you can either:
- Pass
--help
to any command
ls --help
- Print the manual with
man
:
man ls
- Google!
You can use ls
to print a directory's contents without toggling into it. Let's say we want to view the contents of Desktop
:
ls -F Desktop
The shell-lesson-data
directory should be nestled within your home directory. Let's print the contents of shell-lesson-data
to get a peek at what's in there.
ls -F shell-lesson-data
Within shell-lesson-data
, we see a directory called exercise-data
. Let's toggle into this directory with the command cd
(aka 'change directory').
cd ~/command_line_practice/shell-lesson-data/exercise-data
You can go back directories by using ..
(which denotes the parent directory):
Use pwd
to check current directory. Go back one directory:
cd ..
Go back two directories:
cd ../..
Instead of using the ..
notation, we can also use relative (partial) and absolute (full) paths. Let's say we want to cd
into the alkanes
directory (a sub-directory of exercise-data
)
Relative path (starting point is the current directory Desktop
):
cd ~/command_line_practice/shell-lesson-data/exercise-data/alkanes
Absolute path (entire path from the root directory, indicated by a leading slash):
cd /Users/<username>/command_line_practice/shell-lesson-data/exercise-data/alkanes
If you want to change into your home directory, you can use a ~
:
cd ~
If you want to change to the root directory (the directory that holds everything), you can use /
:
cd /
Change back to the shell-lesson-data
directory (use pwd
to verify). Let's use ls
to view the north-pacific-gyre
directory.
ls -F north-pacific-gyre
We see that this directory contains a bunch of text files, many of which are sample names that all start with 'NENE'.