Lesson 13: Navigate the File System with Terminal Flashcards

1
Q

Key Points

The ~ (tilde) represents the current user’s home directory.

Use pwd to print the current working directory.

The / (Forward slash) represents the root of the hard drive, or Macintosh HD.

Use cd to change to a different working directory. Examples include:

cd ~/Desktop navigates to the current working user’s Desktop.

cd /Applications navigates to the local Applications directory.

cd .. navigates to the current working directory’s parent folder.

The absolute file path is the full path to a file or directory, beginning at the root level.

Using the absolute file path will perform a command regardless of the user’s current location.

For example, cd /Users/localadmin/Downloads moves the current working directory to the user’s Downloads folder, even if they are not currently located in /Users/localadmin.

Relative file paths are the short path to a file or directory in relation to the current working directory.

cd Downloads moves to the user’s Downloads folder, only if the current directory is /Users/localadmin.

If the user is located anywhere else in the file system, e.g. /Users/localadmin/Desktop, the above command will fail because the user’s Downloads folder is not relative to the Desktop folder.

To make a new directory, use mkdir.

For example, mkdir ~/Desktop/Jamf creates a new directory on the current user’s Desktop called Jamf.

To create a new, empty file, use touch.

For example, touch ~/Desktop/test.txt creates an empty text file called test.txt.

This command only works with certain file types. For example, touch ~/Desktop/unicorn.psd results in an unusable file.

To move a file from one directory to another, or to rename a file, use mv. To move a file, include the source file followed by the destination directory.

For example, mv ~/Desktop/test.txt ~/Desktop/Jamf moves test.txt from the desktop to the Jamf folder.

To rename a file, include the source file followed by the destination directory and the new file name. This can be the same directory the file currently occupies.

For example, mv ~/Desktop/test.txt ~/Desktop/100.txt renames test.txt to 100.txt, and it will remain on the desktop.

To copy a file, use cp. Include the source file followed by the destination.

For example, cp ~/Desktop/100.txt ~/Desktop/Jamf copies 100.txt from the Desktop to the Jamf folder.

To copy a directory and its contents, use cp with the -r option.

For example, cp -r ~/Desktop/Jamf ~/Desktop/JamfBackup creates a copy of the Jamf directory along with any contained files.

To remove a file, use rm.

For example, rm ~/Desktop/100.txt deletes the targeted text file.

To remove a directory and all of it’s contents, use rm -r.

For example, rm -r ~/Desktop/Jamf deletes the directory, all subdirectories, and all files from the Jamf folder.

Use extreme caution with the rm command. These files will not appear in the trash and there is no way to recover them short of restoring a backup or using a data recovery service.

A

https://youtu.be/rlGIFljfYMU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly