Using the terminal is a fantastic tool for a Web Developers to save time. It allows you to really harness the power of your machine without having to click through various windows.
The more you familiarise yourself with helpful comamnds the more likely you are to use them in your everyday workflow.
Try these commands today:
Open A File In The Browser
open index.html
This is a useful command to simply open a file in your default browser when using the terminal.
Create New Files
touch index.html
Great way to create new files quickly, you can also type in multiple files after touch to create many.
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 or cat filename.json
There are a couple of ways to inspect files using terminal, generally I use less or cat. You can also use keys such as b and f to then scroll through content.
Open A Project In Finder
open .
If you are on a Mac this is a great way to open a project in finder from the terminal.
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 for listing files.
Clear The Terminal
ctrl + l
A great command to clear the content of your current terminal session.
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: Click Here. You can also press command+a+d and this will split the window pretty neat!
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 by 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 VSCode
code .
An easy yet awesome way to open a file in VSCode, simply browse to the dir type in code . and this will open. Make sure you have VSCode instaled in the path beforehand.
These are just some of the useful commands that are out there, have a play to see if these speed up your developer workflow.