Useful Terminal Commands For Web Developers


The terminal is a powerful tool that when used correctly can speed up any Web Developers workflow, it is much faster than using a GUI and generally is a better way of understanding what you are actually doing. Below I have listed some of my most used & useful commands:

Open A File In The Browser

open index.html

This will open any document in your default browser for me Chrome.

Create New Files

touch index.html 
touch one.html two.html three.html

This is a great way to create a new file or file(s) using the command line.

Create A New Directory

mkdir test && cd $_

A simple way to create a directory and then go into it.

Inspecting A File

less index.html

There are a couple of ways to inspect files using terminal, generally I use less this will easily show the contents of a file. You can also use keys such as b and f to scroll through along with /pattern to search for patterns within use q to exit.

Open A Project In Finder

open .

This is a simple command used to open any file in finder.

Download Files Using Curl

curl -O http://www.domain.com/path/to/download.tar.gz

A way to easily download files from a website using command line.

What A Command Does

man ls

The man command is used to display instructions on how to use a command, just type man and then the command for example see above.

View Command History

history

You can easily view the history of a command by using the up arrow key, however if you would like a clear list of commands you can simply type history and they will be displayed.

Using Tab For AutoComplete

This has no code example however you can easily use tab to autocomplete… lifesaver.

Multiple Terminal Windows

screen

This is a command used to open multiple windows within terminal, you can view a more detailed guide by clicking the following link: https://kb.iu.edu/d/acuy. You can also press command+a+d and this will split the window pretty neat huh!

Remove Contents Of A File But Keep The File

cat /dev/null > test.html

This is another useful command that will remove the contents of a file however will keep the file.

List Current Processes

ps aux

The ps aux command will simply list all running processes on your system.

List Files By Size

ls -lSr

This is a simple way to list all files of a directory be size

List Only Folders Within A Directory

ls -d */

This is a relatively new command I found, essentially a way to easily list folders only and not files etc.

Clear The Terminal

alias c=”clear”

This essentially allows you to clean the terminal by typing “c” instead of “clear”.

Create Multiple Files Of Any Given Format

touch {user,age,location,height}.js

An awesome command when creating multiple files for any given format, saves you from having to write touch each time.

List File Tree Format

tree

To list the file structure as a tree simply type the tree command, wola!

Open A File Using Sublime Text

subl index.html

An easy yet awesome way to open a file in Sublime text, simply browse to the dir the file in and type in subl filename.html and this will open. (See the following response on Stack Overflow to get this setup Click Here)

These are just some of the useful commands that are out there, have a play to see if these speed up your workflow and enjoy.