Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet31/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   27   28   29   30   31   32   33   34   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

options

source destination
If you wish to rename a file, then source and destination are the old name and the new 
name, respectively. Otherwise, source and destination 
must
be in different directories. If 
destination is a directory, then the file’s name is not changed. For instance,
mv ~foxr/temp/foo2.txt .
would move foo1.txt to the user’s subdirectory temp without changing the name. However,
mv foo1.txt ~/temp/foo2.txt
would move the file and rename it from foo1.txt to foo2.txt.
To indicate that a file from a directory other than the current directory should be moved 
to the current directory, you would specify the directory and filename as source and use . 
as destination. For instance,
mv ~foxr/temp/foo2.txt.
would move foxr’s file foo2.txt, which is in his subdirectory temp, to the current working 
directory. Notice the use of ~ here, for the specification of the directory, you can use ~ and .. 
as needed.
If you are moving a file to the same directory, the command acts as a rename command. 
Otherwise, the file is physically moved from one directory to another, thus the file in the 
source directory is deleted from that directory. This physical “movement” is only of a link. 
The file’s contents, stored in disk blocks, is usually not altered.
*
The mv command can operate on multiple files if you are moving them all to a new 
directory and only if you use some form of filename expansion. For instance, you would 
not be allowed to specify
mv file1.txt file2.txt file3.txt /home/zappaf
as there are too many parameters. You are not allowed to rename multiple files in a single 
mv command as there is only one “newname” specified in the instruction and renaming 
multiple files into the same destination would not work.
*
The disk file may have to be moved only if the file is being moved to a different disk partition.


Navigating the Linux File System

83
If the mv operation would cause the file to be moved to the destination location where a 
file of the same name already exists, the user is prompted to see if the mv should take place 
and thus overwrite the existing file in the destination directory. You can force mv to oper-
ate without prompting the user by supplying the -f option. The -i option will prompt the 
user before overwriting the file (-i is the default so it does not need to be specified).
The copy command is 
cp
. It’s format is much the same as mv
cp [
options

source destination
Unlike mv, the file is physically copied so that two versions will now exist. There are 
three different combinations of source and destination that can be used. First, the destina-
tion specifier can be another directory in which case the file is copied into the new direc-
tory and the new file is given the same name as the original file. Second, if destination is 
both a directory and file name, then the file is copied into the new directory and given a 
different name. Third, the destination is a filename in which case the file is copied into the 
current directory under the new filename.
Let us look at some examples.
cp foo.txt ~zappaf/foo1.txt
will copy the file foo.txt from the current working directory to zappaf’s home directory, 
but name the new file foo1.txt rather than foo.txt.
Source can consist of multiple files by using wildcards. The following command pro-
vides an example:
cp *.txt ~
In this command, all files in the current directory that end with a .txt extension are 
copied to the user’s home directory.
Note that if the source and destination contain directories and they are the same direc-
tory, then cp will only work if the destination filename is different from the source file-
name. For instance,
cp foo1.txt .
will not work because you cannot copy foo1.txt onto itself.
The copy command has a number of different options available. The most common 
options are shown in Table 3.4.
Without the -p option, all copied items are given the current user’s ownership. For 
instance, if the files foo1.txt, foo2.txt, and foo3.txt in zappaf are all owned by zappaf with 
the group cit371, the operation
cp ~zappaf/foo*.txt .


84

Linux with Operating System Concepts
will copy each of these three files to your current working directory, and change the owner 
and group to be yours. Similarly, creation date and time are given the current date and time. 
But if you use -p, the copied items have the same owner, group, creation date and time, and 
permissions as the original files. This may be useful when you are copying files as root.
As noted in Table 3.4, cp has -i and -f options that are essentially the same as those found 
with the mv command. However, cp has another option worth discussing, -r. What does 


Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   27   28   29   30   31   32   33   34   ...   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