0% found this document useful (0 votes)
7 views30 pages

Linux Operating System Overview for BCA

The document provides an overview of Linux and its architecture, including its features, shell types, and file system. It details the history of Linux, its development from UNIX, and the various commands used in Linux. Additionally, it explains the directory structure, file types, and permissions associated with Linux operating systems.

Uploaded by

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

Linux Operating System Overview for BCA

The document provides an overview of Linux and its architecture, including its features, shell types, and file system. It details the history of Linux, its development from UNIX, and the various commands used in Linux. Additionally, it explains the directory structure, file types, and permissions associated with Linux operating systems.

Uploaded by

vikasrajput4000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

OS using B.C.

A
Linux sem 3

3 z– Starting with Linux

Chapter
Contents
[Link] architecture
 Linux Features,
 Types of Shell ( C, Bourn, Korn )
 Linux file system
 Directory Structure of Linux
 Types of File
o Ordinary Files
o Directory Files
o Device Files
[Link] Commands :passwd, logout, who, who am i,
clear, bc, factor, cal, date
[Link] and Directory Related Command : ls, cat, cd,
pwd, mv, cp, ln, rm, rmdir, mkdir,umask, chmod,
chown, chgrp, find,
pg, more, less, head, tail,wc, touch

Prepared by Prof. Gunja


1
OS using B.C.A
Linux sem 3

 Introduction to UNIX OR Short note on UNIX.


 UNIX is a multitasking, multi-user computer operating system.
 Originally developed in 1969 by a group of AT&T employees at Bell Labs.
 Including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas
McIlroy, and Joe Ossanna.
 Suggested the name UNICS (Then jokingly reared to as the Uniplexed Information And
Computer System) for this operating system.
 The Unix operating system was first developed in assembly language, but by 1973 had
 been almost entirely recoded in C, greatly facilitating its further development and
porting to other hardware.
 Unix operating systems are widely used in servers, workstations. The Unix
environment and the client–server program model were essential elements in
the development of the
 Internet and the reshaping of computing as centered in networks rather than in
individual computers.
 Both Unix and the C programming language were developed by AT&T and distributed
to
government and academic institutions, which led to both being ported to a
wider variety of machine families than any other operating system. As a result,
UNIX became synonymous with "open systems".
 Following table shows timeline of UNIX development.

Year Description
1965 GE & AT&T and MIT created MULTICS (multiuser) by Dennies
Ritchie, Brein
Kernigham)
1969 UNICS (single version of MULTICS) implemented on PDP 7 to PDP 11
by KEN
THOMPSON
1970 UNIX was created in Assembly Language UNIX ver. 1
1973 Unix version3
1979 Unix version 7
1981 BSD(Berkely software Distribution developed at California Uni.)
1982 System II was developed
1987 Minix was developed
1991 FINNISH student Linus Torvalds developed Linux

 History of Linux

 Linux is an operating system that created by Linus Torvalds when he was a


student at the University of Helsinki in Finland in 1991.
 When Linus Torvalds was studying at the University of Helsinki, he was
using a version of the UNIX operating system called ‘Minix’.
 Linus and other users sent requests for modifications and
improvements to Mimix’s creator, but they felt that they weren’t necessary.
 That’sby
Prepared [Link]
why Gunja decided to create his own operating system that would take
2
into
OS using B.C.A
Linux sem 3

account users’ comments and suggestions for improvements.


 He released it for free on the Internet.
 Due to the far reach of the Free Software Foundation (FSF) and the GNU
Project,
 Linux popularity increased rapidly, with utilities developed and released for free
online.
 A system is termed UNIX only if it complies fully with (and is certified by) the Single
 Unix Specification (SUS) standards. Similar systems that do not comply
fully or are not certified, such as Linux, are termed “Unix-like”
operating systems.
 Linux is an operating system means that it’s meant to be used as an
alternative to other operating systems, Windows, MS-DOS and others.
 Linux is not a program like a word processor and is not a set of programs like an
office
 suite. Linux is an interface between computer/server hardware, and the programs
which run on it.
 There are many versions of Linux famous versions are,
 Red hat Linux Fedora, Centos
 Debian  Ubuntu, Linux mint, Linspire, PCLinux

 Architecture of Linux:

 Linux System Architecture is consists of following layers

Utilities & Applications programs

The Shell

Kernel

Prepared by Prof. Gunja


 Hardware layer: Hardware consists of all peripheral devices (RAM/HDD/ CPU etc).
