Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

INTRODUCTION TO COMMAND LINE

The command line is a text interface for the comouters operating system. You can
use it to traverse and edit your computers filesystem. Through the command line,
you can create new files, edit the contents of those files, delete files and more.

The first command we are going to look at is ls.

ls-looks at the directory you are in and then "list" all the files and directories
inside of it.

$-in the terminal the first thing you'll see in $. This is called a shell prompt.
It appears when the terminal is ready to accept a command.

Next command is pwd.

pwd- 'print working directory', it ouputs the name of the directory you are
currently in, called the working directory.

Next command is cd.

cd-stands for 'change directory', cd switches you into the directory you specify,
it changes the working directory.

Argument ..

cd .. allows us to move back in the directory (move one space back up/above)

cd ../.. allows us to move two spaces above

Example: let's say our directory is /home/user/workspace/blog

Let's say we want to go into a directory that is inside 'blog' called 2015:

cd 2015

Now let's say we want to go back to /home/user/workspace/blog:


cd ..

Now let's say we want to go back to /home/user:


cd ../..

The next command we are going to look at is mkdir.

mkdir-'make directory', it takes in a directory name as an argument and then


creates a new directory in the current working directory.

To make a new directory within a directory that has just been created you can use
either of these two approaches:

-use mkdir from the current position by using the relative path as an
argument
Example: let's say the new directory is media and the new directory within
media is tv. It would be: mkdir media/tv
OR
-cd into the new directory, in this case media, (if it already has been
created) and then use mkdir (without a relative path)
Example: mkdir media---> cd media---> mkdir tv

Next command is touch.

touch-creates a new file inside the working directory. It takes in a filename as an


argument and then creates an empty file with that name in the current working
directory. Here we us the command touch to create a new file names keyboard.txt

Example: touch keyboard.txt

HELPER COMMANDS

tab can be used to autocomplete your commands.

up and down arrows can be used to cycle through previous commands, will take you up
or down to the most recent ones.

clear is used to clear your terminal, which is useful when it's full of previous
commands and outputs. It doesn't change or undo the previous commands, it just
clears them from view.

REVIEW

The command line- is a text interface for the computers operating system. To access
the command line, we use the terminal.

A filesystem-organizes a computers files and directories into a tree structure. It


starts with the root directory. Each parent directory can contain more child
directories and files.

Directory- a folder used to store files

ls REVISISTED-OPTIONS

We can use ls as is, or attach an option. Options modify the behavior of commands.
Here are three common options used with ls:

-a: list all contents, including hidden files and directories. This command
displays all the files and directories, including those starting with a dot (.).
Files starting with a dot are normally hidden and don't appear with the command ls
alone. Ex: ls -a

-l: (lowercase "L") list all contents of a directory in long format, as well as the
file permissions. Ex: ls -l

-t: orders files and directories by the time they were last modified.Ex: ls -t

In addition to using each option separately, multiple options can be used together.
We can group letter options for other commands in the same way.
Example: ls -alt

COMMAND CAT

How do we view the contents of an individual file in out terminal? We can use cat.
cat-outputs the contents of a speicifed file. This is a useful command for peeking
at files without opening them, and confirming the results of other commands that
change the contents of files.
Example: cat file.txt (name of file.txt) and it will output all the text from that
file.

You might also like