The following steps will show you how to use the black window all hackers use. It might look a bit scary at first but really it's just a prompt waiting for commands from you.
What is the command line? The window, which is usually called the command line or command-line interface, is a text-based application for viewing, handling, and manipulating files on your computer. It’s much like Windows Explorer or Finder (Mac), but without the graphical interface. Other names for the command line are: cmd, CLI, prompt, console or terminal.
How can I open it?
If you don't know what to do, you can try Google, ask the coach, or you can e-mail us.
When you open the command line, you should see a white or black window that is waiting for your command.
Each command will be prepended by the sign $
or >
(depending on your operating system)
and one space, but you don’t have to type this prompt.
Your computer will do it for you.
$
>
Each operating system has slightly different set of commands for the command line, so make sure to follow the instructions for your operating system.
Font size (Windows)
If your font is too small you can click on the small window icon in the up right corner. Then choose Properties and find the Font tab where you can set a different font size.
In other operating systems, you can try: Ctrl++ and Ctrl+- (+ Shift).
We will start with a very easy command.
Write whoami
(who am I?)
and press Enter.
Your user ID will be shown. For example on Alex' computer, it looks like this:
$ whoami
Alex
> whoami
PCname\Alex
The command line always works from a directory (also folder).
We can print our working directory (also called current directory) by using the command pwd
(Linux, MacOS)
or cd
(Windows). pwd
means print working directory and cd
stands for current directory
$ pwd
/home/Alex/
> cd
C:\Users\Alex
The current directory is often also displayed before $
or >
, but it's
good to know this command in case that you get lost or if you have to
work on a computer that is set to display something different before $
.
Command ls
or dir
(list or directory)
will show us what's in the current directory: all files and
subfolders.
$ ls
Applications
Desktop
Downloads
Music
…
> dir
Directory of C:\Users\Alex
05/08/2014 07:28 PM <DIR> Applications
05/08/2014 07:28 PM <DIR> Desktop
05/08/2014 07:28 PM <DIR> Downloads
05/08/2014 07:28 PM <DIR> Music
…
You can chnage your current directory by using the command cd
(change directory) -
for all OSs (in Windows, if you don't specify anything after cd
, command
prints the current directory as we said earlier)
So after cd
we have to write the folder's name where we want to go.
Don't forget to check if you were successful.
If you have Linux or macOS, be careful - those systems are case sensitive,
so Desktop
and desktop
are two different folders!
$ cd Desktop
$ pwd
/home/Alex/Desktop
> cd Desktop
> cd
C:\Users\Alex\Desktop
Note for Windows users
If you change directories to a different disk (to D:
from C:
)
you have to enter the disk's name (D:
) as a special command before
you enter cd
.
How about creating a practice directory on your Desktop? You can do this by using the
command mkdir
(make directory).
After that command, write the name of the folder that you want to create -
in our case practice
.
$ mkdir practice
> mkdir practice
Now, look on your Desktop or into some other graphical program for browsing folders, and check if the folder was created!
In your new practice
directory, try to create a subfolder test
and check
if it was created.
The commands cd
, mkdir
and ls
or dir
might help you.
We don't want to leave a mess, so let's remove everything we did until that point.
But you can't delete the folder in which you currently are.
First, we need to get back to the Desktop. We can't use cd Desctop
because in the current
folder, there is no Desktop.
So we have to go to the parent directory which contains the folder that you are
currently in.
Two dots stand for the parent directory.
$ pwd
/home/Alex/Desktop/practice
$ cd ..
$ pwd
/home/Alex/Desktop
> cd
C:\Users\Alex\Desktop\practice
> cd ..
> cd
C:\Users\Alex\Desktop
Now it's time to delete the practice
directory.
For that purpose, use rm
or rmdir
(remove or remove directory).
Warning!
The command line does not have a Recycle Bin! Everything will be deleted for good. Every time, make sure that you are deleting the right folder.
In Unix, you have to write rmdir -rv
(minus,r
, v
). The parameter deletes everything
(r
- recursive) inside the folder, and it prints info telling you (v
- verbose)
what the command is doing.
In Windows, you also have to add a switch to the rm
command to delete everything inside a
directory. Here, the switch is /S
(forward slash, S
).
$ pwd
/home/Alex/Desktop
$ rm -rv practice
removed directory: ‘practice’
> cd
C:\Users\Alex\Desktop
> rmdir /S practice
practice, Are you sure <Y/N>? Y
There is a table of basic commands:
Unix | Windows | Description | Example |
---|---|---|---|
cd |
cd |
change directory | cd test |
pwd |
cd |
show the current directory | pwd cd |
ls |
dir |
list directories/files | ls dir |
cp |
copy |
copy a file |
cp original.txt copy.txt
copy original.txt copy.txt
|
mv |
move |
move a file |
mv old.txt new.txt
move old.txt new.txt
|
mkdir |
mkdir |
create a new directory | mkdir test |
rm |
del |
delete a file | rm test.txt del test.txt |
rmdir /S |
rm -rv |
delete a directory | rm -rv testdir |
exit |
exit |
close the window | exit |
There are of course a lot more commands.
All the programs that you have installed on your laptop can be
run from the command line - usually by typing their names.
Try for example - firefox
, notepad
, safari
, or gedit
.
If it's not working, ask your coach and they might help you to find an example command that works.
We will use commands/programs like python
and git
a lot. We will install them
in a while.
Now you can try one more command - the one that closes the command line window - exit
.
It works the same in all operating systems.
$ exit
We will be using $
to indicate Linux/macOS (in fact, for Unix based OS) commands
and >
to indicate Windows commands for the rest of our course.
This is the convention in most materials and tutorials you will find.
{ "data": { "sessionMaterial": { "id": "session-material:2018/pyladies-en-prague:install:1", "title": "Introduction to command line", "html": "\n \n \n\n <h1>Command line</h1>\n<p>The following steps will show you how to use the black window all \nhackers use. It might look a bit scary at first but really it's \njust a prompt waiting for commands from you.</p>\n<p>What is the command line?\nThe window, which is usually called the <em>command line</em> or <em>command-line interface</em>, \nis a text-based application for viewing, handling, and manipulating files on your computer. \nIt’s much like Windows Explorer or Finder (Mac), but without the graphical interface. \nOther names for the command line are:\n<em>cmd</em>, <em>CLI</em>, <em>prompt</em>, <em>console</em> or <em>terminal</em>.</p>\n<p>How can I open it?</p>\n<ul>\n<li>Windows (English): Start → write "cmd" → Command prompt</li>\n<li>Windows (older versions): Start menu → All programs → Accessories → Command prompt</li>\n<li>macOS (English): Applications → Utilities → Terminal</li>\n<li>Linux (KDE): Main Menu → search for Console</li>\n<li>Linux (GNOME): Super → search for Terminal</li>\n</ul>\n<p>If you don't know what to do, you can try Google, ask the coach,\nor you can e-mail us.</p>\n<p>When you open the command line, you should see a white or black window that is waiting for your command.\nEach command will be prepended by the sign <code>$</code> or <code>></code> (depending on your operating system) \nand one space, but you don’t have to type this prompt. \nYour computer will do it for you.</p>\n<div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix (Linux, macOS)</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$\n</span></pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">>\n</span></pre></div></div></div><p>Each operating system has slightly different set of commands for the command line, \nso make sure to follow the instructions for your operating system.</p>\n<div class=\"admonition note\"><p class=\"admonition-title\">Font size (Windows)</p>\n<p>If your font is too small you can click on the small window icon in the up right corner.\nThen choose Properties and find the Font tab where you can set a different font size.</p>\n<p><span class=\"figure\"><a href=\"/2018/pyladies-en-prague/beginners-en/cmdline/static/windows-cmd-properties.png\"><img src=\"/2018/pyladies-en-prague/beginners-en/cmdline/static/windows-cmd-properties.png\" alt=\"Screenshot of command line window\"></a></span></p>\n<p>In other operating systems, you can try:\n<kbd>Ctrl</kbd>+<kbd>+</kbd> and\n<kbd>Ctrl</kbd>+<kbd>-</kbd> (+ Shift).</p>\n</div><h2>First command</h2>\n<p>We will start with a very easy command.\nWrite <code>whoami</code> (<em>who am I?</em>)\nand press <kbd>Enter</kbd>.\nYour user ID will be shown. For example on Alex' computer, it looks like this:</p>\n<div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span>whoami\n<span class=\"go\">Alex</span>\n</pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">> </span>whoami\n<span class=\"go\">PCname\\Alex</span>\n</pre></div></div></div><h2>Working directory</h2>\n<p>The command line always works from a <em>directory</em> (also <em>folder</em>).\nWe can print our working directory (also called current directory) by using the command <code>pwd</code> (Linux, MacOS)\nor <code>cd</code> (Windows). <code>pwd</code> means <em>print working directory</em> and <code>cd</code> stands for <em>current directory</em></p>\n<div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span><span class=\"nb\">pwd</span>\n<span class=\"go\">/home/Alex/</span>\n</pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">> </span>cd\n<span class=\"go\">C:\\Users\\Alex</span>\n</pre></div></div></div><p>The current directory is often also displayed before <code>$</code> or <code>></code>, but it's\ngood to know this command in case that you get lost or if you have to\nwork on a computer that is set to display something different before <code>$</code>.</p>\n<h2>So what's in that directory?</h2>\n<p>Command <code>ls</code> or <code>dir</code> (<em>list</em> or <em>directory</em>)\nwill show us what's in the current directory: all files and\nsubfolders.</p>\n<div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span>ls\n<span class=\"go\">Applications</span>\n<span class=\"go\">Desktop</span>\n<span class=\"go\">Downloads</span>\n<span class=\"go\">Music</span>\n<span class=\"go\">…</span>\n</pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">> </span>dir\n<span class=\"go\"> Directory of C:\\Users\\Alex</span>\n<span class=\"go\">05/08/2014 07:28 PM <DIR> Applications</span>\n<span class=\"go\">05/08/2014 07:28 PM <DIR> Desktop</span>\n<span class=\"go\">05/08/2014 07:28 PM <DIR> Downloads</span>\n<span class=\"go\">05/08/2014 07:28 PM <DIR> Music</span>\n<span class=\"go\">…</span>\n</pre></div></div></div><h2>Change current directory</h2>\n<p>You can chnage your current directory by using the command <code>cd</code> (<em>change directory</em>) -\nfor all OSs (in Windows, if you don't specify anything after <code>cd</code>, command \nprints the <em>current directory</em> as we said earlier)\nSo after <code>cd</code> we have to write the folder's name where we want to go.\nDon't forget to check if you were successful.</p>\n<p>If you have Linux or macOS, be careful - those systems are case sensitive,\nso <code>Desktop</code> and <code>desktop</code> are two different folders!</p>\n<div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span><span class=\"nb\">cd</span> Desktop\n<span class=\"gp\">$ </span><span class=\"nb\">pwd</span>\n<span class=\"go\">/home/Alex/Desktop</span>\n</pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">> </span>cd Desktop<span class=\"gp\"></span>\n<span class=\"gp\">> </span>cd\n<span class=\"go\">C:\\Users\\Alex\\Desktop</span>\n</pre></div></div></div><div class=\"admonition note\"><p class=\"admonition-title\">Note for Windows users</p>\n<p>If you change directories to a different disk (to <code>D:</code> from <code>C:</code>)\nyou have to enter the disk's name (<code>D:</code>) as a special command before\nyou enter <code>cd</code>.</p>\n</div><h2>Create directory</h2>\n<p>How about creating a practice directory on your Desktop? You can do this by using the\ncommand <code>mkdir</code> (<em>make directory</em>).\nAfter that command, write the name of the folder that you want to create -\nin our case <code>practice</code>.</p>\n<div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span>mkdir practice\n</pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">> </span>mkdir practice\n</pre></div></div></div><p>Now, look on your Desktop or into some other graphical program\nfor browsing folders, and check if the folder was created!</p>\n<h2>Task</h2>\n<p>In your new <code>practice</code> directory, try to create a subfolder <code>test</code> and check\nif it was created.</p>\n<p>The commands <code>cd</code>, <code>mkdir</code> and <code>ls</code> or <code>dir</code> might help you.</p>\n<div class=\"solution\" id=\"solution-0\">\n <h3>Řešení</h3>\n <div class=\"solution-cover\">\n <a href=\"/2018/pyladies-en-prague/beginners-en/cmdline/index/solutions/0/\"><span class=\"link-text\">Ukázat řešení</span></a>\n </div>\n <div class=\"solution-body\" aria-hidden=\"true\">\n <div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span><span class=\"nb\">cd</span> practice\n<span class=\"gp\">$ </span>mkdir <span class=\"nb\">test</span>\n<span class=\"gp\">$ </span>ls\n<span class=\"go\">test</span>\n</pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">> </span>cd practice<span class=\"gp\"></span>\n<span class=\"gp\">> </span>mkdir test<span class=\"gp\"></span>\n<span class=\"gp\">> </span>dir\n<span class=\"go\">05/08/2014 07:28 PM <DIR> test</span>\n</pre></div></div></div>\n </div>\n</div><h2>Cleaning</h2>\n<p>We don't want to leave a mess, so let's remove everything we did until that point.</p>\n<p>But you can't delete the folder in which you currently are.\nFirst, we need to get back to the Desktop. We can't use <code>cd Desctop</code> because in the current\nfolder, there is no Desktop.\nSo we have to go to the <em>parent directory</em> which contains the folder that you are\ncurrently in.\nTwo dots stand for the parent directory.</p>\n<div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span><span class=\"nb\">pwd</span>\n<span class=\"go\">/home/Alex/Desktop/practice</span>\n<span class=\"gp\">$ </span><span class=\"nb\">cd</span> ..\n<span class=\"gp\">$ </span><span class=\"nb\">pwd</span>\n<span class=\"go\">/home/Alex/Desktop</span>\n</pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">> </span>cd\n<span class=\"go\">C:\\Users\\Alex\\Desktop\\practice</span><span class=\"gp\"></span>\n<span class=\"gp\">> </span>cd ..<span class=\"gp\"></span>\n<span class=\"gp\">> </span>cd\n<span class=\"go\">C:\\Users\\Alex\\Desktop</span>\n</pre></div></div></div><p>Now it's time to delete the <code>practice</code> directory.\nFor that purpose, use <code>rm</code> or <code>rmdir</code>\n(<em>remove</em> or <em>remove directory</em>).</p>\n<div class=\"admonition warning\"><p class=\"admonition-title\">Warning!</p>\n<p>The command line does not have a Recycle Bin! Everything will be deleted for good.\nEvery time, make sure that you are deleting the right folder.</p>\n</div><p>In Unix, you have to write <code>rmdir -rv</code> (minus,<code>r</code>, <code>v</code>). The parameter deletes everything\n(<code>r</code> - <em>recursive</em>) inside the folder, and it prints info telling you (<code>v</code> - <em>verbose</em>) \nwhat the command is doing.</p>\n<p>In Windows, you also have to add a switch to the <code>rm</code> command to delete everything inside a\ndirectory. Here, the switch is <code>/S</code> (forward slash, <code>S</code>).</p>\n<div class=\"row side-by-side-commands\"><div class=\"col\">\n <h4>Unix</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span><span class=\"nb\">pwd</span>\n<span class=\"go\">/home/Alex/Desktop</span>\n<span class=\"gp\">$ </span>rm -rv practice\n<span class=\"go\">removed directory: ‘practice’</span>\n</pre></div></div><div class=\"col\">\n <h4>Windows</h4><div class=\"highlight\"><pre><span></span><span class=\"gp\">> </span>cd\n<span class=\"go\">C:\\Users\\Alex\\Desktop</span><span class=\"gp\"></span>\n<span class=\"gp\">> </span>rmdir /S practice\n<span class=\"go\">practice, Are you sure <Y/N>? Y</span>\n</pre></div></div></div><h2>Summary</h2>\n<p>There is a table of basic commands:</p>\n<table class=\"table\">\n <tbody><tr>\n <th>Unix</th>\n <th>Windows</th>\n <th>Description</th>\n <th>Example</th>\n </tr>\n <tr>\n <td><code>cd</code></td>\n <td><code>cd</code></td>\n <td>change directory</td>\n <td><code>cd test</code></td>\n </tr>\n <tr>\n <td><code>pwd</code></td>\n <td><code>cd</code></td>\n <td>show the current directory</td>\n <td><code>pwd</code><br><code>cd</code></td>\n </tr>\n <tr>\n <td><code>ls</code></td>\n <td><code>dir</code></td>\n <td>list directories/files</td>\n <td><code>ls</code><br><code>dir</code></td>\n </tr>\n <tr>\n <td><code>cp</code></td>\n <td><code>copy</code></td>\n <td>copy a file</td>\n <td>\n <code>cp original.txt copy.txt</code>\n <br>\n <code>copy original.txt copy.txt</code>\n </td>\n </tr>\n <tr>\n <td><code>mv</code></td>\n <td><code>move</code></td>\n <td>move a file</td>\n <td>\n <code>mv old.txt new.txt</code>\n <br>\n <code>move old.txt new.txt</code>\n </td>\n </tr>\n <tr>\n <td><code>mkdir</code></td>\n <td><code>mkdir</code></td>\n <td>create a new directory</td>\n <td><code>mkdir test</code></td>\n </tr>\n <tr>\n <td><code>rm</code></td>\n <td><code>del</code></td>\n <td>delete a file</td>\n <td><code>rm test.txt</code><br><code>del test.txt</code></td>\n </tr>\n <tr>\n <td><code>rmdir /S</code></td>\n <td><code>rm -rv</code></td>\n <td>delete a directory</td>\n <td><code>rm -rv testdir</code></td>\n </tr>\n <tr>\n <td><code>exit</code></td>\n <td><code>exit</code></td>\n <td>close the window</td>\n <td><code>exit</code></td>\n </tr>\n</tbody></table><p>There are of course a lot more commands.\nAll the programs that you have installed on your laptop can be\nrun from the command line - usually by typing their names.\nTry for example - <code>firefox</code>, <code>notepad</code>, <code>safari</code>, or <code>gedit</code>.\nIf it's not working, ask your coach and they might help you to find an example command that works.</p>\n<p>We will use commands/programs like <code>python</code> and <code>git</code> a lot. We will install them\nin a while.\n<!--- XXX: this assumes installation is after intro to cmdline --></p>\n<h2>Exit</h2>\n<p>Now you can try one more command - the one that closes the command line window - <code>exit</code>.\nIt works the same in all operating systems.</p>\n<div class=\"highlight\"><pre><span></span><span class=\"gp\">$ </span><span class=\"nb\">exit</span>\n</pre></div><p>We will be using <code>$</code> to indicate Linux/macOS (in fact, for Unix based OS) commands\nand <code>></code> to indicate Windows commands for the rest of our course.\nThis is the convention in most materials and tutorials you will find.</p>\n\n\n " } } }