3
OS using B.C.A
Linux sem 3

 Kernel: Core component of Operating System, interacts directly with hardware,


and provides low level services to upper layer components. It manages
hardware and executing processes. It controls the allocation & deallocation of
memory to processes. Kernel is written in C program. User interacts with the
Kernel by using System calls.
 Shell: An interface to kernel, hiding complexity of kernel’s functions from
users. Takes commands from user and executes kernel’s functions. Computers
don’t have any inherent capability of translating commands into action. This
requires a command line interpreter (CLI) and this is handled by the “Outer
Part” of the operating system i.e. Shell. It interprets the commands the user
types in and arranges for them to be carried out. Moreover, the shells provide the
meta characters like *, [ ], ? and so on. For better searching of files.
 Utilities: Utility programs giving user most of the functionalities of an operating
systems. For
e.g. Antivirus, Disk Management Tools, Disk Cleanup Tool, calculator.

 Features of Linux:
Following are some of the important features of Linux Operating System.
 Portable: Portability means software can works on different types of
hardware in same way. Linux kernel and application programs support
their installation on any kind of hardware platform.
 Open Source: Linux source code is freely available and it is community based
development project. Multiple team works in collaboration to enhance the
capability of Linux operating system and it is continuously evolving.
 Multi-User: Linux is a multiuser system means multiple users can
access system resources like memory! ram! application programs at
same time.
 Multiprogramming: Linux is a multiprogramming system
means multiple applications can run at same time.
 Hierarchical File System: Linux provides a standard file
structure in which system files! user files are arranged.
 Shell: Linux provides a special interpreter program which can be used to
execute
commands of the operating system. It can be used to do various types of
operations, call application programs etc.
 Security: Linux provides user security using authentication features like
password protect jon! controlled access to specific files! encryption of data.

 Shell and It’s types


 "It is a facility of UNIX and Linux OS which provides a user interface.
and work as a command interpreter."
 The kernel program is usually stored in a file called ‘LINUX’ whereas the shell
program is in a file called ‘sh’.
 With a shell, users can type in commands and run programs on a Linux system.
Basically, the main function a shell performs is to read in from the terminal
what by
Prepared one
[Link],
Gunja run the commands, and show the output of the commands.
 It reads your terminal input and translates the commands into actions taken by the
4
OS using B.C.A
Linux sem 3
system.

Prepared by Prof. Gunja


5
OS using B.C.A
Linux sem 3

 Different people implemented the interpreter function of the shell in different


ways. This gave rise to various types of shells, the most prominent (famous,
well known) of which are outlined below:
 Bourne Shell
 C Shell
 Korn Shell

(1) Bourne Shell (sh)


 Bourne shell was developed by Steve (Stephen) Bourne at AT&T bell labs
and first released in 1977 in the version 7 of Unix release.
 It is the most basic shell its later versions are known as Bash (Bourne again
Shell) Shell is having extended features than Bourne shell.
 The Bourne shell or sh was the default UNIX shell of UNIX 7 and replaced the
original Unix shell.
 It is available on all UNIX systems.
 This shell does not have the interactive facilities provided by modern shells
such as the C shell and Korn shell.
 It is most powerful and most widely used shell.
 The prompt symbol of Bourne shell is $ (Doller) sign.
 The Bourne shell does provide an easy to use language with which you can
write shell scripts.

(2) C Shell (csh)


 The C shell is a UNIX shell that was created by Bill Joy while a graduate
student at University of California, Berkeley in the late 1970s.
 The C shell is a command processor that's typically run in a text window,
allowing the user to type commands which cause actions.
 The C shell can also read commands from a file, called a script. Like all Unix
shells, it supports filename wildcarding, piping, here documents,
command substitution, variables and control structures for condition-
testing and iteration.
C shell's overall style of the language looked more like C and was seen
as more readable.
 The C shell was developed at University of California.
 It is designed by Bill Joy.
 C shell gets its name from its programming language, which resembles
the C programming language in syntax.
 The prompt symbol of C shell is Percent (%) sign.
 It provides two advantage : We can write our own command by writing a
program and secondly, previously typed command can be recalled.
 Previously typed commands can be recalled, since the C shell keeps
track of all commands issued at the command line.
 This feature is similar to the one provided by the program DOSKEY in MS-
DOS environment.

Prepared by Prof. Gunja


6
OS using B.C.A
Linux sem 3

(3) Korn Shell (ksh)


 The Korn shell (ksh) is a Unix shell which was developed by David Korn
