Linux Basic
Why do we use command lines?
Through the usage of the command line we are able to perform any task related to programming much faster than using a graphical user interface. Although a graphical user interface is user friendly at the "first look" but when we want to know all the background details a command line is easier to use to showcase what is happening in the background.
What is the shell?
The shell is a program that takes command from the keyboard and gives them to the operating system to perform. Shell can also be referred as CLI(Command Lines Interface)
What is the terminal?
A terminal is a tool which we can use to pass the shell commands. This is a program that opens a window and let us interact with the shell.
There are many operating system that can be used however for this guide we will use the ubantu operating system.
To open the terminal
we can either search for terminal
or we can use the keyboard shortcut Ctrl +Alt+ T to open the Terminal
- Print working directory (pwd)
This is a present working directory command. This shows us in what directory we are currently working in.
Currently it shows that we are working on the home directory which is "/home/username"
- list command (ls)
ls is a linux shell command that let us lists contents of files or directories.
As we can see we have the files listed on the right.
However there are little files that keep our computer running smoothly that doesn't appear when we use the ls command. As we don't need to manipulate them at all as they are automatic
what if we wanted to see them anyway
we can use a dash(-) option:
For instance ls -a, where a stands for all format
ls -l, whereby l stands for long format
Now we can combine both dash(-) function
ls -al, whereby al stands for all formats and long format version
We can use another dash(-) options ls -h, where h stands for human readable.
Therefore when we combine all dash(-) options
ls -ahl: where a stand for all format , h stands for human readable format and l stands for long format.
we get:
Now the storage taken is in kilobytes. If we have bigger and bigger files such as GB or TB , this function will make it easier for the user to read.
when using dash(-) options it needs to be in alphabetical order or it wont work. Lets check when we use the dash(-) options in non alphabetical order
we can see it gets deleted. Therefore alphabetical order when using commands is really crucial.
- Change directory(CD)
Going into the desktop is an option by using the cd command combine with Desktop we can go there.
This is the equivalent of clicking in a folder. we can check where we are by using the printing work directory.
We can type the exact folder location we want to be in.
For example : We want to be in the Desktop Folder1. We use /home/username/directory
Likewise we can check which folder we are in by using pwd command
There are some shortcuts that can be used on linux.
Such as:
"~" , represent home directory. We can use this instead of /home/username/directory.
ls ~
"." , shows the directory we are in.
ls .. , list all files in parent folder to the one we are currently in. For us its Desktop.
- mkdir
We can use mkdir to create directories in linux.
For example lets create a directory name Family.
Firstly we want to create the directory on our desktop. Therefore we must use the cd command line to direct us to desktop "cd desktop". Then we use the mkdir command line and choose a name for our directory that we want to create that is Family.
As we can see the Family directory has been created.
Let's create a sub-directory "Father" for our parent directly "Family".
As we can see the sub-directory "Father" has been created in the directory Family.
If we want to create a sub-directory from a parent directory that doesn't exist. Let's take "Math" as sub-directory and "Subject" as parent directory.
As we can see we cannot create create this sub-directory as the parent directory doesn't exist on the system currently.
In order to create this directory structure we can use "-p" which is the short version of the flag . The longer version is "--parents" command .
If we want to create several sub-directories inside our parent directory. Lets assume our parent directory as names and other sub-directories as Anya , Stacy , Anastasia.
We use our flag "-p" parents name/{ Anya , Stacy , Anastasia}
Comments
Post a Comment