Basic Linux Commands

This tutorial gives you a brief introduction to the commands you may need while working and is not the complete list. To know in detail about each command do: man

File System Related Commands

  • cd:
    cd or change directory command. To change the working directory.
    examples: cd programs(Change to the programs directory). cd /home/john (Changes directory to the john folder in the home directory)
  • ls:
    Shows the content of current directory.
    examples:
    ls ls -al (this gives a complete list with dates and permissions) ls /home (this give a list of everything in the home directory)
  • mkdir:
    Makes a directory.
    examples: mkdir test (this will make a directory called test in the folder you are currently in. mkdir /tmp/files (this makes a files directory in the tmp folder)
  • rm:
    Removes a file or folder.
    examples: rm test.txt (this removes the file named test.txt in your current directory) rm /home/john/test.txt (this would remove the test.txt file in the folder John.)
  • cp:
    Copy files. This will copy source file(s) to target file(s)/directory
    examples: cp test.txt /home/john/ (this will copy test.txt from the current folder that your in and place it in the john folder). cp /tmp/test.txt /home/john/test_old.txt (it will name the test.txt file test_old.txt in the john folder.)
  • pwd:
    Present Working Directory command. This will show you what directory you are currently in.
    example: pwd example output: /home/john
  • mv:
    This can move or rename a file or directory
  • examples: mv test.txt test (this renames the file test.txt to test and keeps it in the same folder) mv test.txt /home/john (this is the same as above but moves it to the john folder) mv -i (this will move all the contents within a directory but ask for confirmation on every file).

Other Useful commands

  • man:
    This is the Linux help system. It will help you know more about a command and different ways to use it.
    examples: man man (this will tell you better how to use the man page) SPACE BAR - to scroll forwarded one page at a time. RETURN - to scroll one line at a time. Q - to quit and go back to the prompt
  • lynx : Accessing the course home page The course home page contains information about the course. To access the course home page type :
    lynx http://www.cse.iitb.ac.in/~cs101
    This page has links to various references for Fortran and general instructions.
  • more:
    This will show you the contents of a file.
    examples: more test.txt (This will display on the screen the contents of test.txt. It has to be in your current folder) more /home/john/test.txt (Same as above but will display the test.txt file on the john folder) SPACE BAR - to scroll forward one page at a time. RETURN - to scroll one page at a time. b - goes back one page Q - to quit and go back to the prompt There is also the less command. It has all the features of more, plus a bunch or other features.
  • clear:
    This command will clear the screen.
  • pine:
    To send a mail to your TA, one can use "pine". This program is menu driven and easy to use.

Editing Using Pico

Pico is a simple, display-oriented text editor. Commands are displayed at the bottom of the screen, and context-sensitive help is provided. As characters are typed they are immediately inserted into the text. Editing commands are entered using control-key combinations.
Some basic features
  • case-insensitive searching This feature is useful to search any string in current text. String searches are not sensitive to case. A search begins at the current cursor position and wraps around the end of the text. The most recent search string is offered as the default in subsequent searches. Use 'Where Is' (ctrl-W) to invoke this feature.
  • block cut/paste Blocks of text can be moved, copied or deleted with use of the following commands:
    • text Selection (ctrl-^) : Mark cursor position as the beginning of the text to be selected.
    • select : Move the cursor (using arrow keys ) to select the text.
    • cut Text(ctrl-K) : This will cut/delete the selected text.
    • paste Text(ctrl-U) : This will paste the recently deleted text starting from current cursor position.
  • file browser.
    The file browser is offered as an option in the "Read File" and "Write Out" command prompts. It is intended to help in searching for specific files and navigating directory hierarchies. Filenames with sizes and names of directories in the current working directory are presented for selection. 'Write Out'(ctrl-O) : Used to Save the current file. 'Read File'(ctrl-R) : Used to Read/Load file. after invoking one of the above command we can use following file browser commands : 'To Files' (ctrl-T): to invoke file browser.

Compiling Fortran programs

The Fortran programs are saved in files which have a ".f90" extension. e.g. filename can be myprogram.f90
To compile the program :
f90 myprogram.f90
This will create a file named "a.out". To run the program
a.out

Telnet

What is telnet? Telnet is basically getting the command prompt from another Linux machine. To telnet to another Linux machine from a Linux machine type the following:
telnet 192.168.111.56 (make sure you type in a real IP address) or telnet machinename.cse.iitb.ernet.in (you can also telnet by using the domain name)
It will then ask you for a login prompt were you can enter your username and password.

logout:
After you are finished with your lab session DO NOT forget to logout. to logout type exit or logout at the command prompt. if you do not log out then the next person sitting on the machine can cause havoc to you/your files.

Note

  • This is only an introductory tutorial sheet, use man for details.
  • In any case, please to not switch off any machine. Ask your TA for help.
  • All the commands in Linux are case sensitive. That means LS, ls lS are all different commands.