The shell takes commands and executes them against the operating system. The terminal is a program that wraps the shell. This list includes common commands and scripts for learning more about navigating the terminal.
This Repo is a resource for Terminal and Shell command scripting. To make a contribution to this directory, please make a pull request. Requests will be reviewed in the order received.
- Clear the window: ( control + l )
- Also clears the window:
clear
- Open a new window vertical: ( cmd + t )
- Open another vertical window: ( cmd + d )
- Open a horizontal window: ( shift + cmd + d )
- Delete a window: ( cmd + w )
- How to delete one word at a time going forwards: ( option + d )
- How to delete one word at a time going backwards: ( option + backspace )
- Navigate to the beginning of a line in terminal: ( control + a )
- Navigate to the end of a line in terminal: ( control + e )
- How to scroll up and down in the window: ( shift + arrow buttons )
- How to get out of vi: ( cmd + :q! )
- How to move cursor forwards or backwards over text to delete or just move back: ( command + b )
- iTerm recommended by developers as a better terminal
[download iTerm]("https://iterm2.com/downloads.html") - How to check if you're using bash or zsh: in the iTerm window
echo $SHELL
- ** zsh ** everything applicable to zsh is applicable to bash.
- How to change from bash to zsh: in the iTerm window
chsh -s /bin/zsh
- How to install Oh My ZSH
` sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" `
- Get the docs for Oh My ZSH:
vi .zshrc
- [customizing your Oh MY zsh theme](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes)
- How to access the manual page... this will work for any command to learn more info about how each command works
man
- "What manual page do you want?"
man
+ ( command ) type man and the command you want the manual for - type
q
to exit/quit
- start typing a file name then press ( tab ) to finish the file name
date
gives the current date and timecal
shows your calender add the year ex:cal 2022
for full years calenderwhoami
gives the user namehistory
gives the history of all terminal commands ran and a number for each one!155
to run that command againhistory | grep "grep"
shows the history of the grep command!!
gives you the previous command ran in the terminal^rep^grep
replaces rep with grep in the last command ran
.
your current directorypwd
gets working path directoryls
shows the contents inside of the current working directoryls -a
shows files that begin with a "."ls -al
shows more details about the filescd
change directory/file/foldercd ~
go back to the root directorycd ..
go back one level in the directorycd ../..
go back two levels, keep chaining on /.. for more levelscd -
go back to the previous foldermkdir
( + file_name ) makes a new file in whatever directory you are currently inmkdir -p
( + file_name/another_file/one_more_file ) creates sub directoriesrm + -rf
( + file_name ) removes a file and it's root directory CAN NOT BE UNDONEmv
( + file_1 + file_2 ) moves file_1 inside of file_2tree -- help
to see tree commands, will need to install tree with Homebrewmv
( rename_this + new_file_name ) How to give your file a new name
touch
( my_file.py ) creates a new my_file.py filerm
( file_name* ) removes any file that starts with "file_name"echo
prints the specified text string before listing of all the files in the current working directory- ( > ) override
- ( >> ) append
cat
( + file_name ) view the contents of your fileless
( + file_name ) view less of the content, press spacebar to paginate over the file contentshead
( + file_name ) view the first 10 lines of the file contentstail
( + file_name ) view the last 10 lines of the contentscp
( + file_to_copy + new_file_name ) copies the contents of one file to a new filecp
( * .file_extension + folder_name ) moves all files with this file extension to the specified folder.cp -r
( * folder_name + new_folder ) moves all folders to a new folderfind .
lists every file in the current working foldersfind . -type f -name file_name.ext
finds the specified file/s sub -iname in place of -name to ignore the case sensitivity if files add -delete to remove the file insteadfind . -type f -name "*.ext"
finds all files with the specified extensionfind . -type f -empty
finds all of the empty files remove -type to find all empty folders
man grep
to get the manual for this command grep stands for, global regular expression print works with both folders and filesgrep -r
( + "REGEX Goes here" + file_name ) and is used to search recursive text within filesgrep -ni
( + "REGEX" ) search for the line number and ignore the letter casegrep -rni -A 1 -B 1
( + "REGEX" ) search for one line before and one line after the results adjust the numbers as neededgrep
works with REGEX and any other text as well