(AT&T Bell Laboratories) in the early 1980s.
 This shell gets its name from its inventor David Korn of Bell’s Lab.
 It is now provided as the standard shell on Unix systems.
 It provides all the features of the C and TC shells.
 Korn shell is not-so-widely-used but most powerful, and is a superset of
Bourne Shell.
 It offers a lot more capabilities and is decidedly more efficient than the
other.
 We can switch between the different shells once we have found out if
they are available.

 File System in Linux OR Types of File available in Linux

File
"File is a container for storing information.”

 We can also say that file is a nothing but sequence of characters.


 In Linux right from directory to device each things are treated as a file.
 Directory is simply a folder which can contain files and other sub- directories.
 In Linux mainly three types of files available
(1) Ordinary file (Regular File)
(2) Directory file
(3) Device file
(1) Ordinary File (Regular File)
"This type of files only contains data as stream of characters."

 It is also known as regular file.


 It is further divided into two types (i) Text file (ii) Binary File
(i) Text file:–

 This contains only printable characters. For example your "C" language's
code is to be said as text file.
(ii) Binary file:–

 This contains printable and non–printable characters also. For example picture
file or any object code or executable file are also known as binary file.
(2) Directory File
 As you have proper cupboards in library for storage of various books similarly
directories are some sort of containers for files stored in a computer system. In
other words,
Prepared by Prof. Gunja
7
OS using B.C.A
Linux sem 3

"The directory contains no data but keeps some details of the files and
sub–directories."
 A directory file contains entry for every file and subdirectory that is contains.
Suppose you have 20 files in directory then you'll have 20 entries in the directory.
 Each entry has two components
 The filename
 A unique identification number for the file (known as inode number)
(3) Device File
 We know that printer is used for printing files also CD ROM is also used for data
transfer etc.,
 Here the entire device attached to computer is treated as file. And all thing are
located at /dev
folder of Linux
 One advantage of it is that we can use all command that related to ordinary files
also be used with device file.

 Directory structure of Linux

 Top level of the Unix file structure file structure (/) is known as a root directory
or slash directory, and it always has a certain set of subdirectories, including bin,
dev, etc, lib, mnt, tmp, and usr.

Directories

1. The bin Directory


 The bin directory is where all the executables binaries were kept in early
LINUX. Over time, as more and more executables were added to LINUX, it
became quite unmanageable to keep all the executables in one place and
the bin directory split into multiple parts(/bin/sbin,/usr/bin).
2. The dev Directory

 Among the most important portions of any computer are its device drivers.
Without them, you would not have any information on your screen. You
Prepared by Prof.
would notGunja
be able to enter information.
8
OS using B.C.A
Linux sem 3

3. The etc Directory


 In UNIX for management of user accounts, the file system, security, device
drivers there is specific directory, the etc directory as the storage place for all
the administrative files and information.

4. The lib Directory


 In this all the library functions are stored in this directory.
5. The lost + found Directory

 When files are recovered after any sort of problem or failure, they are placed in
the lost + found directory, if the kernel cannot ascertain the proper location in
the system.
6. The mnt directory

 The mnt directory is an empty directory reserved for mounting removable file
systems like hard disks, removable cartridge drives, and so on.
7. The tmp Directory
 The tmp directory contains temporary files created by LINUX system programs.
8. The usr Directory
 The usr directory consists of several subdirectories that contain additional
LINUX commands and data files. It is also the default location of user home
directories.

 Linux files and directory permissions and ownership

Ownership
 File ownership is an important component of LINUX that provides a secure
method for storing files.
 In LINUX files and directories are belongs to different kind of users as following.

(1) User (Owner) Permissions:


 The owner's permissions determine what actions the owner of the file performs
on the file.
(2) Group Permissions:
 The group's permissions determine what actions a user, who is a member the
group that a file belongs to, can perform on the file.
(3) Other Permissions:
 The permissions for others indicate what action all other users perform on the
file.

Prepared by Prof. Gunja


9
OS using B.C.A
Linux sem 3

Permissions
 There are three specific permissions on LINUX-like systems that apply to each
class:
(a) Read Permission
 The read permission grants the ability to read a file.
 When set for a directory, this permission grants the ability to read the
names of files in the directory (but not to find out any further
information about them such as contents, file type, size, ownership,
permissions, etc.)
(b) Write Permission
 The write permission grants the ability to modify a file. When set for a
