Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

S.No: 1 Exp.

Name: What is an OS Command, Familiarization of Editor - vi, OS Commands Date:

ID: 19331A03B6     Page No:            


Aim:
Write different commands in vi editor.

Explanation:
Operating system (OS) command line interfaces are usually distinct programs supplied with the operating system. A program that
implements such a text interface is often called a command-line interpreter, command processor or shell.

vi editor:
The default editor that comes with the UNIX operating system is called vi (visual editor).
The UNIX vi editor is a full screen editor and has two modes of operation:
Command mode commands which cause action to be taken on the file
Insert mode in which entered text is inserted into the file

vi always starts out in command mode. When you wish to move between the two modes, keep these things in mind.
You can type i to enter the insert mode. If you wish to leave insert mode and return to the command mode, hit the ESC key.
If you are not sure where you are, hit ESC a couple of times and that should put you back in command mode.
A User can start using vi editor by using the commands like:
vi filename - Creates a new file if it does not exist, otherwise opens existing file
vi -R filename - Opens an existing file in read only mode

Commands of vi editor:
I - Insert text at the cursor
A - Append text at the end of the line
a - Append text after cursor
O - Open a new line of text above the cursor
o - Open a new line of text below the cursor
x - Delete a single character
dd - Delete an entire line
ndd - Delete n number of lines
d$ - Delete from cursor to end of line
yy - Copy a line in buffer
P - Paste text from buffer
nyy - Copy n number of lines to buffer
G - Go to last line of the file
1G - Go to first line in the file
w - Move forward to next word
b - Move backwards to next word
$ - Move to the end of line

OS Commands:
ls:
ls is a command to list files in Unix and Unix-like operating systems.
The ls command lists all files in the directory that match the name. If name is left blank, it will list all of the files in the
directory.
MVGR College of Engineering (Autonomous)

ls with no option list files and directories in bare format where we won’t be able to view details like file types, size, modified
date and time, permission and links etc.
Syntax: ls [option] [names]
The most common options to reveal this information or change the list of files are:
-l - long format, displaying Unix file types, permissions, number of hard links, owner, group, size, last-modified date and
filename.
-f - do not sort. Useful for directories containing large numbers of files.
-F - appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular
files have no suffix.
-a - lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By
default, these files are excluded from the list.
-R - recursively lists sub directories. The command ls -R / would therefore list all files.
-d - shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a
directory.

ID: 19331A03B6     Page No:            


-t - sort the list of files by modification time.
-h - print sizes in human readable format.

cd:
The cd command, which stands for "change directory", changes the shell's current working directory.
The cd command is one of the commands user will use the most at the command line in Linux. It allows the user to change the
working directory.
User use it to move around within the hierarchy of the file system.
Syntax: cd directory name
pwd:
The pwd command prints the name of the working directory. pwd prints the full path name of the current working directory.
Syntax: pwd
mkdir:
The mkdir command is used to create directories on a file system. If the specified directory does not already exist,
mkdir creates it.
Syntax: mkdir [option] directory_name(s)
This command has following options:
-m (mode) - Set file mode
-p (parent) - Create parent directories as necessary. When this option is used, no error is reported if a specified
directory already exists.
-v (verbose) - Verbose output; print a message for each created directory.
--help - Display a help message, and exit.
--version - Display version information, and exit.

The directory_name is the name of any directory that the user is asking mkdir to create. Any number of directories can be
created simultaneously.
cat:
The cat command is one of the most frequently used command in Linux/Unix like operating systems.
The cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect output in
terminal or files.
Syntax: cat [OPTIONS] [FILE]
To create a file syntax is : cat > filename
To view a file syntax is : cat filename

cat command has following options:


-e - $ is printed at the end of each line. This option must be used with -v.
-s - Suppress messages pertaining to files that do not exist.
-t - Each tab will display as ^I and each form feed will display as ^L. This option must be used with -v.
-u - Output is printed as unbuffered.
-v - Display control characters and non-printing characters.

Some of the examples are:


cat file1.txt file2.txt - Reads the contents of file1.txt and file2.txt, and displays them in order on the terminal screen.
cat file.txt > newfile.txt - Read the contents of file.txt and write them to newfile.txt, overwriting anything
newfile.txt previously contained. If newfile.txt does not exist, it will be created.
cat file.txt >> another-file.txt - Read the contents of file.txt and append them to the end of another-file.txt. If another-
MVGR College of Engineering (Autonomous)

file.txt does not exist, it will be created.


cat -s file.txt - Display the contents of file.txt by omitting any repeated blank lines.

cp:
The cp command is used to make copies of files and directories.
Syntax: cp [OPTIONS] SourceDestination
The cp command has the following options:
cp -a - archive files
cp -f - force copy by removing the destination file if needed
cp -i - interactive - ask before overwrite
cp -l - link files instead of copy
cp -L - follow symbolic links
cp -n - no file overwrite
cp -R - recursive copy (including hidden files)

ID: 19331A03B6     Page No:            


cp -u - update - copy when source is newer than destination
cp -v - verbose - print informative messages

Some of the examples are:


cpmain.c bak - Copy single file main.c to destination directory bak.
cpmain.c def.h /home/usr/rapid/ - Copy 2 files main.c and def.h to destination absolute path
directory /home/usr/rapid/.
cp*.c bak - Copy all C files in current directory to sub directory bak.
cpsrc /home/usr/rapid/ - Copy directory src to absolute path directory /home/usr/rapid/.
cp-R dev bak - Copy all files and directories in dev recursively to sub directory bak.
cp-i test.c bak - cp: overwrite 'bak/test.c'? y - Interactive prompt before file overwrite.
cp-u * bak - Update all files in current directory and copy only newer files to destination directory bak.

mv:
The mv command is used to move or rename files. mv command renames file source to destination or moves the source
file(s) to directory.
Syntax:mv [OPTIONS] SourceDestination
The mv command has the following options:
mv-f - force move by overwriting destination file without prompt
mv-i - interactive prompt before overwrite
mv-u - update - move when source is newer than destination
mv-v - verbose - print source and destination files
manmv - help manual

Some of the examples are:


mvmain.c def.h /home/usr/rapid/ - Move main.c def.h files to /home/usr/rapid/ directory.
mv*.c bak -Move all C files in current directory to sub directory bak.
mvmain.c main.bak - Rename file main.c to main.bak.
mvbak bak2 - Rename directory bak to bak2.
mv-u main.c bak - Update and move when main.c is newer.

man:
On Linux and other Unix like operating systems, man is the interface used to view the system's reference manuals.
man is the system's manual viewer; it can be used to display manual pages, scroll up and down, search for occurrences of
specific text, and other useful functions.
The man command itself is extremely easy to use.
Syntax: man command-name

MVGR College of Engineering (Autonomous)

You might also like