2. Codecademy: Learn the Command Line Flashcards
(Left angle bracket)
Redirect standard output to a command.
For some reason, the app is deleting the actual less than symbol, also referred to as the left angle bracket
’ > ‘
Redirect standard output of a command to a file, overwriting its previous contents.
’»_space; ‘
Redirect standard output of a command, appending original contents of a file.
’ | ‘
Pipe symbol; Redirect standard output of a command to another command.
*
The asterisk acts as a wildcard to select files and directories.
(E.g., cp m*.txt Movies/ copies all .txt files stating with the letter ‘m’ into the Movies/ directory)
wc
Output number of lines, words, and characters
sort
Order the contents of the standard input alphabetically for the standard output.
uniq
Filter out adjacent, duplicate lines in a file.
(best used in a pipeline with ‘sort’ e.g.,
$sort deserts.txt | uniq
which sorts the contents of desert.txt alphabetically, making duplicates adjacent and filtering them out of the output of the uniq command)
-r or -R
Meaning “recursive,” when following a command it acts as an option
(See rm -r and grep -R)
ls -a
List all files and directories in the working directory, including any hidden files (files starting with ‘ . ‘ are hidden by default)
ls -l
List all files and directories in long format
ls -t
List all files and directories by date last modified
ls -alt
List all files and directories, including hidden files, in long format, by date last modified
(ls options can be combined in any combination, e.g., ls -al, ls -at, ls -lt)
rm -r
Remove directory and all of its contents (permanently!!)
-i
disregard case/case insensitive
grep -R
Search all files in a directory and output file names and lines containing matched results.
grep -Rl
Search all files in a directory and output only file names with matched results.
sed
Stands for “stream editor.” Accepts, modifies, then prints standard input based on an expression containing other commands.
(See ‘s’ and ‘g’)
s
sed expression meaning substitute ‘this string’ of the standard input for ‘that string’ in the standard output. (Only substitutes first instance of ‘this string’ unless ‘g’ expression is used).
(using the following syntax: sed s/this/that filename
e.g., sed s/snow/rain forests.txt)
g
sed expression meaning global or search globally
e.g., $sed s/snow/rain/g forests.txt
Redirection
Reroutes standard input, standard output and standard error
using commands including >, >, |, etc
nano
a command line text editor
Type nano followed by the filename you would like to open; if filename does not exist a new file will be created
~
The tilde symbol represents the user’s home directory.
.
Files starting with ‘ . ‘ are hidden files.
USER
Environment variable that denotes computer owner’s name or current user
PS1
Environment variable that defines the makeup and style of the command prompt
(default ends with $)
PATH
Environment variable that lists which directories contain scripts.
du
print the disk usage of a directory
du -h
print list of sizes of subdirectories in a directory in ‘human readable format’
du -sh
print the total size of directory in ‘HRF’
du - a
du -a print list of the sizes of all files/directories
du -ah
print list of sizes of all files/directories in HRF
Ctrl + a
Move cursor to front of line
Ctrl + e
Move cursor to end of line
Ctrl + u
Clear current line
Ctrl + l
Clear terminal window (not history)
Toggle previous commands
Up and Down arrow keys