General Command Line Flashcards

1
Q

General Command Line

create an environment variable for your current session

A

$ SOMETHING=”something else”

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

General Command Line

make more permanent changes to your environment

A

by editing environment files

ex

.bash_profile

.profile

.bashrc

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

General Command Line

environment variable that determines where the shell looks for executables

A

$PATH

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

General Command Line

environment variable that determines the appearance of your prompt

A

$PS1

ex

$ PS1=’some custom prompt’

\u username

\w working dir

\W basename of working dir

\d current date

\n new line

\h hostname

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

General Command Line

change the permissions of a file or folder

A

chmod

ex

$ chmod 740 sample.txt

4 - Read

2 - Write

1 - Execute

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

General Command Line

jump to the beginning of the prompt

A

$ Ctrl-a

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

General Command Line

jump to the end of the prompt

A

$ Ctrl-e

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

General Command Line

clear the prompt

A

$ Ctrl-u

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

General Command Line

use the mouse to move the cursor in the command line

A

Option + click

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

General Command Line

redirect the output from a command to a file

A

write over >

append >>

ex

$ echo ‘something’ > file.txt

$ echo ‘something else’ >> file.txt

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

General Command Line

list all the txt files in the parent directory

A

$ ls ../*.txt

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

General Command Line

repeat the last command

A

execute the last command

$ !!

execute the last curl command

$ !curl

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

General Command Line

search through your recent commands

A

$ Ctrl-r

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

General Command Line

redirect the output of one command to the input of another command

A

|

ex

$ head text.txt | wc

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

General Command Line

view the last 10 lines of a file that’s constantly changing (like a log file)

A

$ tail -f file-name

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

General Command Line

search less output

A

/

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

General Command Line

next match in less search

A

n

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

General Command Line

previous match in less search

A

N

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

General Command Line

beginning of less output

A

1G

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

General Command Line

end of less output

A

G

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

General Command Line

find text within files

A

grep

ex

$ grep ‘needle’ haystack.txt

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

General Command Line

make grep case insensitive

A

-i

ex

$ grep -i ‘needle’ haystack.txt

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

General Command Line

print a list of all processes currently running

A

$ ps aux

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

General Command Line

terminate a specific process

A

kill

ex kill -15 pid

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

General Command Line

prepend each line of grep output with the line number

A

-n

ex

$ grep -n rose sonnets.txt

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

General Command Line

skip to a specific line number in Less

A

nG

goes to line number n

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

General Command Line

print a list of previously entered commands

A

$ history

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

General Command Line

execute your nth command from history

A

$ !n

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

General Command Line

option passed to mkdir so that all intermediary directories are created as necessary

A

-p

ex

$ mkdir -p add/all/these/folders

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

General Command Line

change directories to the directory you came from

A

$ cd -

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

General Command Line

use grep to search all files and subfolders of a folder called haystack

A

-r

ex

$ grep -r needle haystack/

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

General Command Line

behavior when including the trailing slash of a dir with cp

A

only the contents of the dir are copied; omit the slash when you want to copy the dir and its contents.

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

General Command Line

find txt files in the current directory and all subfolders

A

$ find . -name ‘*.txt’

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

General Command Line

enter multiple commands on one line, with each additional command running only if the previous one is successful

A

&&

ex

$ git add -A && git commit -m “Add about page”

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

General Command Line

enter multiple commands on one line that run regardless of whether the previous commands were successful

A

;

ex

$ git add -A; git commit -m “Test commit”; git push

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

General Command Line

add a blank line to the end of a specific file

A

$ echo >> test.txt

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

General Command Line

print working directory

A

$ pwd

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

General Command Line

my computer’s network name

A

$ hostname

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

General Command Line

make directory

A

$ mkdir

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

General Command Line

change directory

A

$ cd

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

General Command Line

list directory

A

$ ls

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

General Command Line

remove directory

A

$ rmdir

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

General Command Line

push directory

A

$ pushd

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

General Command Line

pop directory

A

$ popd

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

General Command Line

copy a file or directory

A

$ cp

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

General Command Line

move a file or directory

A

$ mv

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

General Command Line

page through a file

A

$ less

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

General Command Line

print the whole file

A

$ cat

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

General Command Line

execute arguments

A

$ xargs

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

General Command Line

read a manual page

A

$ man

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

General Command Line

find what man page is appropriate

A

$ apropos

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

General Command Line

look at your environment

A

$ env

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

General Command Line

print some arguments

A

$ echo

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

General Command Line

export/set a new environment variable

A

$ export

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

General Command Line

exit the shell

A

$ exit

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

General Command Line

become super user root

A

$ sudo

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

General Command Line

change ownership

A

$ chown

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

General Command Line

wildcard character that matches all characters

A

*

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

General Command Line

wildcard character that matches any one character

A

?

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

General Command Line

wildcard character that denotes a range of characters

A

[]

works like regex ranges

only single digit range

61
Q

General Command Line

wildcard character that expands multi-character ranges

A

{x..y}

ex

$ ls

file_1 file_2 file_3 … file_78

$ rm file_{1..20}

$ ls

file_21 … file_78

ex

$ ls

file.txt file.pdf file.pl file.odf

$ rm file.{txt,pdf,odf}

$ ls file.pl

62
Q

General Command Line

find option that specifies how many subdirectories to search

A

–maxdepth

ex

$ find . -maxdepth 1 -name ‘some*’

63
Q

General Command Line

find options to run commands on multiple files

A

-exec [command] [-args…] {} \

ex

$ find directory_to_backup -mtime +30 -size +500k -exec rm {} \;

64
Q

General Command Line

execute one command within another

A

command or $(command)

ex

$ grep date +%b apache_error_log

65
Q

General Command Line

sort stdout

A

$ sort

66
Q

General Command Line

cut out selected portions of each line of input

A

$ cut

67
Q

General Command Line

cut option that specifies delimiter

A

-d

ex

$ cut books -d:

68
Q

General Command Line

cut option that specifies which columns to keep

A

-f

ex

$ cut -d: -f1 books

69
Q

General Command Line

filter out repeated (consecutive) lines in input

A

$ uniq

70
Q

General Command Line

uniq option that includes a count of a number of times the line was repeated in the input

A

-c

ex

$ cut -d: -f1 books | sort | grep “, John” | uniq -c

1 Bartlett, John

2 Bunyan, John

3 Mill, John Stuart

1 Milton, John

71
Q

General Command Line

run a process in the background, returning control to the terminal

A

&

ex

$ rails s > output.txt &

72
Q

General Command Line

see a list of processes running in the background

A

$ jobs

73
Q

General Command Line

bring a background process to the foreground

A

$ fg [number]

74
Q

General Command Line

$ SOMETHING=”something else”

A

create an environment variable for your current session

75
Q

General Command Line

by editing environment files

ex

.bash_profile

.profile

.bashrc

A

make more permanent changes to your environment

76
Q

General Command Line

$PATH

A

environment variable that determines where the shell looks for executables

77
Q

General Command Line

$PS1

ex

$ PS1=’some custom prompt’

\u username

\w working dir

\W basename of working dir

\d current date

\n new line

\h hostname

A

environment variable that determines the appearance of your prompt

78
Q

General Command Line

chmod

ex

$ chmod 740 sample.txt

4 - Read

2 - Write

1 - Execute

A

change the permissions of a file or folder

79
Q

General Command Line

$ Ctrl-a

A

jump to the beginning of the prompt

80
Q

General Command Line

$ Ctrl-e

A

jump to the end of the prompt

81
Q

General Command Line

$ Ctrl-u

A

clear the prompt

82
Q

General Command Line

Option + click

A

use the mouse to move the cursor in the command line

83
Q

General Command Line

write over >

append >>

ex

$ echo ‘something’ > file.txt

$ echo ‘something else’ >> file.txt

A

redirect the output from a command to a file

84
Q

General Command Line

$ ls ../*.txt

A

list all the txt files in the parent directory

85
Q

General Command Line

execute the last command

$ !!

execute the last curl command

$ !curl

A

repeat the last command

86
Q

General Command Line

$ Ctrl-r

A

search through your recent commands

87
Q

General Command Line

|

ex

$ head text.txt | wc

A

redirect the output of one command to the input of another command

88
Q

General Command Line

$ tail -f file-name

A

view the last 10 lines of a file that’s constantly changing (like a log file)

89
Q

General Command Line

/

A

search less output

90
Q

General Command Line

n

A

next match in less search

91
Q

General Command Line

N

A

previous match in less search

92
Q

General Command Line

1G

A

beginning of less output

93
Q

General Command Line

G

A

end of less output

94
Q

General Command Line

grep

ex

$ grep ‘needle’ haystack.txt

A

find text within files

95
Q

General Command Line

-i

ex

$ grep -i ‘needle’ haystack.txt

A

make grep case insensitive

96
Q

General Command Line

$ ps aux

A

print a list of all processes currently running

97
Q

General Command Line

kill

ex kill -15 pid

A

terminate a specific process

98
Q

General Command Line

-n

ex

$ grep -n rose sonnets.txt

A

prepend each line of grep output with the line number

99
Q

General Command Line

nG

goes to line number n

A

skip to a specific line number in Less

100
Q

General Command Line

$ history

A

print a list of previously entered commands

101
Q

General Command Line

$ !n

A

execute your nth command from history

102
Q

General Command Line

-p

ex

$ mkdir -p add/all/these/folders

A

option passed to mkdir so that all intermediary directories are created as necessary

103
Q

General Command Line

$ cd -

A

change directories to the directory you came from

104
Q

General Command Line

-r

ex

$ grep -r needle haystack/

A

use grep to search all files and subfolders of a folder called haystack

105
Q

General Command Line

only the contents of the dir are copied; omit the slash when you want to copy the dir and its contents.

A

behavior when including the trailing slash of a dir with cp

106
Q

General Command Line

$ find . -name ‘*.txt’

A

find txt files in the current directory and all subfolders

107
Q

General Command Line

&&

ex

$ git add -A && git commit -m “Add about page”

A

enter multiple commands on one line, with each additional command running only if the previous one is successful

108
Q

General Command Line

;

ex

$ git add -A; git commit -m “Test commit”; git push

A

enter multiple commands on one line that run regardless of whether the previous commands were successful

109
Q

General Command Line

$ echo >> test.txt

A

add a blank line to the end of a specific file

110
Q

General Command Line

$ pwd

A

print working directory

111
Q

General Command Line

$ hostname

A

my computer’s network name

112
Q

General Command Line

$ mkdir

A

make directory

113
Q

General Command Line

$ cd

A

change directory

114
Q

General Command Line

$ ls

A

list directory

115
Q

General Command Line

$ rmdir

A

remove directory

116
Q

General Command Line

$ pushd

A

push directory

117
Q

General Command Line

$ popd

A

pop directory

118
Q

General Command Line

$ cp

A

copy a file or directory

119
Q

General Command Line

$ mv

A

move a file or directory

120
Q

General Command Line

$ less

A

page through a file

121
Q

General Command Line

$ cat

A

print the whole file

122
Q

General Command Line

$ xargs

A

execute arguments

123
Q

General Command Line

$ man

A

read a manual page

124
Q

General Command Line

$ apropos

A

find what man page is appropriate

125
Q

General Command Line

$ env

A

look at your environment

126
Q

General Command Line

$ echo

A

print some arguments

127
Q

General Command Line

$ export

A

export/set a new environment variable

128
Q

General Command Line

$ exit

A

exit the shell

129
Q

General Command Line

$ sudo

A

become super user root

130
Q

General Command Line

$ chown

A

change ownership

131
Q

General Command Line

*

A

wildcard character that matches all characters

132
Q

General Command Line

?

A

wildcard character that matches any one character

133
Q

General Command Line

[]

works like regex ranges

only single digit range

A

wildcard character that denotes a range of characters

134
Q

General Command Line

{x..y}

ex

$ ls

file_1 file_2 file_3 … file_78

$ rm file_{1..20}

$ ls

file_21 … file_78

ex

$ ls

file.txt file.pdf file.pl file.odf

$ rm file.{txt,pdf,odf}

$ ls file.pl

A

wildcard character that expands multi-character ranges

135
Q

General Command Line

–maxdepth

ex

$ find . -maxdepth 1 -name ‘some*’

A

find option that specifies how many subdirectories to search

136
Q

General Command Line

-exec [command] [-args…] {} \

ex

$ find directory_to_backup -mtime +30 -size +500k -exec rm {} \;

A

find options to run commands on multiple files

137
Q

General Command Line

command or $(command)

ex

$ grep date +%b apache_error_log

A

execute one command within another

138
Q

General Command Line

$ sort

A

sort stdout

139
Q

General Command Line

$ cut

A

cut out selected portions of each line of input

140
Q

General Command Line

-d

ex

$ cut books -d:

A

cut option that specifies delimiter

141
Q

General Command Line

-f

ex

$ cut -d: -f1 books

A

cut option that specifies which columns to keep

142
Q

General Command Line

$ uniq

A

filter out repeated (consecutive) lines in input

143
Q

General Command Line

-c

ex

$ cut -d: -f1 books | sort | grep “, John” | uniq -c

1 Bartlett, John

2 Bunyan, John

3 Mill, John Stuart

1 Milton, John

A

uniq option that includes a count of a number of times the line was repeated in the input

144
Q

General Command Line

&

ex

$ rails s > output.txt &

A

run a process in the background, returning control to the terminal

145
Q

General Command Line

$ jobs

A

see a list of processes running in the background

146
Q

General Command Line

$ fg [number]

A

bring a background process to the foreground

147
Q

General Command Line

check for available software updates

A

softwareupdate –list

148
Q

General Command Line

install all available updates

A

softwareupdate –install –all