Mastering the terminal commands in Linux or mac is an important skill. Before you enter Web Development or after you get some experience in the programming world, it is very important to have good skills in mac terminal or Linux command prompt as they call it.
Important Terminal Commands in Linux / Unix / Mac / Ubuntu
It doesn't matter whether you use a Windows operating system or Linux or Mac. What matters is you have good skills in the essential terminal in your favorite operating system. The terminal or command prompt is available in Mac or Ubuntu by default or you may have to install a third-party terminal for Windows operating system.
Which Commands Should You Learn?
There are many software available that can be used in the terminal, but as a programmer or a web developer, you need to master some important commands that I will be teaching you here.
The skills that you need to master in the terminal is to create and edit files, two navigate and copy-paste move folders between the folders on the same or different machines, to be able to connect on a different machine and execute commands, to update upgrade install or uninstall software, to start shut down machines, etc.
Understanding the File System of Linux
Linux files are organized in a tree-like structure where "/" is called the root folder and all other folders/file resides somewhere in that root folder.
So it means, every file or folder has a path relative to the root directory. For example, every user that gets created commonly has a home directory path as /home/rakesh like name where rakesh is my username. This is called a full path. The home path in the case of Mac OS is /Users/rakesh, the concept is still the same.
Absolute and Relative Paths
To use commands properly, one needs to be aware of how we use the path of files/folders. There are two important ways how a path of file/folder can be written.
The absolute path is the path from the root directory "/". For example, the path of my Documents folder on the Mac OS would be /Users/rakesh/Documents. The same Documents folder on the Ubuntu OS will be /home/rakesh/Documents. Both of them are absolute path because they start with the root folder and goes up to the given folder.
The relative path is a path with respect to another folder (generally the current working directory). For example, let's consider that there are two folders in the home directory Documents and Pictures. Now if we want to go Pictures directory from the Documents, the command would be:
The "." and ".." are two special folders that mean current directory and parent directory respectively. The above command says that change directory to parent directory and then go to Pictures directory.
Basics of Running Terminal Commands
First, you need to start the terminal by searching "terminal" in Spotlight Search if you are on Mac OS or in Ubuntu's search panel.
$ command [--param1 param1Value -param2 -param3]
So basically, each terminal command can be run with or without parameters. When no parameters are passed, it runs with default values parameters. Parameters give extra information to the terminal command which is then used by the command to do the customized work.
Terminal commands for navigating between the folders
The pwd command:
The first command is pwd. this command prints the full path of the working directory or directory in which you are at the terminal.
The ls command
The first command is ls. This command basically shows files and folders present in a particular directory. the ls command accepts multiple parameters but let's talk about a handful of them that I find to be using regularly.
Commonly used parameters are -l which is used to show contents in a long listing format. It shows extra information such as file/folder permissions, owner, group, size, and date, etc.
In the *nix systems, the files start with "." (dot) are considered to be hidden and not shown by default. To view hidden files we use param -a with the ls command.
Another two important parameters are -t which is used to sort contents with respect to created/modified time and -r which is applied to reverse the sorting order.
The cd command
The cd command is used to change the directory. The structure that follows is cd [path/to/directory]. Once changed, you can see the path with pwd command.
The mkdir command
To create a new folder mkdir command is used. The syntax for the command is mkdir [options] path/to/folder. As the syntax says, we can create a folder from anywhere, as long as you have given a correct path.
An important parameter that mkdir command takes is -p parameter. If you want to create folders inside folders, you need to pass -p parameter to create all the folders till the last folder.
mkdir -p one/two/three
The above command will create folder "one", then will create folder "two" inside it, and then create folder "three" inside folder "two". If the parameter -p is not passed, there will be an error.
In upcoming parts, we will see Terminal Commands for creating, reading, and writing files, commands for copying, pasting, moving, and deleting files and folders, commands for remotely accessing other machines, commands to search anything on the machine, and so on.
To know more commands, please visit Part 2 of the article.