directory, this permission grants the ability to modify entries in the
directory.
 This includes creating files, deleting files, and renaming files.
(c) Execute Permission
 The execute permission grants the ability to execute a file. This permission
must be set for executable binaries.
 For example, a compiled C++ program or shell scripts, in order to allow the
operating system to run them.
 When set for a directory, this permission grants the ability to access file
contents

Symbolic Notations
 There are several ways by which linux permissions are represented.
 The most common form is symbolic notation as shown by ls -l.

User Group Others

File type

 The first character indicates the file type and is not related to permissions. The
remaining nine characters are (Generally there is d which denotes directory).
 In three sets, each representing a class of permissions as three
characters. The first set represents the user class. The second set
represents the group class. The third set represents the others
class.

Prepared
 Eachby Prof.
of theGunja
three characters represent the read, write, and execute permissions:
1
 r if reading is permitted, and – (dash/hyphen) if it is not.
OS using B.C.A

 w if writing is permitted, and – if it is not.


 x if execution is permitted, and – if it is not.

Numeric Notations
 Another method for representing LINUX permissions is an octal (base-8)
notation. This notation consists of at least three digits. Each of the
three rightmost digits represents a different component of the
permissions: owner, group, and others.

 Field Explanation:
$ ls – l
-rw-r----- 1 admin1 admin1 13 21 July 19 15:27 [Link]
If first character is – then it is normal file
If it is d then it is directory
Field 1 – File Permissions: Next 9 character specifies the files permission. Each 3 characters
refers to the read, write, execute permissions for user, group and world In this example, -rw-
r—– indicates read-write permission for user, read permission for group, and no permission
for others.
Field 2 – Number of links: Second field specifies the number of links for that file. In this
example, 1 indicates only one link to this file.
Field 3 – Owner: Third field specifies owner of the file. In this example, this file is owned by
username ‘admin1.
Field 4 – Group: Fourth field specifies the group of the file. In this example, this file belongs
to ”admin1” group.
Field 5 – Size: Fifth field specifies the size of file. In this example, ’13′ indicates the file size.
Field 6 – Last modified date & time: Sixth field specifies the date and time of the last
modification of the file. In this example, ’21 July 19 15:27′ specifies the last modification
time of the file.
Prepared by Prof. Gunja
1
OS using B.C.A

Field 7 – File or directory name: The last field is the name of the file or directory. In this
example, the file name is [Link]

 Connecting LINUX SHELL:

In windows operating system with the help of RUN command from start menu we can execute
UNIX Shell commands from remotely located computer.

Syntax :-

telnet <name of server> or

telnet IP address of server

 Basic Commands:

1. passwd: It is used to change your password.


Syntax: - passwd
Description:
 passwd changes the password or shell associated with the user given
by name or the current user if name is omitted.
 First user has to insert current password. Then new password will
be asked followed by confirm new password field.
 passwd command can also be used to change the home directory where
the path stands for the home directory.
Example:

2. Logout: To end the session and exit from current logged user's session
$logout command is used.
Syntax: logout

Prepared by Prof. Gunja


1
OS using B.C.A

3. Who: This commands displays all the users currently logged into the system.
Syntax: who
Description: It gives the Username, the terminal and login time of user.
Options:
Option Use
-H It gives the headers of each columns

4. who am i: It is used to getting information regarding current user logged


in only one system.
Syntax: whoami

Description: - Print the user name associated with the current effective user id.
5. Clear: It clears the terminal screen.
Syntax : clear
Description :
 Clear clears your screen if this is possible, including its scroll back buffer.
 Clear ignores any command-line parameters that may be present.

6. bc: bc command is used for command line calculator. It is similar to basic


calculator. By using which we can do basic mathematical calculations.
Syntax :- bc [options]
Description:
 In bc command each line is terminated by <enter> command.
 CTRL +D to exit from command.
 Type halt command to exit bc utility.

Options:

Prepared by Prof. Gunja


1
OS using B.C.A

Option Use
-q It ignores welcome message.
-l Define the standard math library.

ibase and obase


 ibase is a input base value which may be 2(binary), 10(decimal), 8(octal)
and 16(hexadecimal)
 obase is a output base value which may be 2(binary),10(decimal), 8(octal)
and 16(hexadecimal).
 To exit from bc utility type halt command.
Example :
l(15) O/p : 2.708050 (shows
log) sqrt(625) (square root) o/p:
25
7. factor : Prints the prime factors of all specified integer NUMBERs.
Syntax :- factor [NUMBER]...

