Command-Line In Linux is the text editor kind of interface in linux which takes commands from the user through keyboard and instruct the operating system to perform it. This is also known as Terminal or shell. This shell is a program which decides how this terminal or command line is going to behave and what kind of response should be shown to user after entering commands.
In general, there are many shell programs in various distro of Linux. But In my tutorial, I am going to use Bash. But commands will work on any kind of shell program and will provide the same result across the Linux distro.
But if you are curious to know your shell, In that case type this command in your terminal/Command Line Interface and Hit Enter because this is the first introduction of Command-line in linux because this is going to give you the path of shell.
Most of the Linux user finds command line a saver because many complex tasks which involves multiple steps from GUI, can be done through one single line of commands combination and that’s why it is more popular among developers because they are lazy to use mouse and have trust on their keyboard.
So if you want to learn or work on Linux then i would suggest you to learn Linux commands because these commands bring a power in your hand.
Now we are moving towards our first Linux command. Assuming you have logged in through putty.
So as soon as you log in to Linux machine, you land up on the home directory of the user but if you want to know the path of home director they type this command and see the result
compute@computer-VirtualBox:~$ pwd /home/computer
PWD is very important command for newbie which helps to know where are you starting from root.
PWD stands for ‘Present Working Directory’. It prints the directory path where user is currently working starting from root and this is inbuilt shell command and if you want to know the path of this command in your Linux Operating system then type
computer@computer-VirtualBox:~$ which pwd /usr/bin/pwd
you can directly use this command in these three ways
computer@computer-VirtualBox:~$ /usr/bin/pwd /home/computer computer@computer-VirtualBox:~$ /bin/pwd /home/computer computer@computer-VirtualBox:~$ pwd /home/computer
In all three case, we will get the same result. But if you want to know all the options/ flag that can be used with PWD command then type this command in console
computer@computer-VirtualBox:~/etc$ pwd --help pwd: pwd [-LP] Print the name of the current working directory. Options: -L print the value of $PWD if it names the current working directory -P print the physical directory, without any symbolic links By default, `pwd' behaves as if `-L' were specified. Exit Status: Returns 0 unless an invalid option is given or the current directory cannot be read.
These two options can be used like
pwd -L or pwd -P
If user type pwd -L then it gonna print the current working directory but if user type pwd -P then it prints physical directory, without any symbolic links.
Since we have learnt that help text is talking about symbolic link so why not we are going to create one symbolic link, To create symbolic link type commands like this
ln -s <source directory> target directory like this ln -s /etc/ etc
Above command will make a symbolic link of /etc folder of root level to one folder with name etc in /home/computer. Now change directory to etc by using this command and type pwd -P
computer@computer-VirtualBox:~$ cd etc computer@computer-VirtualBox:~/etc$ pwd -P /etc
So here we can see /etc which was linked with etc folder in /home/computer/etc but if is printing the original path of symbolic link.
But if we type pwd -L then it will print the directory even if directory is symbolic link. So lets see what this is going to print on screen
computer@computer-VirtualBox:~$ cd etc computer@computer-VirtualBox:~/etc$ pwd -L /home/computer/etc
PWD can be stored in a variable and can be used in some other places if writing any shell script. But if pwd is used without any options or flag in that case it will be pwd -P by default.
Hope you have liked this complete post on Command-line In Linux and have also learnt about PWD Commands as well.