The default shell for Leopard users is Bash. Although many GNU/Linux users are familiar with it, not all Mac users take full advantage of its power. Here are some very useful commands and tips I use routinely.
Users and login
Use the root superuser
Alter login variables (such as $PATH, $EDITOR)
Other available shells
- /bin/ksh
- /bin/tcsh
- /bin/csh
- /bin/zsh
Files management
Output the contents of a file
Get 20 lines from the end of a file
Get the first 20 lines of a file
Create an empty file
Redirect the output of a command to a file (overwrites)
Redirect the output of a command to a file (appends)
Append the timestamp to a file
touch /backups/backup_`date +%s`.txt
Change to the last directory you were in
cd /var
cd /etc
cd - # will take you to /var
List file size in human-readable units
Available editors
- /usr/bin/vi
- /usr/bin/vim
- /usr/bin/nano
Applications and processes
Run a process in the background
List running processes
The first column will be the PID
Kill a process by pid
Kill a process or processes by name (e.g: the Dock)
Open an application (Mac-only)
open /Applications/iTunes.app/