Terminal for Web Development
Most people are scared when they first see black command line with blinking cursor and zero information. Here you will learn basic commands in command line to simplify your web development workflow.
You might think that you don't need command line at all if you started as a web developer and you just writing some javascript or css. But command line is an important tool which most programmers use every single day.
Here are some typical things that you do with command line:
- starting your web server
- using framework tools to generate new components or modules
- run any scripts
- using git with every project
- install packages, libraries, programs
So first of all you need a command line. In linux and mac you have a good command line by default but not in Windows. There you need to install additional program like cmder or git bash which are 2 most popular solutions to get nice console.
The most useful command is pwd which means "print working directory". It's especially useful for beginners if you don't understand in what folder you are.
pwd
Now we need to learn how to move between folder. For this we have cd command. All command work with relative path or absolute path. If we want to jump 1 folder up we put .. after cd.
cd ..
You can check where you are with pwd again.
if we want to return back to our child directory we type the name of it.
cd src
We also want to see the list of files and folders in the current directory. For this we have ls or list.
ls
We might want to create a new directly. For this we have mkdir command.
mkdir foo
and create a new file.
touch test.js
Obviously for most people it's more comfortable to create files and folders in their editor which is fine.
Really often we want to remove a file or a folder. For example node_modules.
rm test.js
rm -rf node_modules
Here rm is used to remove and we provide attributes r for recursive remove and f to remove folders also
Sometimes we want to copy the file
cp test.js test2.js
Again in all commands you can use any path. Either relative or absolute.
If we want to copy a directly we need to add a recursive attribute.
cp -r foo bar
This will copy a folder with all files recursively.
If you want to move a file or folder you just use move command.
mv test.js foo
This will put test.js file inside foo folder.
One more important thing is tilde. It is a reference to your home directory which can simplify the commands that you run.
cd ~
Goes to my home directly. Also you can use it while writing path for any other commands like cp, mv, rm.
And the last thing that you might need is actually a way to change file in console directly. You can use for this nano editor which is available there by default
To open a file with nano we can write
nano test.js
Change it like in normal editor and click ctrl+o to save and ctrl+x to exit. Or if you don't need to save it just ctrl+x.
So this were basic commands which you need to know to work with command line.
Want to conquer your next JavaScript interview? Download my FREE PDF - Pass Your JS Interview with Confidence and start preparing for success today!