1 | 2 | Current Level: 3 | 4 | 5
Return to exercise-data
in one step
Instead of doing three commands:
cd Desktop
cd shell-lesson-data
cd exercise-data
You can just type:
cd Desktop/shell-lesson-data/exercise-data
Check your location Type:
pwd
Example output:
/Users/nelle/Desktop/shell-lesson-data/exercise-data
Then list contents:
ls -F
What if we want to go back up one level? You already know:
cd ..
Use an absolute path Instead of using a relative path (from where you are), you can jump to a folder using its full location from the root:
cd /Users/nelle/Desktop/shell-lesson-data
This always works — no matter where you are in the system.
How to find the absolute path Use:
pwd
Then copy part of the result. For example, if you’re inside exercise-data
, pwd
might show:
/Users/nelle/Desktop/shell-lesson-data/exercise-data
You can remove the last part to get the full path to shell-lesson-data
.
Relative path: starts from where you are now Example:
cd Desktop/shell-lesson-data
Absolute path: starts with /
and always points to the same location
Example:
cd /Users/nelle/Desktop/shell-lesson-data
Use pwd
to find out where you are.
Use ls -F
to check what’s in a folder after moving.
If your current location is:
/Users/backup
And you want to list folders in reverse order, like this:
pnas_sub/ pnas_final/ original/
Which command would give this output?
Choices:
ls pwd
ls -r -F
ls -r -F /Users/backup
Answer:
/Users/backup
.pwd
.