Tag Archives: shell
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
sudo su -Alter login variables (such as $PATH, $EDITOR)
nano ~/.profileOther available shells
- /bin/ksh
- /bin/tcsh
- /bin/csh
- /bin/zsh
Files management
Output the contents of a file
cat /some/thingGet 20 lines from the end of a file
tail -n 20 /some/thingGet the first 20 lines of a file
head -n 20 /some/thingCreate an empty file
touch /some/thingRedirect the output of a command to a file (overwrites)
command > /some/thingRedirect the output of a command to a file (appends)
command >> /some/thingAppend the timestamp to a file
touch /backups/backup_`date +%s`.txtChange to the last directory you were in
cd /var
cd /etc
cd - # will take you to /var
List file size in human-readable units
ls -lh /dir/or/file
Available editors
- /usr/bin/vi
- /usr/bin/vim
- /usr/bin/nano
Applications and processes
Run a process in the background
command &List running processes
ps axThe first column will be the PID
Kill a process by pid
kill -9
Kill a process or processes by name (e.g: the Dock)
killall DockOpen an application (Mac-only)
open /Applications/iTunes.app/The PHP command accepts some interesting parameters which add flexibility to how scripts that you run from your shell or cron jobs are executed.
One of them is -d, which alters a php.ini value for the duration of the command. An example is as follows:
php5 -d memory_limit=128M symfony propel:data-load
This was a real time saver considering the server was not setup with a CLI-specific php.ini, like some are.
if ( comments_open() ) { ?>