Commands Flashcards
What is the “less” utility
A pager
What is the copy file command
cp sourceFilepath destinationFilepath
How do you rename a file
mv
How do you move a file
mv sourceFilepath destinationDirectory
How do you compare files
diff -u file1 file2
What is the wc command
Word count
What is the command that compresses multiple files for linux systems
tar
Why is it called “tar”
Short for “tape archive”, this command used to be only for creating and reading archive and backup tapes
How do you find the full pathname of the file in your PATH of a non-builtin utility
which utilityToFind
What does the “which” command do
Returns the first pathname found in the directories of $PATH of a utility you provide as an argument
How do you look for files related to a non-builtin utility in standard locations
whereis filesToFind
What does the “whereis” command do
Searches standard locations (instead of $PATH directories) for files relating to a utility you specify
How do you find files using a keyword as to loosely match filenames to
locate keywordOfFilenamesToLooselyMatch
What does the “locate” command do
Finds loosely matched filenames and returns their filepath
What are the 3 commands to see who is using the system
w
who
finger
Which “who” command shows system usage information
w
Which “who” command displays the least amount of information
who
Which “who” command displays the most human profile information
finger
Which command shows system memory information
free
What does the “free” command do
Shows system memory information
How do you write to a user
write userToSendTo
How do you enable messaging
mesg y
What is the “ls” option to show hidden files
-a
What does the “pwd” command do
Prints the current working directory
How do you print the current working directory
pwd
What command makes a new directory
mkdir nameWithOptionalPath
What does “mkdir” do
Makes a new directory
What command changes your directory
cd absoluteOrRelativePath
How do you remove a directory
rmdir pathOfDirectoryToRemove; the directory must be empty.
You can use rm -r to recursively delete the contents of a directory, but making a mistake can be disasterous
What does “rmdir” do
Removes a directory
What does “chmod” do
Changes permissions of a file
How do you change permissions of a file
chmod newPermissions fileToChange
The “cat” command without arguments will start concatenating a string that you type, and includes newlines. How do you finish this?
ctrl-d (end of file)
What do the >, <, and > > symbols do
Redirection
Which is the redirect output symbol
>
Which is the redirect input symbol
<
In BASH, how do you enable and disable overwriting files via redirection
disable:
set -o noclobber
enable
set +o noclobber
Which is the append output symbol
> >
How do you append the end of a file
> >
What is > > called
The Append Output Symbol
What file is the black hole for output, and what is this called
/dev/null
Data Sink / Bit Bucket
What is the difference between redirection and pipelines
Pipelines do everything in memory with no need for files
You can “cat” files and pipe them into another utility, but what is a better way
Use Redirect Input Symbol
commandToUse < fileToReadFrom
Can any command be used as a filter
No
How can you split a command to write to a file and also provide Standard Output
commandGivingOutput | tee pathnameToWriteTo | commandToReceiveOutput
Why is it called “tee”
The letter like a pipeline splitting “T”
How do you run a Job in the background
End the command-line with & (right before you hit Enter)
How do you put a suspended foreground Job into the background and restart it
bg numberOfJobToRestartOrOptionalIfOnlyOne
How do you bring a background job to the foreground
fg numberOfJobOrOptionalIfOnlyOne
OR
% numberOfJobOrOptionalIfOnlyOne
What does “ps” stand for
Process Status
How do you get all of the current background processes
ps
What are PIDs
Process IDs
What command shows what shell youre running
echo $0 (zero)
or
echo $SHELL
How do you delete a word in the terminal
ctrl+w
How do you suspend a program
ctrl-z
How do you delete a line in the terminal
ctrl-u OR ctrl-x
How do you terminate a program
ctrl-c OR [delete]
How do you send a QUIT command from the terminal
ctrl-\
What command displays all current jobs running
jobs
How do you suspend a specific job
If the job number is 3, it is:
kill %3
How do you run the previous command with substitutions
^old^new^
What is stored in !$
The last token (word) of the last command
How do you get the last token (word) of the last command
It’s stored in !$
How do you run a single command using root privs
su -c ‘command’
How do you spawn a new shell with root privs, and how do you close it
su
exit
What is the typical symbol for prompts, and what is it for root privileges
$, and #
What is the syntax for sudo for one command and for multiple
One command:
sudo command
Multiple:
sudo -s
How do you try to find a command
apropos keywordToSearchShortDescriptionsOfManPages
Instead of using the “man” command, how can you get info on a utility
utilityToGetHelpOn - -help
some times you instead use “-h” or “-help”
you often need to pipe this to “less”
What is the remove file command and what is the safe option
rm -i
What are the 2 main sort options
-u, unique
-n, numeric order for numbers
What does the “uniq” command do
Reads a file and skips identical, adjacent lines; often used with “sort” to remove all duplicates
How do you refer to a job number
%jobNumber
wtf is globbing
using wildcards … :(
What are wildcards also called
Special Characters
Meta-characters
Ambiguous File References (for the whole string)
What does the ? special character mean
It is like *, but specifically 1 character (not 0 or many)
What do the special characters [ ] mean
its like ?, but more restrictive in that the characters within the brackets define a set or range of acceptable characters
How do you define a range
use square brackets and a dash between the start and end
[a-z] (all lowercase letters)
[0-9] (all numbers)
[a-zA-Z] (all letters)
What is ^ called
A caret
How do you negate a set/range
have ^ or ! be at the beginning, like:
[!1-3] (not 1, 2, or 3)
How do you list the BASH builtins
info bash
How do you translate contents
tr charsFrom charsTo
What are the 2 vim modes
- Command/Normal Mode
- Insert Mode
How do you delete a character, a word, and a line in vim
x, dw, dd
What are the 3 ending options for “find”
- -exec
- -ok (same as exec but safe mode via prompting)
What are the 15 options for “find”
- -name
- -perm
- -prune
- -user / -nouser
- -group / -nogroup
- -mtime
- -type
- -newer
- -size
- -depth
- -fstype
- -mount
- -follow
- -cpio
- local
What are the 6 arguments for the -type option of “find”
- b (block)
- d (directory)
- c (character)
- p (pipe)
- l (symbolic link)
- f (ordinary)
What does “-o” do for the “find” command
It’s a logical OR
What unit of time is the “-mtime” option for on the “find” command
Days … not sure why they didnt just name it -days
How do you set a range for the “-newer” option of “find”
-newer latestFileModified !-newer newestFileModified
When using “find”, what type of file traversal does it perform
Breadth-first
What do a lot of systems restrict for the -exec command option on “find”
You can only use “ls -l”
What is a common but dangerous -exec command for “find”
Removing files … make sure you “ls -l” instead first to make sure its what you mean to delete, or just replace -exec with -ok to prompt each removal (if the list isnt too big)
What is the -exec syntax for “find”
-print -exec commandToRun {} \;
What is using ~ for a pathname synonymous with
$HOME
What is a limit of using -exec for “find” and what is the solution
The command is not executed until “find” is finished, potentially resulting in a memory limit being reached and the command terminated
You can instead pipe the -print of “find” to “xargs”, which runs in batches instead
What does grep stand for
Global Regular Expression Print