Shell Flashcards

https://www.datacamp.com/courses/introduction-to-shell-for-data-science

1
Q

Which command lets you find out where you are in the filesystem?

A

pwd

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

Which command lets you list the content of your directory?

A

ls

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

Which command lets you list the content of a specific directory?

A

ls /path/to/file

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

What is the conceptual difference between asbolute and relative paths?

A

An absolute path is like a latitude and longitude: it has the same value no matter where you are.

A relative path, specifies a location starting from where you are: it’s like saying “20 kilometers north”.

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

How does the shell decide if a path is relative or absolute?

A

An absolute path starts with a /.

A relative path doesn’t.

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

Which command lets you move around the filesystem?

A

cd

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

What is the parent of a directory?

A

The parent of a directory is the directory above it. For example, /home is the parent of /home/repl, and /home/repl is the parent of /home/repl/seasonal.

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

Which special path corresponds to the one above the one you’re currently in?

A

..

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

Which path is the root directory?

A

/

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

Which path corresponds to the current directory?

A

.

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

Which path corresponds to the home directory?

A

~

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

Which command lets you copy files?

A

cp path/original.txt path/duplicate.txt

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

How do you copy several files to a directory?

A

cp original1.txt original2.txt path/to/directory

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

Which command lets you move files from on directory to another?

A

mv path/to/file1.txt path/to/file2.txt path/to/directory

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

Which command lets you rename a file?

A

mv old_name.txt new_name.txt

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

Which command lets you remove files?

A

rm file/to/file1.txt file/to/file2.txt

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

What happens if you move or copy to an existing filename?

A

The original file with that filename is overwritten.

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

Which command lets you remove an empty directory?

A

rmdir directory_name

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

Which command lets you create a directory?

A

mkdir directory_name

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

Where should you store files and programs you only need briefly?

A

/temp

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

Which command lets you look at the content of files?

A

cat file1.txt file2.txt

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

When printing the content of a file, how do you go to the next page?

A

Press the spacebar

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

When printing the content of a file, how do you quit?

A

Press q

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

When printing the content of several files, how do you move to the next file?

A

Type :n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
When printing the content of several files, how do you move to the previous file?
Type :p
26
When printing the content of several files, how do you quit?
Type :q
27
Which command lets you print the first 10 lines of a csv file?
head file.csv
28
What are command-line flags?
They are a way to specify options for command-line programs. For example, head -n 5 file.csv specifies head should print 5 lines instead of the default 10.
29
By convention, where should command-line flags be placed?
By convention, command-line flags should be placed before any filenames.
30
How do you display everything that is underneath directory?
ls -R
31
When listing files, how do you make it clear which ones are directory names and which ones are runnable programs?
ls -F
32
Which command lets you obtain documentation on a specific command?
man command
33
Which command lets you display columns?
cut
34
When selecting columns, which flag lets you specify the column delimiter?
-d , | (for columns separated by commas)
35
When selecting columns, which flag lets you specify the columns or range of columns to select?
-f 1-4 7 | (columns 1 to 4 and 7)
36
When displaying the content of a file, how do you skip the first x lines?
-n +x
37
Which command lets you display a list of commands you have run recently?
history
38
How do you rerun your most recent use of a command?
!command
39
How do you rerun the xth command in your history?
!x
40
How do you display lines of files containing a specific piece of text?
grep keyword path/to/file
41
With grep, which flag lets you print a count of matching lines rather than the lines themselves?
grep -c
42
With grep, which flag lets you not print the names of the files when searching multiple files?
grep -h
43
With grep, which flag lets you ignore case?
grep -i
44
With grep, which flag lets you print the names of the files that contain the matches, rather than the matches themselves?
grep -l
45
With grep, which flag lets you print only lines that don't match?
grep -v
46
Which command lets you combine files?
paste file1.csv file2.csv
47
How do you save a command's output?
Use redirection: tail -n 5 file.csv \> last5.csv
48
Which command lets you print the number of characters, words, and lines in a file?
wc
49
Which wc flag lets you print the number of characters only?
wc -c
50
Which wc flag lets you print the number of words only?
wc -w
51
Which wc flag lets you print the number of lines only?
wc -l
52
What is a wildcard and why are they useful?
A wildcard is a character that can be used as a substitute for any of a class of characters in a search, thereby greatly increasing the flexibility and efficiency of searches.
53
Which wildcard matches 0 or more characters?
\*
54
Which wildcard matches a single character?
?
55
Which wildcard matches any one of the characters passed?
[characters]
56
Which wildcard matches any of the comma-separated patterns passed?
{pattern1, pattern2}
57
Which command lets you order values?
sort
58
Which sort flag lets you sort in numerical order instead of the default alphabetical order?
-n
59
Which sort flag lets you sort in descending order instead of the default ascending order?
-r
60
Which sort flag lets you ignore leading blanks?
-b
61
Which sort flag lets you fold case (be case-insensitive)?
-f
62
Which command lets you remove adjacent duplicated lines?
uniq
63
Which uniq flag lets you display the count of duplicated lines?
-c
64
In a command expression, where should the command writing to a file appear?
At the very beginning or at the very end.
65
How do you interrupt a runing command?
Ctrl + C
66
Which environment variable corresponds to the user's home directory?
HOME
67
Which path corresponds to HOME?
/home/repl
68
Which environment variable corresponds to the present working directory?
PWD
69
Which environment variable corresponds to the shell program being used?
SHELL
70
Which path corresponds to SHELL?
/bin/bash
71
Which environement variable corresponds to the user's ID?
USER
72
Which command lets you print the value of an environment variable?
printenv ENVIRONMENT\_VARIABLE or echo $ENVIRONMENT\_VARIABLE
73
Which command lets you display a list of all environment variables?
set
74
How do you create a shell variable?
variable=value without spaces before or after =
75
How do you print the value of a variable?
echo $variable
76
How do you define a for loop?
for *variable* in *list* **;** do *command* **;** done
77
How do you indicate a variable name instead of the name you have typed.
$ (use a dollar in front of the variable, eg echo $variable)
78
If you have filenames with spaces, how do you work around that so your command interprets filenames correctly?
Wrap filenames in single or double quotes ('' or "").
79
How do you separate several commands in the body of a for loop?
;
80
How do you open a file with nano?
nano filename
81
How do you delete a line with nano?
Ctrl + K
82
How do you undelete a line with nano?
Ctrl + U
83
How do you save the file with nano?
Ctrl + O
84
How do you exit the editor with nano?
Ctrl + X
85
How do you create a file with nano?
nano filename
86
How do you store commands so you can reuse them later?
Write commands to a .sh file. Although scripts don't have to have names ending in .sh, it's good practice as it helps keep track of which files are scripts.
87
Which command lets you execute commands contained in a .sh file?
bash name.sh
88
How do you call a file full of shell commands?
A shell script.
89
How do you provide a placeholder to a command in a script?
$@
90
How do you execute a shell script with a placeholder?
bash file.sh placeholder
91
How do you provide several placeholders to a shell script?
Use $1, $2...
92
How are several placeholders passed to a shell script?
In the order in which they appear in the bash command calling the script. You need to pay extra attention to the order of the placeholders in the script and in your commands call, to ensure you're passing the appropriate value at the appropriate placeholder.
93
How do you write loops in scripts?
Use semi-colons, or declare them on several lines without semi colon following this format: ## Footnote for value in variable do command1 command2 done Commands do not have to be indented, but doing so makes things clearer.
94
How do you add comments to a script?
Use # at the beginning of the line.
95