General Command Line Flashcards
General Command Line
create an environment variable for your current session
$ SOMETHING=”something else”
General Command Line
make more permanent changes to your environment
by editing environment files
ex
.bash_profile
.profile
.bashrc
General Command Line
environment variable that determines where the shell looks for executables
$PATH
General Command Line
environment variable that determines the appearance of your prompt
$PS1
ex
$ PS1=’some custom prompt’
\u username
\w working dir
\W basename of working dir
\d current date
\n new line
\h hostname
General Command Line
change the permissions of a file or folder
chmod
ex
$ chmod 740 sample.txt
4 - Read
2 - Write
1 - Execute
General Command Line
jump to the beginning of the prompt
$ Ctrl-a
General Command Line
jump to the end of the prompt
$ Ctrl-e
General Command Line
clear the prompt
$ Ctrl-u
General Command Line
use the mouse to move the cursor in the command line
Option + click
General Command Line
redirect the output from a command to a file
write over >
append >>
ex
$ echo ‘something’ > file.txt
$ echo ‘something else’ >> file.txt
General Command Line
list all the txt files in the parent directory
$ ls ../*.txt
General Command Line
repeat the last command
execute the last command
$ !!
execute the last curl command
$ !curl
General Command Line
search through your recent commands
$ Ctrl-r
General Command Line
redirect the output of one command to the input of another command
|
ex
$ head text.txt | wc
General Command Line
view the last 10 lines of a file that’s constantly changing (like a log file)
$ tail -f file-name
General Command Line
search less
output
/
General Command Line
next match in less
search
n
General Command Line
previous match in less
search
N
General Command Line
beginning of less
output
1G
General Command Line
end of less
output
G
General Command Line
find text within files
grep
ex
$ grep ‘needle’ haystack.txt
General Command Line
make grep
case insensitive
-i
ex
$ grep -i ‘needle’ haystack.txt
General Command Line
print a list of all processes currently running
$ ps aux
General Command Line
terminate a specific process
kill
ex kill -15 pid
General Command Line
prepend each line of grep
output with the line number
-n
ex
$ grep -n rose sonnets.txt
General Command Line
skip to a specific line number in Less
nG
goes to line number n
General Command Line
print a list of previously entered commands
$ history
General Command Line
execute your nth command from history
$ !n
General Command Line
option passed to mkdir so that all intermediary directories are created as necessary
-p
ex
$ mkdir -p add/all/these/folders
General Command Line
change directories to the directory you came from
$ cd -
General Command Line
use grep to search all files and subfolders of a folder called haystack
-r
ex
$ grep -r needle haystack/
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.
General Command Line
find txt files in the current directory and all subfolders
$ find . -name ‘*.txt’
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”
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
General Command Line
add a blank line to the end of a specific file
$ echo >> test.txt
General Command Line
print working directory
$ pwd
General Command Line
my computer’s network name
$ hostname
General Command Line
make directory
$ mkdir
General Command Line
change directory
$ cd
General Command Line
list directory
$ ls
General Command Line
remove directory
$ rmdir
General Command Line
push directory
$ pushd
General Command Line
pop directory
$ popd
General Command Line
copy a file or directory
$ cp
General Command Line
move a file or directory
$ mv
General Command Line
page through a file
$ less
General Command Line
print the whole file
$ cat
General Command Line
execute arguments
$ xargs
General Command Line
read a manual page
$ man
General Command Line
find what man page is appropriate
$ apropos
General Command Line
look at your environment
$ env
General Command Line
print some arguments
$ echo
General Command Line
export/set a new environment variable
$ export
General Command Line
exit the shell
$ exit
General Command Line
become super user root
$ sudo
General Command Line
change ownership
$ chown
General Command Line
wildcard character that matches all characters
*
General Command Line
wildcard character that matches any one character
?
General Command Line
wildcard character that denotes a range of characters
[]
works like regex ranges
only single digit range
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
General Command Line
find
option that specifies how many subdirectories to search
–maxdepth
ex
$ find . -maxdepth 1 -name ‘some*’
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 {} \;
General Command Line
execute one command within another
command
or $(command)
ex
$ grep date +%b
apache_error_log
General Command Line
sort stdout
$ sort
General Command Line
cut out selected portions of each line of input
$ cut
General Command Line
cut
option that specifies delimiter
-d
ex
$ cut books -d:
General Command Line
cut
option that specifies which columns to keep
-f
ex
$ cut -d: -f1 books
General Command Line
filter out repeated (consecutive) lines in input
$ uniq
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
General Command Line
run a process in the background, returning control to the terminal
&
ex
$ rails s > output.txt &
General Command Line
see a list of processes running in the background
$ jobs
General Command Line
bring a background process to the foreground
$ fg [number]
General Command Line
$ SOMETHING=”something else”
create an environment variable for your current session
General Command Line
by editing environment files
ex
.bash_profile
.profile
.bashrc
make more permanent changes to your environment
General Command Line
$PATH
environment variable that determines where the shell looks for executables
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
General Command Line
chmod
ex
$ chmod 740 sample.txt
4 - Read
2 - Write
1 - Execute
change the permissions of a file or folder
General Command Line
$ Ctrl-a
jump to the beginning of the prompt
General Command Line
$ Ctrl-e
jump to the end of the prompt
General Command Line
$ Ctrl-u
clear the prompt
General Command Line
Option + click
use the mouse to move the cursor in the command line
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
General Command Line
$ ls ../*.txt
list all the txt files in the parent directory
General Command Line
execute the last command
$ !!
execute the last curl command
$ !curl
repeat the last command
General Command Line
$ Ctrl-r
search through your recent commands
General Command Line
|
ex
$ head text.txt | wc
redirect the output of one command to the input of another command
General Command Line
$ tail -f file-name
view the last 10 lines of a file that’s constantly changing (like a log file)
General Command Line
/
search less
output
General Command Line
n
next match in less
search
General Command Line
N
previous match in less
search
General Command Line
1G
beginning of less
output
General Command Line
G
end of less
output
General Command Line
grep
ex
$ grep ‘needle’ haystack.txt
find text within files
General Command Line
-i
ex
$ grep -i ‘needle’ haystack.txt
make grep
case insensitive
General Command Line
$ ps aux
print a list of all processes currently running
General Command Line
kill
ex kill -15 pid
terminate a specific process
General Command Line
-n
ex
$ grep -n rose sonnets.txt
prepend each line of grep
output with the line number
General Command Line
nG
goes to line number n
skip to a specific line number in Less
General Command Line
$ history
print a list of previously entered commands
General Command Line
$ !n
execute your nth command from history
General Command Line
-p
ex
$ mkdir -p add/all/these/folders
option passed to mkdir so that all intermediary directories are created as necessary
General Command Line
$ cd -
change directories to the directory you came from
General Command Line
-r
ex
$ grep -r needle haystack/
use grep to search all files and subfolders of a folder called haystack
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
General Command Line
$ find . -name ‘*.txt’
find txt files in the current directory and all subfolders
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
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
General Command Line
$ echo >> test.txt
add a blank line to the end of a specific file
General Command Line
$ pwd
print working directory
General Command Line
$ hostname
my computer’s network name
General Command Line
$ mkdir
make directory
General Command Line
$ cd
change directory
General Command Line
$ ls
list directory
General Command Line
$ rmdir
remove directory
General Command Line
$ pushd
push directory
General Command Line
$ popd
pop directory
General Command Line
$ cp
copy a file or directory
General Command Line
$ mv
move a file or directory
General Command Line
$ less
page through a file
General Command Line
$ cat
print the whole file
General Command Line
$ xargs
execute arguments
General Command Line
$ man
read a manual page
General Command Line
$ apropos
find what man page is appropriate
General Command Line
$ env
look at your environment
General Command Line
$ echo
print some arguments
General Command Line
$ export
export/set a new environment variable
General Command Line
$ exit
exit the shell
General Command Line
$ sudo
become super user root
General Command Line
$ chown
change ownership
General Command Line
*
wildcard character that matches all characters
General Command Line
?
wildcard character that matches any one character
General Command Line
[]
works like regex ranges
only single digit range
wildcard character that denotes a range of characters
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
General Command Line
–maxdepth
ex
$ find . -maxdepth 1 -name ‘some*’
find
option that specifies how many subdirectories to search
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
General Command Line
command
or $(command)
ex
$ grep date +%b
apache_error_log
execute one command within another
General Command Line
$ sort
sort stdout
General Command Line
$ cut
cut out selected portions of each line of input
General Command Line
-d
ex
$ cut books -d:
cut
option that specifies delimiter
General Command Line
-f
ex
$ cut -d: -f1 books
cut
option that specifies which columns to keep
General Command Line
$ uniq
filter out repeated (consecutive) lines in input
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
General Command Line
&
ex
$ rails s > output.txt &
run a process in the background, returning control to the terminal
General Command Line
$ jobs
see a list of processes running in the background
General Command Line
$ fg [number]
bring a background process to the foreground
General Command Line
check for available software updates
softwareupdate –list
General Command Line
install all available updates
softwareupdate –install –all