Last active
April 24, 2020 23:26
-
-
Save fathergoose/9d6b9d5bf898240cc3bf0445b36f1863 to your computer and use it in GitHub Desktop.
The bare essentials to shell navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I have forked a much more complete cheat sheet, but is complete at the expense of being accessable | |
# You can find that bigger cheat sheet here https://gist.github.com/fathergoose/3fbc3b5f6c0ba3cbe367b18030b39aba | |
# things in <angleBrackts> are variables to be replaced for a spcific instance of the command | |
# Getting Help | |
man <command> # Read the man(ual) page entry for a given command (detailed help) | |
<command> --help # This *usually* prints a short summary of a command's options and arguments | |
# Directories | |
pwd # tells you where you currently are | |
cd # changes to home | |
cd <dirname> # changes directory dirname | |
mkdir <dirname> # make a new directory | |
# Files | |
ls # lists your files | |
ls -l # lists your files in 'long format', which contains the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified | |
ls -a # lists all files, including hidden files | |
ln -s <filename> <link> # creates symbolic link to file | |
touch <filename> # creates or updates timestamp on file | |
cat <filename> # output the contents of filename | |
mv <filename1> <filename2> # moves a file | |
cp <filename1> <filename2> # copies a file | |
rm <filename> # removes a file | |
chmod -options <filename> # lets you change the read, write, and execute permissions on your files | |
grep <pattern> <filenames> # looks for the string in the files | |
grep -r <pattern> <dir> # search recursively for pattern in directory | |
less <filename> # page though a file (read-only) | |
<command> | less # page though the standard output | |
nano <filename> # edit or create file; very simple and striaght-forward editor | |
vi <filename> # edit or create file; very confusing and life-changingly powerful editor | |
# Redirection | |
cmd1|cmd2 # pipe; takes standard output of cmd1 as standard input to cmd2 | |
> file # directs standard output to file | |
< file # takes standard input from file | |
>> file # directs standard output to file; append to file if it already exists | |
<> file # uses file as both standard input and standard output | |
# Know your shell | |
which <command> # show the location of comamnd being envoked | |
env # show list of all environment variables | |
varname=value # defines a variable | |
export VARIABLE=<value> # assign an environment variable (available to subprocesses) | |
echo $VARIABLE # show the value of VARIABLE | |
alias ls="ls -la" # assign `ls` to run `ls -la` everytime it is called | |
source <file> # read and execute contents of file as a bash script | |
# The default order for command lookup is functions, followed by built-ins, with scripts and executables last. | |
# There are three built-ins that you can use to override this order: `command`, `builtin` and `enable`. | |
command # removes alias and function lookup. Only built-ins and commands found in the search path are executed | |
builtin # looks up only built-in commands, ignoring functions and commands found in PATH | |
enable # enables and disables shell built-ins | |
# Shortcuts | |
# Many more than listed | |
CTRL+A # move to beginning of line | |
CTRL+B # moves backward one character | |
CTRL+C # halts the current command | |
CTRL+D # deletes one character backward or logs out of current session, similar to exit | |
CTRL+E # moves to end of line | |
CTRL+F # moves forward one character | |
CTRL+K # deletes (kill) forward to end of line | |
CTRL+U # kills backward from point to the beginning of line | |
CTRL+L # clears screen and redisplay the line | |
CTRL+Z # stops the current command, resume with fg in the foreground or bg in the background | |
# History | |
history # shows a list of previously run commands | |
!! # execute the last command | |
!n # execute command number n (numbers found in history command) | |
CTRL+N # next line in command history | |
CTRL+O # same as RETURN, then displays next line in history file | |
CTRL+P # previous line in command history | |
CTRL+R # searches backward | |
# SSH, System Processes & Network Commands | |
ssh user@host # connects to host as user | |
ssh -p <port> user@host # connects to host on specified port as user | |
ssh-copy-id user@host # adds your ssh key to host for user to enable a keyed or passwordless login | |
ifconfig # display network configuration information (like what your ip address is) | |
ping <host> # pings host and outputs results | |
wget <file> # downloads file, can be a web address like https://somesite.com/somefile.pdf | |
ps -u yourusername # lists your processes | |
ps -axu # list all processes and owners | |
kill <PID> # kills (ends) the processes with the ID you gave | |
killall <processname> # kill all processes with the name | |
top # displays your currently active processes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment