Wednesday, July 20, 2011

Ubuntu Linux commands....that you can't live without!!

Linux terminal is one of the very good command line interfaces out there.
Knowing linux commands  may help you better understand your system and increase your efficiency.Linux commands are a nice addition to the GUI of 
ubuntu desktop but these commands are absolutely essential for ubuntu 
servers as they install without the GUI.

Opening your terminal in Ubuntu is very easy. Just go to..


 Applications->Accessories->Terminal.

The prompt of the terminal shows something like this:
 

maitnoob@maitnoob-laptop:~$ 

The first name is your username and the one after the @ is your hostname.
After the colon ~ represents your home folder(you always start at your home folder by default)
$ is the prompt symbol in linux just like > in windows ( C:\> )

There are many commands in linux. I am only listing the important ones to get you started.

ls command: This command lists the files in your current folder.use ls -al to  

                    display all files(includes hidden) and their details. 
                    Usage : username@computer:~$ ls -al

cd command: Just like in Windows changes the diretory(case sensitive). But 

                     cd.. or cd. doesn't work here instead cd .. works.
                     Usage: username@computer:~$ cd Desktop
                     You can use a directory in place of Desktop.


cat command: To view the contents of a file in current directory.
                      Usage: username@computer:~$ cat mytxt.txt

What is sudo?? 

A very important question for a linux newbie.The answer is simple.
When you log into your account you are a normal user without admin rights.

You are granted the rights only when you need it.This prevents accidental or intentional changes.These rights are given only for 15 minutes but you can change it according to your needs. This user with admin privilege is a superuser and to jump to this superuser in terminal you place a word sudo before your commands.
 

When you add sudo before your commands computer asks for password.This is the password of your first user account.You can change it later by using passwd command.

man command: opens a help file for a command.Press Q to exit.
                        Usage: username@computer:~$ man ls

pwd command: This command prints the current working directory.
                        Usage: username@computer:~$ pwd

cp command: Makes a copy of the file.The original file remains there.
                     Usage: username@computer:~$ cp mytxt.txt copyofmytxt.txt

mv command: Moves the file form one directory to another.The original file is 

                      moved.
                   Usage: username@computer:~$ mv /home/Desktop/mytxt.txt /home

rm command: Deletes/Removes a file from the directory(folders).
                      Usage: username@computer:~$ rm mytxt.txt 

mkdir command: Allows you to create directories.
                          Usage: username@computer:~$ mkdir mymusic

chmod command: Changes the permisions of the files or folders.You can set the 

                            permissions  for user,group etc. and can also set who can 
                            read, write or execute files.
                            Usage: username@computer:~$ chmod a+x myfile.exe
                            r represents read,w represents write,x represents execution
                            a represents everybody,o represents others,g represents  

                            group.The above command allowed myfile.exe to be 
                            executed by everybody using the machine.

chown command: Changes the ownership of a file.
                        Usage: username@computer:~$ sudo chown maitnoob mytxt.txt
                        this changes the ownership of mytxt.txt to maitnoob. 


df command: Shows the disk space usage of all partitions. df -h is more useful.
                    Usage: username@computer:~$ df -h

free command: Displays amount of free and used memory in the system.
                       Usage: username@computer:~$ free
                       free -m gives the info in megabytes(MB).
 

top command: Displays the system resources,CPU,RAM.swap and tasks being
                       run. To exit press Q.
                       Usage: username@computer:~$ top

uname command: Displays system information.uname -a displays all the info.
                           Usage: username@computer:~$ uname -a

lsb_release command: Displays your linux version with -a.
                                  Usage: username@computer:~$ lsb_release -a

ifconfig command: This reports on your system's network interfaces.
                            Usage: username@computer:~$ ifconfig

Users and Group commands:

adduser command: Creates a new user.
                             Usage: username@computer:~$ sudo adduser $loginname
                             This prompts for password.Enter the password and the 

                             details to create a new user.

passwd command:  This command changes the user's password.When run with

                              sudo it can change any user password.
                              Usage: username@computer:~$ passwd 
                              This changes current user's password.
                              Usage: username@computer:~$ sudo passwd
                              This changes sudo password for your machine.


who command: Displays who is currently logged into the machine.
                       Usage: username@computer:~$ who

addgroup command:Adds a new group.
                              Usage: username@computer:~$ sudo addgroup $groupname

deluser command: Removes a user from your system.To remove user's files and 

                            home directory add -remove-home option.
              Usage: username@computer:~$ sudo deluser maitnoob -remove-home

delgroup: Removes a group from the system.
               Usage: username@computer:~$ sudo delgroup groupname

 If you don't have the permission to run any of the above command you can run  it by adding sudo before the command.


That's all folks!!!
 

If you liked this post show your appreciation by liking/commenting or 
sharing it with your friends.....

 

0 Comments
Comments