Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
MacOS terminal navigation
(section)
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Practice navigating from the terminal == The filesystem on your computer is like a tree made up of folders (also called "directories") and files. The filesystem has a root directory called <tt>/</tt>, and everything on your computer lives in subdirectories of this root directory. We often navigate the filesystem graphically by clicking on graphical folders. We can do the exact same navigation from the terminal. There are three commands that we'll be using in the terminal to navigate the filesystem on your computer: * <code>ls</code> * <code>pwd</code> * <code>cd</code> <code>ls</code> lists the contents of a directory.<br /> <code>pwd</code> gives the full directory path to your current directory.<br /> <code>cd</code> moves you into a new directory (it stands for "change directory"). Let's practice using these commands. ===Open a terminal=== You can find the Terminal application through Spotlight, or navigate to Applications/Utilities/Terminal. If you are using Anaconda Navigator, you can open terminal clicking on the play arrow button in the Environments -> base(root) window. ===Practice using <code>ls</code>, <code>pwd</code>, and <code>cd</code>=== (that's a letter l in "ls", not the number 1) Type each of these commands and hit enter: <pre>ls</pre> This lists all the files in your current directory. <br /> <pre>pwd</pre> This displays the full directory path to your current directory. (It's stands for "print working directory.") <br /> <pre>cd /</pre> This will change you into the <code>/</code> root directory. <br /> <pre>ls</pre> This lists the contents of the <code>/</code> root directory. <br /> <pre>cd Users</pre> This will change you into the <code>Users</code> subdirectory of the <code>/</code> root directory. <br /> <pre>ls</pre> You should see a list of all the files in <code>/Users</code>, including the directory for your username. The directory for your username (e.g. <tt>/Users/Jessica</tt> is often called your "home directory". <br /> <pre>pwd</pre> This displays the full directory path to your current directory, <code>/Users</code>. <br /> <pre>cd ..</pre> <code>..</code> means "parent directory", so this command moved you up to the parent directory. You were in <code>/Users</code>, so now you are in <code>/</code>, the root directory. <br /> <pre>ls</pre> This lists the contents of the root directory, confirming where you are. If you want to get back to your home directory, you can do: <pre>cd Users</pre> <pre>cd YOURNAME</pre> where YOURNAME is the name of your User directory. One helpful tip is that you can start typing a directory, then hit the <code>TAB</code> key and the terminal will autocomplete it. ===Tips=== * You can use Tab to auto-complete directory and file names. So from inside the root directory <tt>/</tt>, if you type <code>cd Us</code> and hit Tab, the terminal will auto-complete the directory name, and you can then hit enter to change into the <code>/Users</code> directory. * The terminal maintains a command history. You can use the up arrow to cycle through old commands. ===Check your understanding=== Answer these questions. Experiment at the terminal prompt if you need to! If you aren't sure about an answer, ask a helper. # What directory are you in after starting a new terminal prompt? # After starting a new terminal prompt, how would you get to the root directory? # How do you check what files and directories are in your current working directory? # If you are in directory <tt>/Users</tt>, and you want to get to <tt>/Users/jesstess/projects</tt>, how would you do that? # What are 2 ways to avoid typing out a full navigation command? (hint: one requires that you've run the command before) # What is the difference between a terminal prompt and a Python prompt? ===Success!=== You've practiced using <code>ls</code>, <code>pwd</code>, and <code>cd</code> to navigate your computer's filesystem from the terminal. [[File:Champagne.png|100px]][[File:Party.png|125px]] [[Category:CDSW]][[Category:Shared Pages]]
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information