Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet35/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   31   32   33   34   35   36   37   38   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

file1 file2
would 
append file2’s first line to file1’s first line, file2’s second line to file1’s second line, and so 
forth. The option -s will serialize the paste so that all of file2 would appear after all of file1. 
However, unlike cat, paste would place the contents of file1 onto one line and the contents 
of file2 onto a second line.
The 
split
instruction allows you to split a file into numerous smaller files. You specify 
the file to split and a prefix. The 
prefix
is used to name the new files which are created out of 
the original file. For each file created, its name will be prefix followed by a pattern of letters 
such as aa, ab, ac, through az, followed by ba, bb, bc, and so forth. For instance,
split file1.txt file1
would result in new files named file1aa, file1ab, file1ac, file1ad, etc where each of these files 
comprises equal-sized portions of file1.txt.
You control the split point of the file through either 
-b 
size
or 
-C 
lines
where 
size
indicates the size of the division in bytes (although the value can include K, KB, M, MB, G, 
GB, etc) and 
lines
indicates the number of lines to include in each file. If, for instance, file1.
txt has 40 lines, then the command
split file1.txt -C 10 file1
would place the first 10 lines in file1aa, the next 10 in file1ab, the next 10 in file1ac and the 
last 10 in file1ad.
The option -d will use numeric suffixes (00, 01, 02, etc) rather than the two-letter suf-
fixes. The split command does not alter the original file. It should be noted that while the 
previously discussed file commands described in this section are intended for text files, 
split can operate on binary files, thus dividing a binary file into multiple subfiles.
A related command is 
cut
. The cut command will remove portions of each line of a file. 
This is a useful way of obtaining just a part of a file. The cut command is supplied options 
that indicate which parts of a line to retain, based on a number of bytes (
-b 
first-last
), 
specific characters (
-c 
charlist
), a delimiter other than tab (
-d ‘
delimiter

), or 
field numbers (
-f 
list
) if the line contains individual fields. Alternatively, --
comple-
ment
will reverse the option so that only the cut portion is returned.
Let us consider a file of user information which contains for each row, the user’s first 
name, last name, user name, shell, home directory and UID, all delineated by tabs. We 
want to output for each user, only their user name, shell, and UID. We would issue the 


Navigating the Linux File System

91
command 
cut -f 3,4,6 
filename
. If each row’s contents were separated by spaces, 
we would add 
-d ‘ ’
to indicate that the delimiter is a space.
The cut command can be useful in other ways than viewing partial contents of a file. 
Imagine that we want to view the permissions of the contents of a directory but we do not 
want to see other information like ownership or size. The 
ls -l
command gives us more 
information than desired. We can pipe the result to cut to eliminate the content that we do 
not want. For instance, if we only want to see permissions and not names, we could simply 
use
ls -l | cut -c1-10
This would return only characters 1 through 10 of each line. If we do not want to see the 
initial character (the — for a file, d for a directory, etc), we could use 
-c2-10
. This solu-
tion however only shows us permissions, not file names. We could instead use -f and select 
fields 1 and 9. The ls -l command uses spaces as delimiters, so we have to add -d ‘ ’, or
ls -l | cut -f 1,9 -d ‘ ’
Unfortunately, our solution may not work correctly as the size of the listed items may 
vary so that some lines contain additional spaces. For instance, if one file is 100 bytes and 
another is 1000 bytes, the file of 100 bytes has an added space between the group owner 
and the file size in its long listing. This would cause field 9 to become the date instead of 
the filename. In Chapter 6, we will look at the awk instruction which offers better control 
than cut for selecting fields.
One last instruction to mention in this section is called 
strings
. This instruction 
works on files that are not necessarily text files, outputting printable characters found in the 
file. The instruction outputs any sequence of 4 or more printable characters found between 
unprintable characters. The option 
-n 

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   31   32   33   34   35   36   37   38   ...   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