Deleting directories while preserving symlinks

At work, we needed to replace a pre-existing folder with a symlink. We wanted to symlink the user’s .git/hooks folder to ../build/git-hooks every time the script was run. We wanted to delete .git/hooks if it existed and replace it with a symlink, but we also wanted to avoid deleting ../build/git-hooks‘s contents by accident if the […]

Fixing “/usr/bin/env: node: No such file or directory”

After a fresh install of npm and bower, you may run into the following error while running bower install: /usr/bin/env: node: No such file or directory The fix on Ubuntu is very simple: sudo ln -s /usr/bin/nodejs /usr/bin/node

Specifying a port when connecting with SSH

Some servers run their SSH server on a different port than 22 for a variety of reasons, including security. To specify a custom port when connecting, use the -p flag as in the example below: ssh -p 2222 In this example, the client would attempt to connect using port 2222.

Knowing the difference between mtime, ctime and atime

If you are dealing with files, you might wonder what the difference is between mtime, ctime and atime. mtime, or modification time, is when the file was last modified. When you change the contents of a file, its mtime changes. ctime, or change time, is when the file’s property changes. It will always be changed […]

Get the number of lines of code for a project

If you want to get the total line count for a project, you can simply combine the find and wc commands. In the example below, we get the number of lines of code for all PHP, JavaScript and CSS files under a given directory: find [directory] -name ‘*.php’ -o -name ‘*.js’ -o -name ‘*.css’ | […]

How to create big test files in OS X and Linux

If you need to have large files to test your application, there is a command in OS X and Linux that allows you to create a file of an arbitrary size. We already know that you can create an empty file by using touch: touch myfile.ext You can also create files with a preset size […]

Install easy_install on Ubuntu and Linux Mint

If you need easy_install on your Ubuntu or Linux Mint machine, use the following command to install it: sudo apt-get install python-setuptools python-dev build-essential I strongly suggest that you use pip instead, but I’m leaving this here for those it might help.

Add some color to the OSX Terminal

If you find the OS X Terminal’s lack of color hard on the eyes, here’s how to set the colors. To get this color scheme, open ~/.bash_profile and add this: export CLICOLOR=1 export LSCOLORS=GxFxCxDxBxegedabagaced export PS1=”\[\033[36m\]\u\[\033[m\]\[\033[32m\]:\[\033[33;1m\]\W\[\033[m\]\$ ” alias ls=’ls -GFh’ The first line enables colors, the second sets the colors for ls and the last […]

OS X Terminal: Open the current folder in Finder

If you use the OS X terminal, you are probably familiar with the open command. Essentially, it opens the given file with the default application, or with the application specified with the -a parameter. For example, open hello.txt will open hello.txt using TextEdit or your default text editor. You can also use this command to […]

Linux tip: repeat a command as sudo

When you run a command in the terminal, and realize it requires superuser permissions, use the following command to re-run the command as superuser: sudo !! Here is an example scenario: apt-get install myapplication (permission denied) sudo !! The best part is that you can use this to prefix your command with anything. In the […]