Wednesday, January 5, 2011

linux : ek newbie ki jabani

Linux/gnu is the buzz now among my 2nd semester friends. It is because we have to use linux environment in our programming lab(can't use windows coz it isn't a true multi-user system). My tryst with linux/gnu started when I got my first computer, thanks to chief minister Tarun Gogoi, which came preloaded with Ubuntu OS. I tried it for a few weeks and then gave it up as it didn't have many of the features I wanted plus the absence of broadband-to install the plugins and other apps. But, the latest version of Ubuntu( aka Maverick Meercat) is awesome. I have been using it(and Lucid Lynx) since I came to IIT Guwahati.
         To a newbie linux/gnu can be terrifying "What's with all these commands?" - you may ask. Does it feel like going back instead of progressing? Actually, it isn't archaic. It is quite useful at times and definitely more powerful. Oh ! I almost forgot to tell you, today's linux distros have GUI too(and it's good)...
my ubuntu desktop & terminal
        I am a newbie myself and in this blog I am gonna take you through the basic linux/gnu commands, enough to survive the first CS110 lab. Learn them well, because not only your aptitude for programming but also your basic linux commands will be put to test in the next CS lab. I'll assume that you have no prior experience with linux and if you do, have patience...atleast comment

Most of these commands will work in all distros unless specified.

        In CC, instructor will ask you to work in Fedora, so forget about the SSH icon you saw in Windows desktop(as was initially taught by Prof. Rao).

In Fedora: Go to Applications -> System tools -> Terminal.
In Ubuntu: Go to Applications -> Accessories -> Terminal.(btw there's a shortcut just press Alt + Ctrl + T, you can also change this shortcut in System -> Preferences -> Keyboard Shortcuts, isn't it cool?)

        There you will see some text before a $ or % sign. It's called the command prompt , basically it means the computer is ready to accept commands. Before connecting to the computing server using the ssh command let's learn some basic commands first.

        Write pwd after the command prompt and press enter. You'll something like /home/username. pwd stands for print working directory and /home/username is the path of your working directory.

        Now enter this command mkdir new_folder  . Well ! don't worry if you see nothing because by mkdir command you have instructed the computer to make a new directory by the name new_folder( by the way don't write new folder, cos linux hates a space in a name. If you have to use spaces in a file/folder name use them inside inverted commas like mkdir 'new folder'). Now, the new directory will have the path /home/username/new_folder

       To see it enter the command ls , which stands for list.  You'll now see among your other files and folders, a folder called new_folder

        To make this new_folder your working directory enter cd new_folder
cd stands for change directory. Now try pwd and see what you get.

      To come out of this directory use cd .. or cd /home/username
the double dot(..) here stands for the parent directory and a single dot(.) means the working directory(did it ring some bells. Arrey bhai ./a.out, now you know why it's ./)
 So, while you were in new_folder your working directory was new_folder and the parent directory was username.

        The other commands are mv to move or rename a file, cp to copy a file, rm to remove/delete a file, rmdir to delete a directory.

use them this way 
to move a file give the command-  mv file (new destination)
suppose you have a file test.c in your username directory that you need to move to temporary, just type mv test.c temporary . Of course you must be in the parent directory of temporary, otherwise you shall have to type mv test.c /home/username/temporary

to rename a file just enter-   mv (old file name) (new file name)
eg to rename test.c as renamed.c enter mv test.c renamed.c

to copy use cp the same way as mv
eg:  cp renamed.c temporary
it will copy renamed.c to temporary

to delete renamed.c enter-   rm renamed.c

to delete a directory enter  rmdir (directory name)
eg: rmdir temporary will remove the directory named temporary.

okay, other interesting commands you might like to try on your own:
#1 whoami
#2 ip addr
#3 info
#4 man (a command name) eg man cp
#5 find (filename*)
#6 exit

(only for IITG 2nd sem students)And to connect to computing server just type the command ssh username@202.141.80.3 
Alternatively, from your Ubuntu system you can goto Places -> Connect to Server.. change the sevice type to SSH , give the server as 202.141.80.3, port 22, folder /home/cs201/stud/username and then connect

       enjoy linux/gnu and if you think I have forgotten something, made a mistake or simply you want to add something of your own...then please comment below...

No comments:

Post a Comment