PyCon intro to open source/Windows terminal navigation: Difference between revisions

no edit summary
imported>Jesstess
(Created page with "__NOTOC__ 200px The filesystem on your computer is like a tree made up of folders (also called "directories") and files. The filesystem has a...")
 
imported>Jesstess
No edit summary
Line 7:
We often navigate the filesystem graphically by clicking on graphical folders. We can do the exact same navigation from the command line.
 
There are twothree commands that we'll be using at a command prompt to navigate the filesystem on your computer:
* <code>dirls</code>
* <code>pwd</code>
* <code>cd</code>
 
<code>dirls</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").
 
<b>Let's practice using these commands!</b>.
 
===Open a command prompt:===
 
<b>For this tutorial, we are always going to use Git Bash rather than the Windows cmd program, because Git Bash gives us access to several useful command line utilities.</p>
* On Windows Vista or Windows 7: click on the Start menu (the Windows logo in the lower left of the screen), type <code>cmd</code> into the Search field directly above the Start menu button, and click on "cmd" in the search results above the Search field.
* On Windows XP: click on the Start menu (the Windows logo in the lower left of the screen), click on "Run...", type <code>cmd</code> into the text box, and hit enter.
 
Start Git Bash either via a shortcut icon on the Desktop, or from your Start menu.
===Practice using <code>dir</code> and <code>cd</code>===
 
===Practice using <code>dirls</code>, <code>pwd</code>, and <code>cd</code>===
 
(that's an l the letter, not the number 1)
 
Type each of these commands and hit enter:
 
<pre>dirls</pre>
This lists all the files in your current directory.
 
<br />
 
<pre>cd C:\pwd</pre>
This willdisplays changethe youfull intodirectory thepath to your <code>C:\</code>current directory.
 
<br />
 
<pre>cd /</pre>
This will change you into the <code>Users/</code> subdirectory of the <code>C:\</code>root directory.
 
<br />
 
<pre>ls</pre>
This lists the contents of the <code>/</code> root directory.
 
<br />
 
<pre>dircd home</pre>
This listswill change you into the contents<code>home</code> subdirectory of the <code>C:\/</code> root directory.
 
<br />
 
<pre>cd Usersls</pre>
You should see a list of all the files in <code>/home</code>, including the directory for your username. The directory for your username (e.g. <tt>/home/jessica</tt>) is often called your "home directory".
This will change you into the <code>Users</code> subdirectory of the <code>C:\</code> directory.
 
<br />
 
<pre>dirpwd</pre>
YouThis should seedisplays the namesfull ofdirectory all thepath filesto andyour directoriescurrent indirectory, <code>C:\Users/home</code>.
 
<br />
 
<pre>cd ..</pre>
<code>..</code> means "parent directory", so this command moved you up to the parent directory. You were in <code>C:\Users/home</code>, so now you are in <code>C:\/</code>, the root directory.
 
<br />
 
<pre>dirls</pre>
This lists the contents of the root directory, confirming where you are.
 
===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 Useho</code> and hit Tab, the command prompt will auto-complete the directory name, and you can then hit enter to change into the <code>C:\Users/home</code> directory.
* The command prompt maintains a command history. You can use the up arrow to cycle through old commands.
* Note that the text that makes up the command prompt changes as you move around directories. The command prompt will always give the full directory path to your current directory.
 
===Check your understanding===
Line 71 ⟶ 85:
# After starting a new command line 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>C:\Users/home</tt>, and you want to get to <tt>C:\Users\/home/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 command prompt and a Python prompt?
Line 77 ⟶ 91:
===Success!===
 
You've practiced using <code>dirls</code>, <code>pwd</code>, and <code>cd</code> to navigate your computer's filesystem from the command prompt.
 
[[File:Champagne.png|100px]][[File:Party.png|125px]]
Anonymous user