Useful commands to navigrate Mac/Linux terminal.
cat path_to_file # use for short files
less path_to_file # use for larger files, page up/down
tail -f production.log # follow file in real time
nano path_to_file
# or
vi path_to_file # to insert text, enter mode (press i)
# to save (press ESC, :, type wq or x)
# to exit w/o save (press ESC, :, type q!)
# to select lines, enter mode (press v)
# -> press 'd' to delete line
# -> press 'y' to copy
# display a file's content and pass it on to grep for searching
cat file-path | grep some-text
# search for two values at a time
less file-path | grep -e 'some-text' | grep 'some-text'
# Note: works on linux but might not on Mac
# -i option: inline replacement
# a after reg exp means it will place new line after match
sed -i '/^RegexToMatch/a newLineTextHere' fileToModify.txt
sudo vi /private/etc/hosts
sudo vi /etc/hosts # (ln to /private/etc/hosts)
ln -s /Users/arturo/Documents/rails-app railsapp
unlink summit2016 # to remove symlink
ls -la # to view files, hidden and symlinks
cat /etc/shells # view available shells
chsh -s $(which zsh) # set default shell to zsh
echo $SHELL # check current shell
bash --version # version
vi ~/.bash_profile # customize shell
source ~/.bash_profile # reload bash without restarting terminal
zsh --version # version
ssh user@website.com
ssh -i 'private-key-file' user@website.com # specificy which ssh key to use
download file to local computer
# . means local current directory - linux
# ~ means local computer's home directory - windows 7
scp user@website.com:~/path_to_file_on_remote_server .
scp user@website.com:/path_to_file_on_remote_server .
# Works on MacOS Sierra
sudo lsof -i -n -P | grep TCP
# To kill process, insert pid from above command
# sudo kill {pid}
or
lsof -n -i4TCP:{port}
ex. lsof -n -i4TCP:9292
ex. lsof -n -i4TCP:5434 -- psql
kill -9 pid
$ history
# To view command history with timestamps,
# add line to .bash_profile and reload Terminal.
# Then run the `history` command again
export HISTTIMEFORMAT="%m/%d/%y %T "
First create a new folder path that will be used link the networkfolder/shared drive.
Note: be sure to disconnect from the network folder first
# mount_smbfs //user@server/folder-path ~/new-path-locally
# example (def works on MacOS Mojave)
$ mount_smbfs //arty@10.0.0.37/Junk ~/mounty/junky
# to view what is currently mounted
$ df
Note: make sure iTerm is not on local path that will be unmounted
umount ~/mounty/junky
# or
diskutil unmount ~/mounty/junky