0% found this document useful (0 votes)
46 views23 pages

Os Lab2

The document discusses various Linux commands like pwd, ls, cp, rm, mkdir, vi, nano, touch, date, cal, clear, exit, and the write() system call. It provides detailed explanations and examples of using these commands and call on a Linux system.

Uploaded by

sai karthik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views23 pages

Os Lab2

The document discusses various Linux commands like pwd, ls, cp, rm, mkdir, vi, nano, touch, date, cal, clear, exit, and the write() system call. It provides detailed explanations and examples of using these commands and call on a Linux system.

Uploaded by

sai karthik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Outline

Linux Commands
Pwd,ls,cp,rm,mkdir, vi, nano, etc
Linux Commands (for Ubuntu)
pwd: print work directory: e.g. if you are at your home directory then
it will print something like /home/<username>
ls: list directory: This command will list the items of a directory. If you
don’t specify a directory then it will list work directory, the place where
you currently are.
mkdir : make directory. It will create a new directory. We will need to
specify a name.
Syntax: mkdir direcrory_name
cd :change directory. It will change your work directly as you specify.
You will have to specify a directory.g. cd /home will change your work
directory to /home regardless where you are.
Syntax: cd direcrory_name
Linux Commands (for Ubuntu)
cd ..: change directory one level up.
cd ~ :change to home directory. Suppose if your username is tom then
cd ~ will change your work directory to /home/tom.
cp: Copy Command. It will copy a file or directory. It is similar to Copy-
Paste in GUI.
Syntax Copy File: cp file_name1 file_name2
tax Copy Directory: cp –r dir1_name dir2_name
mv: Move or rename files. It is like renaming a file or cut-paste in GUI.
Syntax: mv file_name1 file_name2
Linux Commands (for Ubuntu)
rm: remove file.
Syntax: rm file_name1
rmdir : remove empty directory. This will not remove content of the
directory but it will delete a directory if it is empty.
Syntax: rmdir Directory_name1
man: Ubuntu will help you instantly and has a built in manual. Simply
apend any command with man or type executes man. e.g. man mkdir
sudo : sudo basically allow a standard user to execute a command
with root or superuser privilege.
Linux Commands (for Ubuntu)
Vi or Vim editor Commands
Developed by: Bill Joy
The vi editor is elaborated as visual editor.
 It is installed in every Unix system. 
It is user-friendly and works same on different platforms.
It is a very powerful application.
 An improved version of vi editor is vim.
The vi editor has two modes:
Command Mode: In command mode, actions are taken on the file.
The vi editor starts in command mode.
Insert Mode: In insert mode, entered text will be inserted into the file.
The Esc key will take you to the command mode from insert mode.
Linux Commands (for Ubuntu)
Vi or Vim editor Commands
Commands Action
:wq Save and quit
:w Save
:q
Vi or Vim editor Commands
Quit
:w fname Save as fname
ZZ Save and quit
:q! Quit discarding changes made
:w! Save (and write to non-writable file)
Linux Commands (for Ubuntu)
Vi or Vim editor Commands
Command Action
i Start typing before the current character
I Start typing at the start of current line
a
Vi or Vim editor Commands
Start typing after the current character
A Start typing at the end of current line
o Start typing on a new line after the
current line
O Start typing on a new line before the
current line
Linux Commands (for Ubuntu)
Vi or Vim editor Commands
Command Action
j To move down

k To move up

h
Vi orleft
To move Vim editor Commands
l To move right

G Will direct you at the last line of the file

`` Will direct you to your last position in the file

u Undo the last command

. Repeat the last command