Example: factor 100


100: 2 2 5 5
8. cal: Displays a calendar
Syntax:- cal [options] [month]
[year] Description :-
 It is used for displaying calendar. If there is not supplied any arguments
then it will display calendar of current month.

Example:-

9. date: Prints or sets the date and time.


Prepared by Prof. Gunja
1
OS using B.C.A

Syntax: - date [options] [+format] [date]


Description:
 Display the current date with current time, time zone.
 The command can also be used with suitable format specifies as
arguments. Each format is preceded by a + symbol, followed by the %
operator, and a single character describing the format.

Options:
Format (this is only for your knowledge in exam write 3–5 formats only.)
%a Sets abbreviated weekday name (e.g., Sun)
%A Sets full weekday name (e.g., Sunday)
%b Sets abbreviated month name (e.g., Jan)
%B Sets full month name (e.g., January)
%c Sets date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 21)
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%H hour (00..23)
%I hour (01..12)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale’s equivalent of either AM or PM; blank if not
known
%P like %p, but lower case
%r locale’s 12-hour clock time (e.g., 11:11:04 PM)
%t tab

Prepared by Prof. Gunja


1
OS using B.C.A

Example:-
$ date
Fri Feb 19 09:55:15 IST 2016
$ date +%m
02
$ date +%h
Feb
$ date +%y
16
$ date +"Date is %D %t Time is %T"
date is 19/02/16 Time is 10:52:34

To know the week number of the year,


$ date +%V
11

To set the date,

$ date -s "10/08/2016 11:37:23"


The above command will print Wed Oct 08 11:37:23 IST 2016

10. exit :- It is used to terminate a program, shell or log you out of a network normally.
Syntax :- exit

 File and Directory Related Command:


1. ls (List Directories) : Lists the contents of a directory.
Syntax :- ls [options]
Description :-
 It lists the directories and files stored in current directory. Here all the
listed files are arranged in ASCII order means first number then
uppercase and finally lowercase filenames.
Options:
-a Gives the list of all files.
–c Gives files by file time
–C Gives the file list in column style
–d Gives the list of only directories.
–g Gives the list of files but excluding the owner name.
–i Give the inode for each file (inode is a unique number related to
directory)
–L Gives list of files and directories referenced by a symbolic link.
–m Gives the file list with separating commas.
–r Gives the list of files in reverse order
–lt Sorts the files according to the last modification time

Prepared by Prof. Gunja


1
OS using B.C.A

–lu Sorts the files according to the last access time


–p It is used to identify the directory and ordinary files , here the
directories are
displayed with backslash (/) character
-r Reverses the order of how the files are displayed
-R Includes the contents of subdirectories

Example:-
$ ls – l
-rw-r----1 admin1 admin1 13 21 July 19 15:27 [Link]
2. cat (Concatenating, displaying and creating file): It is used for creating
file, displaying file and concatenating of file.
Syntax : - cat [options] [FILE]...
Description :-
 Two basically three uses of the cat command.
(i) for
creating file
Syntax
cat >
filename
cat>[Link]
t
 Above syntax creates [Link] and allow us to insert content for this
file.
(ii) for
appending file
Syntax
cat >> filename
(iii) for displaying file (concatenating)
Syntax
cat filename
You can also display multiple files using :– cat file1 file2….
o After creating or appending for save file use ctrl + d
command.

Concatenating file
contents cat [Link] >>
[Link]
 It can concatenate the contents of two files. For this you have to use
append output redirection operator.
 The contents of [Link] will be appended to [Link].

Options
 cat –n :–Prints the number of line
 cat –e :– Prints $ at the end of line in a file
 cat –v :– Prints displays nonprinting characters as if they were
Prepared by Prof. Gunja
visible, except for tabs and the end of line character 1
OS using B.C.A

3. cd (Change directory ): It is used to change the directory.


Syntax :- cd [directory]
Description:-

Prepared by Prof. Gunja


1
OS using B.C.A

 It is used for changing current working directory. For example before


changing directory default directory in shell as follows:
/home/ubuntu
 here to change directory we will use cd commands as follows
cd bca
it will change current directory to bca

Example:

Command Action performed


cd ~/Desktop Changes directory to /home/username/Desktop,
from any current path. Here the symbol ~ refers to
home directory of
user.
cd / Changes directory to the root directory from any
current
path.
cd Changes directory to home directory from any
current path
cd - Changes directory to previous changed directory.
cd/var/www Changes directory to the www sub-directory with
directory
var. It is useful when we know the path explicitly.

