Operating System - Unix File System
Operating System - Unix File System
1. Ordinary files – An ordinary file is a file on the system that contains data, text, or
program instructions.
Used to store your information, such as some text you have written or an image
you have drawn. This is the type of file that you usually work with.
Always located within/under a directory file.
Do not contain other files.
In long-format output of ls -l, this type of file is specified by the “-” symbol.
2. Directories – Directories store both special and ordinary files. For users familiar with
Windows or Mac OS, UNIX directories are equivalent to folders. A directory file contains
an entry for every file and subdirectory that it houses. If you have 10 files in a directory,
there will be 10 entries in the directory. Each entry has two components.
(1) The Filename
(2) A unique identification number for the file or directory (called the inode number)
Branching points in the hierarchical tree.
Used to organize groups of files.
May contain ordinary files, special files or other directories.
Never contain “real” information which you would work with (such as text). Basically, just
used for organizing files.
All files are descendants of the root directory, ( named / ) located at the top of the tree.
In long-format output of ls –l , this type of file is specified by the “d” symbol.
3. Special Files – Used to represent a real physical device such as a printer, tape drive
or terminal, used for Input/Ouput (I/O) operations. Device or special files are used for
device Input/Output(I/O) on UNIX and Linux systems. They appear in a file system just
like an ordinary file or a directory.
On UNIX systems there are two flavors of special files for each device, character
special files and block special files :
When a character special file is used for device Input/Output(I/O), data is
transferred one character at a time. This type of access is called raw device
access.
When a block special file is used for device Input/Output(I/O), data is transferred in
large fixed-size blocks. This type of access is called block device access.
For terminal devices, it’s one character at a time. For disk devices though, raw access
means reading or writing in whole chunks of data – blocks, which are native to your
disk.
In long-format output of ls -l, character special files are marked by the “c” symbol.
In long-format output of ls -l, block special files are marked by the “b” symbol.
4. Pipes – UNIX allows you to link commands together using a pipe. The pipe acts a
temporary file which only exists to hold data from one command until it is read by
another.A Unix pipe provides a one-way flow of data.The output or result of the first
command sequence is used as the input to the second command sequence. To make a
pipe, put a vertical bar (|) on the command line between two commands.For
example: who | wc –l
5. Sockets – A Unix socket (or Inter-process communication socket) is a special file
which allows for advanced inter-process communication. A Unix Socket is used in a
client-server application framework. In essence, it is a stream of data, very similar to
network stream (and network sockets), but all the transactions are local to the
filesystem.
In long-format output of ls -l, Unix sockets are marked by “s” symbol.
6. Symbolic Link – Symbolic link is used for referencing some other file of the file
system.Symbolic link is also known as Soft link. It contains a text form of the path to the
file it references. To an end user, symbolic link will appear to have its own name, but
when you try reading or writing data to this file, it will instead reference these operations
to the file it points to.
First and second syntax is used to copy Source file to Destination file or
Directory.
Third syntax is used to copy multiple Sources(files) to Directory.
OPTIONS:
1. -i(interactive): i stands for Interactive copying. With this option system first warns the
user before overwriting the destination file. cp prompts for a response, if you
press y then it overwrites the file and with any other option leave it uncopied.
$ cp -i a.txt b.txt
cp: overwrite 'b.txt'? y
$ cat b.txt
GFG
2. -b(backup): With this option cp command creates the backup of the destination file
in the same folder with the different name and in different format.
3.ls -lh (h stands for human readable form) : To display file size in easy to read format.
i.e i.e M for MB, K for KB, G for GB.
pr (Unix)
pr is a command used to paginate or columnate files for printing. It can also be used to compare two
files side by side, as an alternative to diff.
On Unix-like operating systems, the pr command
formats a file to make it look better
when printed.This document covers
the GNU/Linux version of pr. pr paginates
or columnates FILE(s) for printing. 2.The -
t option is implied if PAGE_LENGTH is less
than or equal to 10. If no FILE is specified,
or when FILE is a dash ("-"), pr reads
fromstandard input instead. Syntax
pr [OPTION]... [FILE]...
OPTIONS ::
-c, --show-control-chars Use caret notation (^G) and octal backslash notation.
-d, --double-space Double-space the output.
-D, --date-format=FORMAT Use FORMAT for the header date.
-e[CHAR[WIDTH]],--expand- Expand input character CHAR (by default, the tab char
tabs[=CHAR[WIDTH]] (by default, 8) spaces.
cut command in Linux with examples
The cut command in UNIX is a command for cutting out the sections from each line of
files and writing the result to standard output. It can be used to cut parts of a line
by byte position, character and field. Basically the cut command slices a line and
extracts the text. It is necessary to specify option with command otherwise it gives error.
If more than one file name is provided then data from each file is not precedes by its
file name.
Syntax:
cut OPTION... [FILE]...
Options and their Description with examples:
1. -b(byte): To extract the specific bytes, you need to follow -b option with the list of
byte numbers separated by comma. Range of bytes can also be specified using the
hyphen(-).
2. -c (column): To cut by character use the -c option. This selects the characters given
to the -c option. This can be a list of numbers separated comma or a range of numbers
separated by hyphen(-). Tabs and backspaces are treated as a character. It is
necessary to specify list of character numbers otherwise it gives error with this option.
Syntax:
$cut -c [(k)-(n)/(k),(n)/(n)] filename
Here,k denotes the starting position of the character and n denotes the ending position
of the character in each line, if k and n are separated by “-”
Paste Command Examples in Unix / Linux Tutorials
Paste command is one of the useful commands in unix or linux operating system. The paste
command merges the lines from multiple files. The paste command sequentially writes the
corresponding lines from each file separated by a TAB
ADVANCED FILTER
A filter is a program that reads standard input, performs an operation upon it
and writes the results to standard output.
For this reason, it can be used to process information in powerful ways such
as restructuring output to generate useful reports, modifying text in files and
many other system administration tasks.
1.Grep cmd:; The grep filter searches a file for a particular pattern of characters, and
displays all lines that contain that pattern. The pattern that is searched in the file is
referred to as the regular expression (grep stands for globally search for regular
expression and print out).
Syntax:
1. -a FILENUM : Also, print unpairable lines from file FILENUM, where FILENUM is 1 or
2, corresponding to FILE1 or FILE2.
2. -e EMPTY : Replace missing input fields with EMPTY.
3. -i - -ignore-case : Ignore differences in case when comparing fields.
4. -j FIELD : Equivalent to "-1 FIELD -2 FIELD".
5. -o FORMAT : Obey FORMAT while constructing output line.
6. -t CHAR : Use CHAR as input and output field separator.
Example : Let us assume there are two files file1.txt and file2.txt and we want to
combine the contents of these two files.
// displaying the contents of first file //
$cat file1.txt
1 AAYUSH
2 APAAR
3 HEMANT
4 KARTIK