Linux Commands (for Ubuntu)
Vi or Vim editor Commands
Command Action
x Delete the current character
X Delete the character before the cursor
r Replace theVim
Vi or current character
editor Commands
xp Switch two characters
dd Delete the current line
D Delete the current line from current character to
the end of the line
dG delete from the current line to the end of the file
Linux Commands (for Ubuntu)
Vi or Vim editor Commands
Command Action
dd Delete a line
yy (yank yank) copy a line
p
Vi or Vim editor Commands
Paste after the current line
P Paste before the current line
<n>dd Delete the specified n number of lines
<n>yy Copy the specified n number of lines
Linux Commands (for Ubuntu)
Vi or Vim editor Commands
Command Action
w Move one word forward
b Move one word backward
<n>w
Vi or Vim editor Commands
Move specified number of words forward
dw Delete one word
yw Copy one word
<n>dw Delete specified number of words
Linux Commands (for Ubuntu)
Vi or Vim editor Commands
Command Action
w Move one word forward
b Move one word backward
<n>w
Vi or Vim editor Commands
Move specified number of words forward
dw Delete one word
yw Copy one word
<n>dw Delete specified number of words
Linux Commands (for Ubuntu)
Nano editor Commands
Developed by: Chris Allegretta
Open a file : nano file_name.extension
Command Explanation
CTRL + A Lets you jump to the beginning of the line.
CTRL + E Lets you to jump to the end of the line.
CTRL + Y Scrolls page down.
CTRL + V Scrolls page up.
A Help window will pop out and show you all the available
CTRL + G
commands.
To save the file. Nano will ask you to edit or verify the
CTRL + O
desired file name.
Linux Commands (for Ubuntu)
Nano editor Commands
Command Explanation
Search for a specified phrase in your text. Press ALT +
CTRL + W
W to search for the same phrase again.
It cuts the entire selected line to the cut buffer (similar to
CTRL + K
clipboard).
To paste the text from the cut buffer into the selected
CTRL + U
line.
CTRL + J Justifies the current paragraph.
Shows the current cursor position in the text
CTRL + C
(line/column/character).
CTRL + R Opens a file and inserts it at the current cursor position.
Linux Commands (for Ubuntu)
Nano editor Commands
Command Explanation
To exit Nano text editor. It prompts a save request if
CTRL + X
you made any changes to the file.
CTRL + \ Replaces string or a regular expression.
CTRL + T Invokes the spell checker, if available.
CTRL + _ Lets you go to the specified line and column number.
To select text. You can combine this command
ALT + A with CTRL + K to cut a specific part of the text to the cut
buffer.
Linux Commands (for Ubuntu)
Run : gcc file_name.extension
Output: ./a.out
Question: Print Hello world using C program
Procedure:
1.Open a file using any editor : vi file_name.c
2.Save and exit from file : Esc+ :wq
3.Run the program using gcc command
4.See output using ./a.out
Linux Commands (for Ubuntu)
touch :It is a way to create empty files (there are some other mehtods
also). You can update the modification and access time of each file with
the help of touch command.
Syntax: touch file_name

Option Function
touch -a To change file access and modification time.
touch -m It is used to only modify time of a file.
touch -r To update time of one file with reference to the
other file.
touch -t To create a file by specifying the time.
touch -c It does't create n empty file.
Linux Commands (for Ubuntu)
date : This command will show you the current date and time of your
system (including timezone).
cal : This will show calender in the terminal.
clear : Clear Screen: Use clear command to clear the terminal screen.
exit : exit from terminal.
write() system call
write() system call is used to write to a file descriptor.
 In other words write() can be used to write to any file (all hardware
are also referred as file in Linux) in the system but rather than specifying
the file name, you need to specify its file descriptor.
Syntax:
#include<unistd.h>
ssize_t write(int fd, const void *buf, size_t count);
1.The first parameter (fd) is the file descriptor where you want to write.
2.The data that is to be written is specified in the second parameter.
3.Finally, the third parameter is the total bytes that are to be written.
write() system call
Program1: To write some data on the standard output device (by
default – monitor)
//Name the program file as “write.c”
#include<unistd.h>
int main()
{
write(1,"hello\n",6); //1 is the file descriptor, "hello\n" is the data, 6 is
the count of characters in data
}
write() system call
Program2: To write some data on the standard output device (by
default – monitor) and aslo count
//Name the program file as “write1.c”
#include<stdio.h>
#include<unistd.h>
int main()
{
int count;
count=write(1,"hello\n",6);
printf("Total bytes written: %d\n",count);
}

You might also like