4. pwd (Present Working Directory ): Displaying your current directory name.


Syntax:- pwd
Description:-
 At the time of logging in user is placed in the specific directory of the file
system. You can move around from one directory to another, but any
point of time, you are located in only one directory. This directory is
known as your current directory. pwd command tells your current
directory.
Example:-
$ pwd
/home/abc
5. mv (Moving and Renaming the file or directory ): This command is
used for moving a file or number of files also we can rename files.
Syntax:
mv [options] oldname
newname mv [options]
filename /destDir Description
:-
 mv command which is short for move.
 mv command is different from cp command as it completely removes the
file from the source and moves to the directory specified, where cp
command just copies the content from one file to another.
 mv has two functions: it renames a file and it moves a group of files to a
different directory. Mv doesn’t create a copy of the file , it merely renames it.
Nobyadditional
Prepared Prof. Gunja space is consumed on disk during renaming. For example, if we
rename a file os to os1 and then if we try to read file os we will get error 1
OS using B.C.A

message as it is renamed to os1 there is no existence of file named os.


 Rename a file using mv

Prepared by Prof. Gunja


1
OS using B.C.A

Type the mv command as following to rename [Link] to


[Link]: mv [Link] [Link]
 Rename a directory using mv
Type the mv command as following to rename oldDir to
newDir mv oldDir newDir
 Move directory using mv
Type the mv command as
following mv sourceDir
destDir
example: – mv abc def
Options:
–f It will move the file (s) without asking even if it is being overwritten
on existing
target.
–i It will ask for confirmation whenever the move would overwrite an
existing
target.

6. cp(Copying the files /directories )


Syntax :- cp [options] sourceFile destFile
cp [options] sourcefile (s) direcotryName
Description:-
 The cp command lets you copy a file from one location to another on a UNIX
machine.
 To copy a file or directory there must be source file present without it
error will generated.
 If the destination path is not specified then it will copy in current directory.
 If the destination file doesn’t exist, it will be created.
 If it exists then it will be overwritten without any warning.

Options:
–i it will ask before copying a file if there is already file present.
–r It will copies all directories and sub–directories contained in main
directory.
If the destination directory is not then it will create first directory.
Example:-
$ cp file1 file2
The above cp command copies the content of [Link] to [Link]

Copy folder and subfolders:


$ cp-R scripts scripts1
The above cp command copy the folder and subfolders from scripts to
scripts1

7. ln (Link command): ln command is used to create link to a file (or)


directory. Syntax: ln [options] [existingfile(or directory)name]
[newfile(or directory)name] Description:
It allows
Prepared byProf. Gunja one file to have multiple file names, but there is only one copy
of the file on the disk. 1
OS using B.C.A

 Though the name of the file may be different but they have same inode
number
 It is similar to the shortcut to the Windows OS.

Prepared by Prof. Gunja


1
OS using B.C.A

Options:
–s it is used to create symbolic link to the file.
–i If the destination file already exists then it
asks to
overwrite the existing link.
–f It is used to forcefully overwrite file with link.

Example:
ln -s [Link] [Link] -- will create symbolic link of file1 in current
directory.
$ cat [Link]
This is a file.
$ cat [Link]
This is a file.

But, if we remove [Link]:


$ rm [Link]
we can no longer access the data it contained with our sym link:
$ cat [Link]
cat: [Link]: No such file or directory

8. rm (Remove files or directories): It is used to remove/delete the file from the


directory.
Syntax :- rm [options..] [file/directory]
Description:-
 It is used to delete files and directories. It also delete linked file
 It will ask for permission to delete files if user is sure then and then file
will deletes.
 Deleted file can’t be recovered.

Options:

–r It is used to remove the directory, its sub–directories and all the


[Link]
first all files removed then the directories.
–i It will ask for every deletion.
–f It is used to delete all forcefully , it also deletes protected files.
* It will remove all files in working directory.
-r It will remove directory with content.

Example :-

$ rm [Link]
 Remove the file [Link]. If the file is write-protected, you will be
prompted to confirm that you really want to delete it.
$ rm *
 Remove all files in the working directory. If it is write-protected, you
will
Prepared by Prof. be prompted before rm removes it.
Gunja
$ rm -f [Link] 1
OS using B.C.A

 Remove the file [Link]. You will not be prompted, even if the file is
