General Command Line Flashcards

(148 cards)

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
# General Command Line prepend each line of `grep` output with the line number
-n ex $ grep -n rose sonnets.txt
26
# General Command Line skip to a specific line number in Less
nG goes to line number n
27
# General Command Line print a list of previously entered commands
$ history
28
# General Command Line execute your nth command from history
$ !n
29
# General Command Line option passed to mkdir so that all intermediary directories are created as necessary
-p ex $ mkdir -p add/all/these/folders
30
# General Command Line change directories to the directory you came from
$ cd -
31
# General Command Line use grep to search all files and subfolders of a folder called haystack
-r ex $ grep -r needle haystack/
32
# General Command Line behavior when including the trailing slash of a dir with `cp`
only the contents of the dir are copied; omit the slash when you want to copy the dir and its contents.
33
# General Command Line find txt files in the current directory and all subfolders
$ find . -name '\*.txt'
34
# General Command Line enter multiple commands on one line, with each additional command running only if the previous one is successful
&& ex $ git add -A && git commit -m "Add about page"
35
# General Command Line enter multiple commands on one line that run regardless of whether the previous commands were successful
; ex $ git add -A; git commit -m "Test commit"; git push
36
# General Command Line add a blank line to the end of a specific file
$ echo \>\> test.txt
37
# General Command Line print working directory
$ pwd
38
# General Command Line my computer's network name
$ hostname
39
# General Command Line make directory
$ mkdir
40
# General Command Line change directory
$ cd
41
# General Command Line list directory
$ ls
42
# General Command Line remove directory
$ rmdir
43
# General Command Line push directory
$ pushd
44
# General Command Line pop directory
$ popd
45
# General Command Line copy a file or directory
$ cp
46
# General Command Line move a file or directory
$ mv
47
# General Command Line page through a file
$ less
48
# General Command Line print the whole file
$ cat
49
# General Command Line execute arguments
$ xargs
50
# General Command Line read a manual page
$ man
51
# General Command Line find what man page is appropriate
$ apropos
52
# General Command Line look at your environment
$ env
53
# General Command Line print some arguments
$ echo
54
# General Command Line export/set a new environment variable
$ export
55
# General Command Line exit the shell
$ exit
56
# General Command Line become super user root
$ sudo
57
# General Command Line change ownership
$ chown
58
# General Command Line wildcard character that matches all characters
\*
59
# General Command Line wildcard character that matches any one character
?
60
# General Command Line wildcard character that denotes a range of characters
[] works like regex ranges only single digit range
61
# General Command Line wildcard character that expands multi-character ranges
{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
# General Command Line `find` option that specifies how many subdirectories to search
--maxdepth ex $ find . -maxdepth 1 -name 'some\*'
63
# General Command Line `find` options to run commands on multiple files
-exec [command] [-args...] {} \ ex $ find directory\_to\_backup -mtime +30 -size +500k -exec rm {} \;
64
# General Command Line execute one command within another
`command` or $(command) ex $ grep `date +%b` apache\_error\_log
65
# General Command Line sort stdout
$ sort
66
# General Command Line cut out selected portions of each line of input
$ cut
67
# General Command Line `cut` option that specifies delimiter
-d ex $ cut books -d:
68
# General Command Line `cut` option that specifies which columns to keep
-f ex $ cut -d: -f1 books
69
# General Command Line filter out repeated (consecutive) lines in input
$ uniq
70
# General Command Line `uniq` option that includes a count of a number of times the line was repeated in the input
-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
# General Command Line run a process in the background, returning control to the terminal
& ex $ rails s \> output.txt &
72
# General Command Line see a list of processes running in the background
$ jobs
73
# General Command Line bring a background process to the foreground
$ fg [number]
74
# General Command Line $ SOMETHING="something else"
create an environment variable for your current session
75
# General Command Line by editing environment files ex .bash\_profile .profile .bashrc
make more permanent changes to your environment
76
# General Command Line $PATH
environment variable that determines where the shell looks for executables
77
# 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
environment variable that determines the appearance of your prompt
78
# General Command Line chmod ex $ chmod 740 sample.txt 4 - Read 2 - Write 1 - Execute
change the permissions of a file or folder
79
# General Command Line $ Ctrl-a
jump to the beginning of the prompt
80
# General Command Line $ Ctrl-e
jump to the end of the prompt
81
# General Command Line $ Ctrl-u
clear the prompt
82
# General Command Line Option + click
use the mouse to move the cursor in the command line
83
# General Command Line write over \> append \>\> ex $ echo 'something' \> file.txt $ echo 'something else' \>\> file.txt
redirect the output from a command to a file
84
# General Command Line $ ls ../\*.txt
list all the txt files in the parent directory
85
# General Command Line execute the last command $ !! execute the last curl command $ !curl
repeat the last command
86
# General Command Line $ Ctrl-r
search through your recent commands
87
# General Command Line | ex $ head text.txt | wc
redirect the output of one command to the input of another command
88
# General Command Line $ tail -f file-name
view the last 10 lines of a file that's constantly changing (like a log file)
89
# General Command Line /
search `less` output
90
# General Command Line n
next match in `less` search
91
# General Command Line N
previous match in `less` search
92
# General Command Line 1G
beginning of `less` output
93
# General Command Line G
end of `less` output
94
# General Command Line grep ex $ grep 'needle' haystack.txt
find text within files
95
# General Command Line -i ex $ grep -i 'needle' haystack.txt
make `grep` case insensitive
96
# General Command Line $ ps aux
print a list of all processes currently running
97
# General Command Line kill ex kill -15 pid
terminate a specific process
98
# General Command Line -n ex $ grep -n rose sonnets.txt
prepend each line of `grep` output with the line number
99
# General Command Line nG goes to line number n
skip to a specific line number in Less
100
# General Command Line $ history
print a list of previously entered commands
101
# General Command Line $ !n
execute your nth command from history
102
# General Command Line -p ex $ mkdir -p add/all/these/folders
option passed to mkdir so that all intermediary directories are created as necessary
103
# General Command Line $ cd -
change directories to the directory you came from
104
# General Command Line -r ex $ grep -r needle haystack/
use grep to search all files and subfolders of a folder called haystack
105
# General Command Line only the contents of the dir are copied; omit the slash when you want to copy the dir and its contents.
behavior when including the trailing slash of a dir with `cp`
106
# General Command Line $ find . -name '\*.txt'
find txt files in the current directory and all subfolders
107
# General Command Line && ex $ git add -A && git commit -m "Add about page"
enter multiple commands on one line, with each additional command running only if the previous one is successful
108
# General Command Line ; ex $ git add -A; git commit -m "Test commit"; git push
enter multiple commands on one line that run regardless of whether the previous commands were successful
109
# General Command Line $ echo \>\> test.txt
add a blank line to the end of a specific file
110
# General Command Line $ pwd
print working directory
111
# General Command Line $ hostname
my computer's network name
112
# General Command Line $ mkdir
make directory
113
# General Command Line $ cd
change directory
114
# General Command Line $ ls
list directory
115
# General Command Line $ rmdir
remove directory
116
# General Command Line $ pushd
push directory
117
# General Command Line $ popd
pop directory
118
# General Command Line $ cp
copy a file or directory
119
# General Command Line $ mv
move a file or directory
120
# General Command Line $ less
page through a file
121
# General Command Line $ cat
print the whole file
122
# General Command Line $ xargs
execute arguments
123
# General Command Line $ man
read a manual page
124
# General Command Line $ apropos
find what man page is appropriate
125
# General Command Line $ env
look at your environment
126
# General Command Line $ echo
print some arguments
127
# General Command Line $ export
export/set a new environment variable
128
# General Command Line $ exit
exit the shell
129
# General Command Line $ sudo
become super user root
130
# General Command Line $ chown
change ownership
131
# General Command Line \*
wildcard character that matches all characters
132
# General Command Line ?
wildcard character that matches any one character
133
# General Command Line [] works like regex ranges only single digit range
wildcard character that denotes a range of characters
134
# 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
wildcard character that expands multi-character ranges
135
# General Command Line --maxdepth ex $ find . -maxdepth 1 -name 'some\*'
`find` option that specifies how many subdirectories to search
136
# General Command Line -exec [command] [-args...] {} \ ex $ find directory\_to\_backup -mtime +30 -size +500k -exec rm {} \;
`find` options to run commands on multiple files
137
# General Command Line `command` or $(command) ex $ grep `date +%b` apache\_error\_log
execute one command within another
138
# General Command Line $ sort
sort stdout
139
# General Command Line $ cut
cut out selected portions of each line of input
140
# General Command Line -d ex $ cut books -d:
`cut` option that specifies delimiter
141
# General Command Line -f ex $ cut -d: -f1 books
`cut` option that specifies which columns to keep
142
# General Command Line $ uniq
filter out repeated (consecutive) lines in input
143
# 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
`uniq` option that includes a count of a number of times the line was repeated in the input
144
# General Command Line & ex $ rails s \> output.txt &
run a process in the background, returning control to the terminal
145
# General Command Line $ jobs
see a list of processes running in the background
146
# General Command Line $ fg [number]
bring a background process to the foreground
147
# General Command Line check for available software updates
softwareupdate --list
148
# General Command Line install all available updates
softwareupdate --install --all