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
This will open any document in your default browser for me Chrome.
Create New Files
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
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
This is a simple command used to open any file in finder.
Download Files Using Curl
A way to easily download files from a website using command line.
What A Command Does
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
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
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
The ps aux command will simply list all running processes on your system.
List Files By Size
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
This essentially allows you to clean the terminal by typing “c” instead of “clear”.
Create Multiple Files Of Any Given Format
An awesome command when creating multiple files for any given format, saves you from having to write touch each time.
List File Tree Format
To list the file structure as a tree simply type the tree command, wola!
Open A File Using Sublime Text
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.