write- protected; if rm can delete the file, it will.
$ rm -f *
 Remove all files in the working directory. rm will not prompt you for any
reason before deleting them.
$ rm -i *
 Attempt to remove every file in the working directory, but prompt before
each file to confirm.
9. rmdir (Removes
directories) Syntax :- mkdir
[options] directory
Description:-
 It is used to delete directories.
 If the directory contains the files it can't be deleted and prompts the
message "Directory is not empty".
 The parent(main) directory can't remove if there is sub–directory present
in main directory.
Options:

-p It tells rmdir to remove the parent directories of the specified


directory if
each successive parent directory will, in turn, become empty and
if each parent directory has write permission.

Example:
rmdir bca
rmdir -p dir3/dir4/dir5
10. mkdir (Makes Directory)
Syntax: mkdir [options] directory(s)
Description: It removes only empty directory.

Options:

-p It is used to create directories and its sub directories using a


single
command.

11. umask (User Mask): It is used to set default permission to files.


Syntax: umask <umask values>
Description:
 default permissions given to the files.
 If umask is 000 that means all read, write and execute permissions are
assigned.
 This umask is octal value deducted from default permissions.
 If umask is 666 it indicates all read permissions are removed.

For example, umask 123


Here, umask command applies opposite permissions to files. Like if 123
Prepared byisProf. Gunjait will set the permission of 654(777-123) means rw,rx,r.
given,
2
OS using B.C.A

It simply subtract from 777(all permission) with whatever number is given


with umask. (Note: by default umask does not set execute
permission).
$umask 123
$touch [Link]
$ ls -l
-rw-r--r—1 d1 None 241 Feb 21 04:02

12. chmod (Change Mode): chmod command allows you to alter / Change
access rights to files and directories.
Syntax:- chmod [options] [MODE] FileName

(i) Relative mode permissions


Syntax :chmod <category> <operations>
<permission> filename Here,

For example,
Changing modes using relative method
$ chmod u+x [Link]
-> this will add execution mode to user with [Link] file.

(ii) Absolute mode


permissions Syntax
chmod <octal code>
filename For read operation
4 (octal 100)
For write operation 2 (octal 010)
For execute permission 1 (octal 001)

For example
Changing modes using absolute method
$ chmod 000 [Link]
This will remove all the permissions from [Link]
13. chown: Command for system V that changes the
owner of a file. Syntax :- chown [options] <newowner>
filename/directoryname
Prepared by Prof. Gunja Description:
2
OS using B.C.A

 Any file when created its creator becomes its Owner.


 Further on to change the owner of file in LINUX chown command is used.
 It accepts the user name whom has to the ownership is given and the file
name is supllied.

Example :-
$ ls -l [Link]
-rw-r--r-- 1 root root 0 Jan 31 05:48 [Link]
$ chown vivek [Link]
-rw-r--r-- 1 vivek root 0 Jan 31 05:48 [Link]

14. Chgrp (Change the group): chgrp command is used to change the
group of the file or directory.
Syntax: chgrp [options] newgroup filename/directory
name chgrp ''group'' ''target1'' [''target2'' ..]
Description:
 The group parameter indicates the new group with which the targets
should be associated.
 It may either be a symbolic name or an identifier.
 The target1 parameter indicates the files or directories for which the
change should be made.
 The target2 parameter indicates optional additional files or directories for
which the change should be made.
Example :-
$ ls -l [Link]
-rw-r--r-- 1 root root 0 Jan 31 05:48 [Link]
$ chgrp vivek [Link]
-rw-r--r-- 1 root vivek 0 Jan 31 05:48 [Link]

15. Find: Finds one or more files assuming that you know their approximate
path.
Syntax :- find [options] path [expressions]
Description :-
 Find is one of the powerful utility of Unix (or Linux) used for searching
the files in a directory hierarchy.
 It finds through one or more directory trees of a file system, locates files
based on some user-specified criteria and applies a user-specified
action on each matched file.
 By default, find returns a list of all files below the current working
directory.
 For never to follow symbolic links. Use -P flag.
 The -L flag will cause the find command to follow symbolic links.
 The -H flag will only follow symbolic links while processing the
command line arguments.
Find From current directory
Find . -name 'my*'
This searches in the current directory (represented by a period) and
below it, for files and directories with names starting with my.
Prepared by Prof. Gunja
2
OS using B.C.A

For finding files only


