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
?