Using the Linux Command Line
Using the Linux Command Line
The CS50 IDE is a cloud-based machine running
Ubuntu, one of the many flavors of the Linux OS.
Many modern Linux distributions have graphical
user interfaces (GUI) to allow easy mouse-based
navigation.
Still, as a programmer you’ll likely be using your
terminal window frequently, and you can do many
of the same tasks with keyboard commands.
Using the Linux Command Line
Lets have a look at some of the most important of
these keyboard-based commands for working
within the IDE or any UNIX-based system.
Using the Linux Command Line
ls
Short for “list, this command will give you a readout of
all the files and folders in your current directory.
Using the Linux Command Line
cd <directory>
Short for change directory, this command change your
current directory to <directory>, which you specify,
in your workspace or on your operating system.
The shorthand name for the current directory is .
The shorthand name for the parent directory of the
current directory is ..
If ever curious about the name of the current directory,
though the terminal prompt will often tell you, you can
type pwd (present working directory).
Using the Linux Command Line
mkdir <directory>
Short for “make directory, this command will create a
new subdirectory called <directory> located in the
current directory.
Using the Linux Command Line
cp <source> <destination>
Short for copy, this command will allow you to create a
duplicate of the file you specify as <source>, which it
will save in <destination>.
If you wish to copy entire directories, you’ll need to
modify the command slightly:
cp –r <source directory> <destination directory>
The “-r” stands for recursive, and tells cp to dive down
into the directory and copy everything inside of it
(including any subdirectories it might contain).
Using the Linux Command Line
rm <file>
Short for “remove”, this command will delete <file>
after it asks you to confirm (y/n) you want to delete it.
You can skip the confirmation by typing:
rm –f <file>
But use at your own peril! There’s no undo.
To delete entire directories you need to use the –r flag,
just as was the case with cp.
rm –r <directory>
You can also combine the –r and –f flags into –rf.
Again, careful! There’s no undo!
Using the Linux Command Line
mv <source> <destination>
Short for “move”, this command will allow you to
effectively rename a file, moving it from <source> to
<destination>.
Using the Linux Command Line
To be sure, there are many more basic command
line utilities at your disposal, and we’ll discuss
many of them in the future in CS50.
If you wish to explore other interesting ones before
we see them in the class, read up on:
chmod ln touch
rmdir man diff
sudo clear telnet