Oh my gosh! The terminal, that black thing where you write commands for everything, even for navigating directories or for creating and deleting files.
I remember the days as a Junior Software Engineer, when I used to be intimidated by the terminal and when using the terminal for creating new files was considered a superior knowledge.
Nowadays, I would say that knowing your way around the terminal, not only makes a good impact on your productivity but also looks impressive from the side.
When I'm working together with other engineers and I see them swiftly using the terminal in their workflow, somehow I get reassured about their professional knowledge.
Anyway, knowing how to use the terminal and bash commands shouldn't be a priority over learning a programming language. I would say it's important and it makes a difference, but if you're a Junior Engineer, consider it as a "nice to have" skill.
Here's a list of the most used commands in my daily workflow:
Disclaimer - I'm using iTerm2 for MacOS with Bash (a Unix shell), these commands should work just fine on any Mac and Linux systems, Windows default terminal is different.
If you're using Windows, have a look at my post about Programming on Windows.
Navigating
Change directory is probably my most used command for navigation to folders in the system's files structure.
cd
Can be used like:
cd ~/Documents/projects/my-app
For getting back to a higher level folder I use:
cd ..
This will bring us to ~/Documents/projects
cd ../..
Will bring us to ~/Documents
When I feel lost in the endless folders of enterprise projects I use a magic command:
pwd
Print working directory, which does just that, it prints the path to the folder you're currently in. Also useful for sharing the folder's path with your teammates.
Creating and Deleting files and folders
I use the touch command for creating new empty files.
touch index.js
Will create a new index.js file.
For creating a new folder I use the make directory command
mkdir js
Will create a new folder named js.
We can chain two or more commands together using the && operator.
mkdir js && cd js/ && touch index.js
Will create a directory named js, navigate inside that directory, and then create an index.js file inside of it.
For deleting files I use the remove command
rm index.js
Will delete the index.js file. But if we want to remove an entire folder, we need to add a recursive option to the remove command
rm -r js
Will delete the whole js folder including the index.js file.
Opening and Reading files
If I want to have a quick look at the content of a file, then I use the catenate command.
cat index.js
Will print the content of the index.js file on the terminal screen.
For opening files or folders with the default app, I use the open command.
open js/index.js
I will open the index.js file with Sublime Text, which is set as the default app for js files on my machine.
cd js && open .
Will navigate inside the js folder and then open it with the Finder app.
So here you have it, some of the most basic commands that I use on daily basis in my terminal.
There are many other more powerful commands, like change mode chmod
that sets access permissions of given files, or event the simple clear
that will clear your terminal interface.
But even just the basic knowledge of navigation and manipulation of files will improve your productivity.