Feb 8th, 2019
Useful commands for working in the terminal. Some of the commands are specific to macOS.
Various keyboard shortcuts for working with the command line prompt.
Ctrl + a - go to beginning of the line
Ctrl + c - cancel the command
Ctrl + e - go to end of the line
Ctrl + u - clear up to the beginning
My preferred permissions for folders and files.
chmod 755 # folder permissions chmod 644 # file permissions
Copy all the files in a folder into another folder.
cp -R folderA/. folderB
List the contents of a folder or of a specified folder.
ls ls folderA/
Rename a file or folder.
mv oldname.txt newname.txt mv oldfolder/ newfolder/
Remove a folder that already contains files.
rm -rf folderA/
Move all files from one folder to another folder. Example below demonstrates moving all the files from the Downloads folder to the Videos folder.
mv ~/Downloads/* ~/Videos
Open a file from the macOS terminal.
open fileA.txt # open a file in its default application open -a safari fileA.txt # opens with the specified application open -R fileA.txt # selects the file in a Finder window
Mount and unmount a volume on a Mac.
hdiutil attach Secure.dmg # mount a dmg volume named "Secure.dmg" hdiutil detach /Volumes/Secure # unmount a volume named "Secure"