Linux with Operating System Concepts



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

recursive
copy do? The term recursive means that the copy is performed recursively. A 
recursive operation is one that operates on the files in the current directory but also works 
on the subdirectories. By recursive, we mean that the files (and subdirectories) in the sub-
directories are also copied. Consider the filespace illustrated in Figure 3.4. Assume t1, t2, 
t3, f1, f2, f3, b1, and b2 are files and all other items are directories.
The current working directory is ~dukeg. The command
cp -r ~foxr/temp .
would copy directory temp2 with the files f1, f2, and f3, but also subdirectories a and b, 
and the files b1 and b2 from directory b. These would be copied into ~dukeg so that dukeg 
bin
foxr
dukeg
marst
zappaf
temp
temp2
a
b
f1
f2
f3
b1
b2
t1 t2
t3
etc
home
usr
FIGURE 3.4 
Example file space.
TABLE 3.4 
Common Options for the cp Command
-b
Create a backup of every destination file
-f
Force copy, as with mv’s -f
-i
Prompt the user, as with mv’s -i
-I, -s
Create hard/symbolic link rather than physical copy
-L
Follow symbolic links
-p
Preserve ownership, permissions, time stamp, etc.
-r
Recursive copy (recursion is discussed below)
-u
Copy only if source newer than destination or destination missing
-v
Verbose (output each step as it happens)


Navigating the Linux File System

85
would now have directory temp2, files f1, f2, f3, and temp2 would have subdirectories a 
and b, files f1, f2, f3, and subdirectory b would have b1 and b2. The recursive copy is a very 
convenient way to copy an entire portion of the file system to another location. Of course, 
to copy the files and subdirectories, you would need to have adequate permissions.
3.3.3 File Deletion Commands
The next command to examine is 
rm
, for remove or delete. The rm command has the 
syntax
rm [
options

file(s)
As with mv and cp, the rm command can work on multiple files either by listing each 
item (separated by spaces) or using wildcards, or both. If a directory contained files file1.
txt, file2.txt, and file3.txt (and no other files ending in .txt), and you wanted to delete all 
three, either of the following instructions would work
rm file*.txt
rm file1.txt file2.txt file3.txt
Obviously, the first instruction is simpler. However, if the directory did contain other 
files whose names were similar, for instance, file4.txt and file10.txt, and you did not want 
those deleted, you would have to use the latter instruction.
As rm permanently deletes files, it is safest to use rm with the option -i. This option 
causes rm to pause before each file is deleted and ask the user if he or she is sure about 
deleting that file. The user responds with a ‘y’ or ‘n’ answer. Users may not think to use 
rm 
-i
, so it is common for a system administrator to create an alias of rm to rm -i so that, by 
default, rm is always run with the -i option.
If you are applying rm to a lot of files, for instance by doing 
rm *.txt
, you may not 
want to be bothered with having to respond to all of the prompts (one per item being 
deleted) and so you might use 
rm -f *.txt
to override the prompting messages. This 
can be dangerous though, so only use -f when you are sure that you want to delete the file(s) 
specified.
The -r option is the same as with cp, but in this case, the files and subdirectories are 
deleted. If you (or the system administrator) have aliased rm to be rm -i, then with -r you 
are asked before each deletion to confirm. This can be time consuming and undesirable. In 
this case, you might combine -f and -r, as in
rm -fr *
This will delete everything in the current directory, any subdirectories and their con-
tents as well. Of course you should explore the current directory before using such a com-
mand to ensure that you do not delete content mistakenly.
Notice that 
rm
-r
will delete directories. Generally, rm cannot delete a directory. 
You would have to use rmdir (explained below). But in the case of a recursive deletion, 


86

Linux with Operating System Concepts
directories can be removed once their contents are deleted. Referring back to Figure 3.4, 
the command
rm -fr /home/foxr/temp2
would delete the files and directories in this order: f1, f2, f3, b1, b2, a, b, temp2.
3.3.4 Creating and Deleting Directories
To create a directory, use 
mkdir
followed by the directory name as in
mkdir TEMP
The directory is created in the current working directory, unless a path is specified. 
The directory is initially empty. The permissions for the directory default to permissions 
that you have established previously through the 
umask
command. If you have not used 
umask, then they default to the umask value established by the system administrator. We 
look at umask in Chapter 9.
The mkdir command only allows for a few basic options. With -m or --
mode=
MODE

you can specify the initial permissions of the directory, otherwise they default to the per-
missions set up with umask. Alternatively, -Z or --
context=
CTX
can be used to spec-
ify SELinux (security enhanced) rather than normal permissions to control access to the 
directory. The context, 
CTX
, provides for rules that describe access rights. SELinux is dis-
cussed in Chapter 8.
To remove a directory, it must be empty. Therefore, you would have to delete its contents 
first. Once a directory is empty, to delete it, use the instruction 
rmdir
. Attempting to 
delete a nonempty directory yields the error message:
rmdir: failed to remove `dirname’: Directory not empty.
To delete the contents of the directory, you would want to use rm. By using the * wild-
card, it simplifies the rm operation. Now you will perform these three operations:
rm *
(in the directory will delete its contents)
cd ..
(to move to the parent directory)
rmdir 

Download 5,65 Mb.

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