Search

Learn Linux -4 Basic Commands

Aim: To introduce the reader to a few basic commands of Linux.

Now that we know how to launch a terminal and how to move about in a terminal lets learn some commands that we can run on the terminal.
If you want to refresh how to use terminal. Have a quick look at
http://tuxthink.blogspot.com/2010/04/learn-linux-2-using-terminal.html

Now Open the terminal. Try these commands out as you read, its the best way to get a hang of the commands.

We will start with running the commands and then go then later dive into the commands in detail.

mkdir: Make Directory. 


Creates directory or folder by name specified.


Syntax:    mkdir  "directory name" 


Eg:  mkdir folder1

once you type the command and the name of the folder you want to create, hit enter. if every thing goes fine, the cursor will simply move to the next line.

user@desktop:~$ mkdir folder1  
user@desktop:~$                       


ls: list


Only ls Lists the contents of the folder you are working in. There are ways to lists contents of other folders, we will come to that a little later.

syntax:    ls  

If you did run the "mkdir" and there was no error, how do you check did the folder actually get created or not ?
Just type "ls" on the command prompt and hit enter. It should list out all the folders in the folder/directory you are working in.

user@desktop:~$ ls 
folder1                      
user@desktop:~$    




cd: Change Directory 


The command changes the directory you are working to the new directory that is mentioned with the command.

syntax: cd  "directory name" 


For Eg:  cd folder1

Type "cd" followed by a folder name, in our case "folder1" which we just created.
Hit enter and if the command runs proparly, the command prompt will move to the next line. But do you see any difference in the prompt. See the example below, you should be able to see the folder name before the "$". 

user@desktop:~$ cd folder1
user@desktop:~/folder1$     




pwd: Present Working Directory


The command displays the folder that you are currently working in.

syntax:  pwd


Type "pwd" and hit enter, you should see the path to your directory displayed as shown below.

user@desktop:~/folder1$pwd 
/home/user/folder1                  
user@desktop:~/folder1$        


Remember the filesystems ? If you look at the path, it starts from "/" the mount point from where all folders originate in Linux. 



man: Manual Pages. 


The command displays help pages for any command that is passed to it.

syntax: man "command name". 


For eg : man ls

If you run the above example you will be shown a whole page explaining the working of the command ls and the various options that comes with it.  If you don't understand the options don'e worry we will get to it.
So in case any time while using linux you want to learn about a command just use the command "man".
To exit the man pages just press "q"

Another command similar to man is "info" which also works similarly but provides a little more in depth information.





Great so now we know how to create a directory, check the contents of a directory, change into a directory and find out the path to the directory we are working in. Also get help for any command we want. 

If you have got these commands working, lets explore them further with a lot of options that are available with them in the next chapter. 

No comments:

Post a Comment