Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet148/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   144   145   146   147   148   149   150   151   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

FORMAT
—output only the requested information where 
FORMAT
uses the char-
acters listed in Table 10.2, additionally when used with -f (file system stats) there are 
other formatting characters available (see second half of Table 10.2)
Let us take a closer look at stat with two examples. First, we view information of a series 
of regular files. Specifically, we use stat to provide for us the size of each file in blocks and 
bytes, the file name, the inode number of the file, and the time of last access. This com-
mand is given as 
stat -c “%b %s %n %i %x”
. A partial output is shown below. Each 
file consists of only 8 blocks with sizes that vary from 48 bytes to 413 bytes. The inodes are 
all in the 53x,xxx range. Finally, the last access time and date are given.
8 361 courses.txt 530970 2013-03-06 07:59:03.458188951 -0500
8 117 mykey.pub 530991 2013-03-06 07:59:03.436319789 -0500
8 413 names.txt 530974 2013-03-06 07:59:03.426421446 -0500
8 80 s1 531019 2013-03-06 07:59:03.440076584 -0500
8 48 s2 531021 2013-03-06 07:59:03.426421446 -0500
Second, we inspect devices from /dev where we look at the file’s type, described in 
English using %F, among other things. The command is 
stat –c “%d %u %h %i 
%n %F”
. We also view the device number, UID of the owner, number of hard links, inode 
number, file name, and file type. Below are some excerpts from this output.
5 0 1 12556 autofs character special file
5 0 1 6106 dm-0 block special file
5 0 1 10109 dvdrw symbolic link
TABLE 10.2 
Formatting Characters for -c, Bottom Half for -c -f
Formatting Character
Meaning
%b, %B
Number of blocks (file size in blocks), size of blocks
%d, %D
Device number storing file in decimal, in hexadecimal
%f
File type (see Table 10.1)
%g, %G, %u, %U
GID, group name, UID, user name
%h
Number of hard links
%i
inode number
%n
File name
%s
Size in bytes
%x, %y, %z
Time of last access, modification, change
%a
Free blocks available to ordinary users
%b
Total blocks in file system
%c
Total file inodes in use
%d
Free inodes
%f
Total free blocks
%l
Maximum allowable file name length
%s
Block size
%T
Type of file system


404

Linux with Operating System Concepts
5 0 3 5341 input directory
5 0 1 2455364 log socket
11 0 2 1 pts directory
5 69 1 5185 vcs character special file
In this second listing, we see the devices autofs, dm-0, dvdrw, input, log, pts, and vcs. 
All except pts are located on device number 5. All except vcs are owned by user 0 (root); 
vcs is owned by vcsa, the virtual console memory owner account. Most of the items have 
only one hard link, found in /dev. Both input and pts are directories and have more than 
one hard link. The inode numbers vary from 1 to 2,455,364. The file type demonstrates 
that “files” can make up a wide variety of entities from block or character files (devices) to 
symbolic links to directories to domain sockets. This last field varies in length from one 
word (directory) to three words (character special file, block special file).
You might want to explore the inode numbers in your file system to see how diverse they 
are. Each new file is given the next inode available. As your file system is used, you will 
find newer files have higher inode numbers although deleted files return their inodes. The 
following script will output the largest and smallest inode numbers of a list of files passed 
in as parameters.
#!/bin/bash
largest
=
‘stat –c "%i" $1‘
largestFile
=
$1
smallest
=
‘stat –c "%i" $1‘
smallestFile
=
$1
shift
for item in $@; do
number
=
‘stat –c "%i" $item‘
if [ $number –gt $largest ]; then
largest
=
$number; largestFile
=
$item;
fi
if [ $number –lt $smallest ]; then
smallest
=
$number; smallestFile
=
$item;
fi
done
echo The largest inode from the files provided is
echo $largest of file $largestFile. The smallest
echo inode from the files provided is $smallest
echo of file $smallestFile
Notice in this script the use of the shift command so that all of the parameters after the 
first are shifted down. Since we had already processed the first parameter ($1), we no longer 
need it.
Whenever any file is used in Linux, it must first be opened. The opening of a file requires 
a special designator known as the 
file descriptor
. The file descriptor is an integer assigned to 
the file while it is open. In Linux, three file descriptors are always made available:


The Linux File System

405
• 0 – stdin
• 1 – stdout
• 2 – stderr
Any remaining files that are utilized during Linux command or program execution 
need to be opened and have a file descriptor given to that file.
When a file is to be opened, the operating system kernel gets involved. First, it deter-
mines if the user has adequate access rights to the file. If so, it then generates a file descrip-
tor. It then creates an entry in the system’s file table, a data structure that stores file pointers 
for every open file. The location of this pointer in the file table is equal to the file descriptor 
generated. For instance, if the file is given the descriptor 185, then the file’s pointer will be 
the 185th entry in the file table. The pointer itself will point to an inode for the given file. As 
devices are treated as files, file descriptors will also exist for every device, entities such as 
the keyboard, terminal windows, the monitor, the network interface(s), the disk drives, as 
well as the open files. You can view the file descriptors of a given process by looking at the 
fd subdirectory of the process’ entry in the /proc directory (e.g., /
proc/16531/fd
). There 
will always be entries labeled 0, 1, and 2 for STDIN, STDOUT, and STDERR, respectively. 
Other devices and files in use will require additional entries. Alternatively, the 
lsof
com-
mand will list any open files.
10.4 PARTITIONS
The disk drive(s) making up your Linux storage space is(are) divided into partitions. Each 
Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   144   145   146   147   148   149   150   151   ...   254




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish