Command Line Flashcards

1
Q

pwd

A

print working directory

It outputs the name of the directory you are currently in, called the working directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

cd

A

change directory

changes the working directory (when followed by an argument)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does ‘cd ..’ do?

A

moves up one directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ls

A

list all files and directories in the working directory

In addition to -a, the ls command has several more options. Here are three common options:

  • a - lists all contents, including hidden files and directories
  • l - lists all contents of a directory in long format
  • t - order files and directories by the time they were last modified.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

mkdir

A

make a new directory

It takes in a directory name as an argument, and then creates a new directory in the current working directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

touch

A

Here we used touch to create a new file named keyboard.txt inside the 2014/dec/ directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the ‘command line’?

A

The command line is a text interface for the computer’s operating system. To access the command line, we use the terminal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

filesystem

A

A filesystem organizes a computer’s files and directories into a tree structure. It starts with the root directory. Each parent directory can contain more child directories and files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

$

A

The shell prompt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

-a

A

The -a modifies the behavior of the ls command to also list the files and directories starting with a dot (.). Files started with a dot are hidden, and don’t appear when using ls alone.

The -a is called an option. Options modify the behavior of commands. Here we used ls -a to display the contents of the working directory in more detail.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

..

A

parent directory link

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

.

A

current directory link

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does -l list?

A

1) Access rights. These are actions that are permitted on a file or directory.
2) Number of hard links. This number counts the number of child directories and files. This number includes the parent directory link (..) and current directory link (.).
3) The username of the file’s owner. Here the username is cc.
4) The name of the group that owns the file. Here the group name is eng.
5) The size of the file in bytes.
6) The date & time that the file was last modified.
7) The name of the file or directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

-alt

A

The -t option orders files and directories by the time they were last modified.

In addition to using each option separately, like ls -a or ls -l, multiple options can be used together, like ls -alt.

Here, ls -alt lists all contents, including hidden files and directories, in long format, ordered by the date and time they were last modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

cp

A

The cp command copies files or directories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What command do you use to copy a file to a directory?

A

To copy a file into a directory, use cp with the source file as the first argument and the destination directory as the second argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you copy multiple files into a directory?

A

To copy multiple files into a directory, use cp with a list of source files as the first arguments, and the destination directory as the last argument. (Here, we copy the files biopic/ray.txt and biopic/notorious.txt into the historical/ directory.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Copy all files in a directory

A

cp * directoryname/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does * do?

A

Selects groups of files. Specifically selects all files in the working directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

cp m*.txt scifi/

A

selects all files in the working directory starting with “m” and ending with “.txt” and copies them to scifi/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

mv

A

moves files. Similar to “cp” in its usage.

To move a file into a directory, use mv with the source file as the first argument and the destination directory as the second argument.

To rename a file, use mv with the old file as the first argument and the new file as the second argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

rm

A

The “rm” command deletes files and directories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

rm -r

A

the “-r” is an option that modifies the behavior of the rm command. “-r” stands for recursive and it’s used to delete a directory and all of its child directories.

24
Q

echo

A

“echo” command accepts the strings as standard input and echoes the string back to the terminal as standard output.

25
Q

stdin

A

standard input. Information inputted into the terminal through the keyboard or input device.

26
Q

stdout

A

standard output. the information outputted after a process is run.

27
Q

stderr

A

standard error. error message outputted by a failed process.

28
Q

cat

A

the “cat” command outputs the contents of a file to the terminal.

29
Q

>

A

takes the standard output of the command on the left, and redirects it to the file on the right

30
Q

> >

A

takes the standard output of the command on the left and appends it to the file on the right. You can view the output data of the file with “cat” and the filename

31
Q
A

takes the standard input from the file on the right and inputs it into the program on the left

32
Q

|

A

”|” is a pipe. the | takes the standard output of the command on the left and pipes it as standard input to the command on the right.

Think of this as “command to command” redirection.

33
Q

sort

A

“sort” takes the standard input and orders it alphabetically for the standard output.

34
Q

uniq

A

“uniq” stands for “unique” and filters out adjacent, duplicate lines ina file.

35
Q

grep

A

“grep” stands for “global regular expression print”. It searches files for lines that match a pattern and returns the results. NOTE: It is also case sensitive when enabled with -i like “grep -i “

36
Q

grep -R

A

searches all files in a directory and outputs filenames and lines containing matched results.

-R stands for “recursive”

37
Q

grep -Rl

A

searches all files in a directory and outputs only filenames with matched results.

-R stands for “recursive and “l” stands for “files with matches”

38
Q

sed

A

“sed” stand for “stream editor”. It accepts standard input and modifies it based on an expression before displaying it as output data.

NOTE: It is similar to “find and replace”

NOTE: “s” stands for substitution. It is always used when using sed for substitution.

39
Q

g

A

“g” expression, meaning “global”

$ sed ‘s/snow/rain/g’ forests.txt // sed searches forests.txt for the word “snow” and replaces it with “rain”, GLOBALLY.

40
Q

Each time we launch terminal, it creates…

A

a new session

41
Q

nano

A

opens the nano text editor

nano is a command line text editor. It works just like a desktop text editor like TextEdit or Notepad except it is accessible from the command line and only accepts keyboard input.

42
Q

Command to save the file (in nano editor)

A

Ctrl+O

43
Q

Command to exit nano

A

Ctrl+X

44
Q

Command to clear the terminal window

A

clear

45
Q

Name of the file used to store environment settings

A

the “bash profile”

i.e. $ nano ~/.bash_profile

When a sesion starts, it will load teh contents of the bash profile before executing commands.

46
Q

source

A

makes the changes available right away in the session we are in

47
Q

alias

A

The “alias” comnaomand allows you to create keyboard shortcuts, or aliases, for commonly used commands.

48
Q

alias hy=”history”

A

hy is set as alias for the “history” command in the bash profile. The alias is then made available in teh current session through “source”. By typing “hy”, the command line outputs a history of commands that were entered in the current session

49
Q

environment variables

A

environment variables are variables that can be used across commands and programs and hold information about the environment.

e.g. export USER=”Jane Doe”

50
Q

What command do you use to make a variable available to all child sessions initiated from the session you are in?

A

export

e.g. export USER=”Jane Doe”

51
Q

What is always used when returning a variable’s value?

A

$

52
Q

Define “PS1”

A

PS1 is a variable that defines the makeup and style of the command prompt.

Ex: export PS1=”» “ // sets the command prompt variable and exports the variable. After you use “source” command, the command line displays the new command prompt.

53
Q

Define “HOME”

A

The HOME variable is an environment variable that displays the path of the home directory.

NOTE: You can customize the HOME variable if needed, but in most cases this is not necessary.

54
Q

Define “PATH”

A

PATH is an environment variable that stores a list of directories separated by a colon.

Each directory contains scripts for the command line to execute. The PATH variable simply lists which directories contain scripts.

55
Q

env

A

The env command stands for “environment”, and returns a list of the environment variables for the current user.

56
Q

env | grep PATH

A

env | grep PATH is a command that displays the value of a single environment variable. Here the standard output of env is “piped” to the grep command. grep searches for the value of the variable PATH and outputs it to the terminal.