Unix Bash Commands I Always Forget
For my reference on the go, and perhaps yours too.
Command line keyboard shortcuts
[ctrl] + [a]move cursor to beginning
[ctrl] + [e]move cursor to end
[ctrl] + [u]delete to beginning of line
[ctrl] + [k]delete to end of line
[ctrl] + [w]delete backwards to beginning of word
[opt] + [d]delete forwards to end of word
[fn] + [delete]forward delete
Adding directory to binaries to $PATH
$HOME are environment variables.
Creating a symbolic link
Alternatively, this command compresses an entire directory or a single file on Linux, working recursively to do so.
This decompresses/extracts an archive instead.
-zuse gzip (use
-fallows us to specify input/output
Processes and Jobs
psshows execeuting processes.
jobsdoes a similar thing and also states its status.
[ctrl] + [c]kills a foreground process.
[ctrl] + [z]suspends a foreground process.
bg puts processes in the foreground and background respectively. Can be used on suspended processes.
kill terminates a suspended/background process. Syntax can be as above for jobnumber, or with process numbers (PID):
less: keyboard shortcuts
[ctrl] + [f]forwards one window
[ctrl] + [b]backwards one window
[ctrl] + [d]forwards half window
[ctrl] + [u]backwards half window
Nto move between matches
&patterndisplays only matching lines
[h]shows these shortcuts (and more)
-iignores upper/lower case in the search query
-vdisplays lines that do not match
-npreceeds the matching lines with the line number
-cprints the total count of matched lines
These can be combined. For example,
grep -ivnc fxquah test.txt returns the number of lines which do not have fxquah or Fxquah. Note that the
-n option can be omitted in this case.
This counts the numbers of users which are logged on.
cat & sort
This joins two files into a single file.
This sorts a file and outputs it into another.
This lists all the files ending with …fxquah
This lists all the files starting with one character following fxquah
find recursively descends the directory tree for each path listed to find a query. Some examples:
rread and copy files (or list files in a dir)
wchange a file (or delete/move files from dir)
xexecute (or access directory to read files)
-adds and takes away permission respectively
Example: this removes read write and execute permissions on the file for the group and others.
Storage related: quota, df, du, file
quotachecks amount of space allocated, and one’s usage.
dfreports space left.
-hoption for human readability.
-has before, and
file *classifies the chosen files by type.
Getting help: man, whatis & apropros
manfull manual page.
whatisone-line description of comment
apropos keywordreturns commands with keyword in their manual page header