Powered By Blogger

Tuesday, May 8, 2012

Unix Commands...

  • Clear - Used to clear the screen
  • ls- Used to list all the files and folders
  • mkdir- to create a new directory (folder)
  • cat><File name> - used to create a new file
  • cat <File name>- To view file contents
  • cd <Folder name>- to Enter into the directory(folder) created
  • cd <Space Bar Key> - To come out of the directory (folder)
  • rmdir- To remove the directory(folder)
  • who- tell who all are connected to the server
  • date- displays the date and time (of the system)
  • cal- displays the present year calendar of all the months
  • cal <month(in number)> <Year(in number)>- displays the specified month and year
  • pwd- This command is provided to know the current working directory.
  • cp <Old File> <New File> - To copy the contents of old file to a new file
  • mv <Old File> <New File>- to move the data of old file into new file
  • wc <File Name>- To count the number of words lines and characters in a given file
  • bc- Calculator  to come out of it Press CTRL+d
  • who am i- Identify the user and lists the user name, Terminal line, the date and time of login.
  • Semi column(;) - to run multiple commands at a time.
  • vi editor- visual editor used to write C Programs.
  • sort <File Name>- it will sort the file according to the alphabetic order.
  • rm <File Name>- To delete the file which is already created.

How to run a C file in UNIX???

First open a file using VI editor (vi <File name.c>) after entering into it then press the key 'i' so that we can insert the data into the file which we created. after writing the program press escape key and the ':wq' to save and quit the program. After that use the command 'gcc <File Name.c>' to compile u r C program. If no errors then just give './a.out' to see the output.

 Sample Program for addition of 2 numbers:
$vi add.c
press 'i' key to type the program.
#include<stdio.h>
int main()
{
 int a,b,c;
 printf("\n Enter the values of A and B:");
 scanf("%d %d",&a,&b);
 c=a+b;
 printf("The Result is %d",c);
 return c;
}
 press the 'escape key' and ':wq'
after that compile using gcc or cc.
$gcc add.c
To view the output.
$./a.out  
finally u r result will be displayed if u don't have any errors.