find . -name "my*" -type f
This limits the results of the above search to only regular files, therefore
excluding directories, special files, pipes, symbolic links, etc.
Search All directories
find / -type f -name "myfile" -print
This searches every file on the computer for a file with the name myfile
and prints it to the screen.
Search According to modification time
find –mtime –1
This will find all the files whose modification time is less than one day
in the current directory.

Options:

Example:-
$ find -name "[Link]"
./bkp/[Link]
./[Link]

$ find -iname "[Link]"


./[Link]
./bkp/[Link]
./[Link]

$ find -maxdepth 1 -name "[Link]"


./[Link]

Find Files Under Home Directory


Find all the files under /home directory with name [Link].

$ find /home -name [Link]


/home/[Link]
$ find . -size 10M

Display files whose size is exactly 10M


$ find . -size +10M

Display files larger than 10M size


$ find -newer "[Link]"
Display the files which are modified after the modification of a
give file.
$ find . -perm 777

Prepared by Prof. Gunja


2
OS using B.C.A

Display the files based on the file permissions.


This will display the files which have read, write, and execute
permissions. To know the permissions of files and directories use the
command "ls -l".

$ find -name '*' -size +1000k


The system would search for any file in the list that is larger than 1000k.

16. pg (Paginate the file): This command is used to see the


information of the document page wise.
Syntax: $pg Starting Line Number No of Lines Per Page Option
File Name pg [option] [filename] [filename2]…..
Description:
 Whenever the file size is too larger that doesn't fits in the user screen then
it will use paging technique.
 We can say it likes scrollbar utility in windows. It displays file to the screen
but in page mode when you see first page then you have to press enter to
see second page of file. Example
$pg -c -20 [Link] //will displays 20 lines per page
$pg +10 –15 –p “Page No. %d” –s [Link]
Above command starts displaying the contents of [Link] file, 15 lines at a
time from 10th line onwards. At the end of each displayed page a prompt
comes which displays the page number on view. This prompt overrides the
default ‘:’ prompt of the pg command. The –s option ensures that the prompt
is displayed in reverse video.

17. more (Paging output) : Displays text one screen at a time.


Syntax :- more [options] filename
Description :-
 If the file is larger than the screen size then the contents of file will scroll
up to until it reaches the end of the file.
 press q for exit.
Options
 more –c :–It clears the screen before displaying the file
 more –d :– It displays error messages
 more –w :– It wait s for the users key stroke at the end (works like
getch() functions in 'C')
18. less
Syntax: less [options] filename.
Description:
 It similar to more but it allows backward movement in the file as well as
forward movement also.
 Less doesn't read entire file before starting, It is fast then other page
related commands.

19. head : Displays the


beginning of file Syntax:- head
[options] filename
Prepared by Prof. Gunja
Description:
2
OS using B.C.A

 It is used to display the lines from the top of the file.


 If there are no any arguments supplied then it will display first 10 lines by
default.
Options
 head –c 256 :– It will display first 256 characters of file
 head –1b : – It will display first 512 byte block
 head –2m :– It will display two blocks of 1 mb

Example :-
$ head [Link]
➢ Display the first ten lines of [Link].

$ head -15 [Link]


➢ Display the first fifteen lines of [Link].

$ head -c 20 [Link]
➢ Will output only the first twenty bytes (characters) of [Link]. Newlines
count as a single character, so if head prints out a newline, it will count it as a
byte.

$ head -n 5K [Link]
➢ Displays the first 5,000 lines of [Link].

20. tail : Displays the ending


of file. Syntax :- tail [options]
filename. Description:-
 It is used to display the lines from the end of the file.
 If there is no any arguments supplied then it will display last 10 lines by
default.
Example : -
$ tail [Link]
It displays the last 10 lines of '[Link]'.

21. Wc : Word, line and


character count Syntax: - wc
[options] [filename]
Description:-
 It is used to count words , lines and characters in given file.
Options:
 wc –l :– It counts the lines in the file
 wc –w :– It counts the words in the files
 wc –c : – It counts the characters in the file.
Example:
$wc [Link]
12 16 112 [Link]

22. touch
Syntax: touch [file_nm1] [file nm 2]….
Description:-
Prepared byProf.
It isGunja
used to change the modification time or access time of file.
2
OS using B.C.A

 The created using the touch command is empty. This command can be used when the
user doesn’t have data to store at the time of file creation.

Options:

 touch –a :– It changes the last access time of a file


 touch –m :– It changes the last modification time of a file.

Prepared by Prof. Gunja


2

You might also like