Unix Basics (Lab-1)
Unix Basics (Lab-1)
Unix Basics (Lab-1)
shell
a utility program that enables the user to interact with the UNIX operating system.
Commands entered by the user are passed by the shell to the operating system
which carries them out. The results are then passed back by the shell and
displayed on the user's display.
There are several shells available. The user may select which one they wish to
use.
shell prompt
a character at the start of the command line which indicates that the shell is ready
to receive your commands. The character is usually a '%' (percent sign) or a $
(dollar sign). It may be different on your system.
standard input
standard output
Unix commands are executable binary files located in directories with the name bin (for
binary). Many of the commands that you use are located in the directory /usr/bin.
When you enter the name of a command the shell checks to see if it is a built-in
command. If it is not, it looks for the the binary file that the command name refers to in
each of the directories that are defined in the PATH environment variable.
1. LISTING OF FILES
SYNTAX: ls –[options][filelist][directory list]
ls list visible files in the working directory.
ls -a list all enteries including filenames beginning with a period.
ls -l list visible files using long format ( includes modes, size, date etc).
ls / will display the name of the files in the root directory.
2. CREATING A FILE
SYNTAX : cat >filename
……………
……………
^D
10. TO PLACE THE USER IN THE HOME DIR FROM ANYWHERE IN THE
FILE SYSTEM.
SYNTAX : cd
SCREEN EDITOR vi
SYNTAX vi file_name
vi operates in 2 modes – command mode & edit mode.
- In the command mode it execute the commands.
- In order to enter text, we have to press i or a to switch to edit mode.
- In order to execute the command after entering the text mode, press ESC
to switch to the command mode.
CURSOR-MOVEMENT COMMANDS
j moves the cursor down one line
k moves the cursor up one line
h moves the cursor left one space character
l moves the cursor right one space character
0 moves the cursor to the beginning of a line
$ moves the cursor to the end of a line
TEXT-DELETION COMMANDS
x deletes character under cursor
dw deletes from cursor to beginning of next word
dd deletes line containing cursor
d) deletes rest of sentence
d} deletes rest of paragraph
COMPILING PROGRAMS
cc filename .c
compiles the c program in the file named filename.c and produces an executable
file named a.out.
cc filename.c –o filename
compiles the c program in the file named filename.c and produces an executable
file named filename.
EXECUTING PROGRAMS
./a.out
to execute the c program that has been compiled into the executable file named
a.out
EXERCISE:
1. Write a simple C program to display the message “Hello There!”.
2. Write a C program to read and display n numbers.
3. Write a C program to sort n numbers using any sorting algorithm.
4. Write a C program to search a number in the array.
REFERENCE:
******************************