terminal

Open a terminal from another (e.g. VSCode) terminal

open -a terminal .

Add to path on Mac

vim /etc/paths

Using pipe and grep

pip3 freeze | grep Xlsx

Open current directory in finder

open .

Find and kill process on a port

lsof -i tcp:3000
kill [PID]

Recursively remove node_modules

find . -name "node_modules" -exec rm -rf '{}' +

Location of a command in PATH

The following will return something along the lines of hie is /Users/username/.local/bin/hie:

type -a hie

Common commands

  • clear - clear the terminal

  • pwd - print working directory

  • mkdir - make directory

  • touch - create a file (e.g. touch example.txt)

  • cp - copy (e.g. cp file.txt target_directory)

  • mv - move (e.g. mv file.txt target_directory), can also rename a file (e.g. mv old_file_name.txt new_file_name.txt)

  • rm - remove (e.g. rm file.txt), can also remove files recursively (e.g. rm directory_name)

  • echo - send to stdout

  • cat - read content of a file

  • alias - set aliases (e.g. alias pd="pwd" means pd can be used interchangably with pwd)

  • export - set environment variables!

  • env - return list of environment variables

  • > - redirect stdout to a file (e.g. echo "Hello" > hello.txt)

  • >> - append stdout to a file

  • < - redirct stdin to a command (e.g. cat < file.txt)

  • | - pipe stdout of LHS as stdin to RHS

  • wc - word count (of a text file)

  • uniq - unique the contents of a file (on a line-wise basis?)

  • grep - global regular expression print (-i adds case insensitivity, -R recursive, e.g. within directory)

  • sed - 'streams editor', can be used for find and replace

  • nano - text editor

  • source - source ~/.bash_profile makes all aliases available in the current session

  • history - command history

Environment settings

  • Stored in:

~/.bash_profile

(where ~ is an alias for $HOME and . represents a hidden file)

How cmd line works

  • Most commands are stored in /bin

  • /bin is a directory on the path (...and hence is available in a terminal session)

  • Hence you can see all commands using: cd /bin, ls

Last updated