Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet39/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   35   36   37   38   39   40   41   42   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

Expression
Meaning
Example
-amin [
+−
]
n
Find all files accessed 
>

<
or 
=
n
minutes ago
-amin 
+
10
-anewer 
file
Find all files accessed more recently than 
file
-anewer file1.txt
-atime [
+−
]n
Find all files accessed 
>

<
or 
=
n
days ago
-atime -1
-cmin [
+−
]n
Find all files created 
>

<
or 
=
n
minutes ago
-cmin 60
-cnewer 
file
Find all files created more recently than 
file
-cnewer abc.dat
-ctime [
+−
]n
Find all files created 
>

<
or 
=
n
days ago
-ctime 
+
3
-mmin [
+−
]n
Find all files last modified 
>

<

=
n
minutes ago
-mmin -100
-mtime [
+−
]n
Find all files last modified 
>

<

=
n
days ago
-mmin 1
-newer 
file
Find all files modified more recently than 
file
-newer foo.txt
-empty
Find all empty files and directories
-executable,
-readable,
-writable
Find all files that are executable, readable, or writeable
-perm 
test
Find all files whose permissions match 
test
-perm 755
-fstype 
type
Find all files on a file system of type 
type
-fstype nfs
-uid n
-gid n
Find all files owned by user 
n
or group 
n
-uid 501
-user name
-group name
Find all files owned by user name or group name
-user zappaf
-regex 
pattern
Find all files whose name matches the regular expression in 
pattern
-regex [abc]
+
\.txt
-size [
+−
]n
Find all files whose size is 
>

<

=
n

n
can be followed by b 
(512-byte blocks), c (bytes), w (2-word bytes), k (kilobytes), 
M (megabytes), and G (Gigabytes)
size 
+
1024c
size 
+
1 k
-type 
type
Find all files of this type
type
is one of b (block), c 
(character), d (directory), p (pipe), f (regular file), l 
(symbolic link), s (socket)


Navigating the Linux File System

97
it by one or more debugging options of 
help

tree

stat

opt
, and 
rates
.
*
Ordering of 
expressions allows find to attempt to optimize the expressions provided in order to reduce 
search time. Ordering is specified by -O followed by an optimization number with no 
space between them, as in 
-O3
. The optimization number is between 0 and 3 with 3 being 
the most optimized. Note that while optimization will reduce search time, it takes longer 
to set up the search query. Therefore, optimization has a tradeoff and the higher the opti-
mization level, the slower find will be to start. Depending upon the size of the file space 
being searched, optimization may or may not be useful.
Aside from these options, you can also specify options in the expression portion of the 
command. These include 
-daystart
so that -amin, -atime, -cmin, -ctime, -mmin, and 
-mtime all start from the start of the day rather than 24 hours earlier. For instance, by say-
ing “search for files created 1 day ago,” if you add -daystart, then “1 day ago” literally means 
at any time of the day before midnight” rather than “exactly 24 hours ago.”
The option 
-depth
indicates that item should be sought (or acted upon) before the 
current directory itself is acted upon. This is useful when doing a recursive deletion. Next, 
-maxdepth
, which is followed by a nonnegative integer, indicates how far down the 
file system find should search from the given directory. Typically, find will search all 
subdirectories from the directory specified to the leaf level of the file space. By indicating 
-maxdepth 1
, aside from the current directory, find will only search subdirectories of the 
current directory. There is also a 
-mindepth
. Finally, 
-mount
indicates that find should 
not go down any directories that are mounted.
The default action for find is to list all matches found to the terminal window. Find can 
also perform other operations, as indicated in Table 3.7.
As the find program is far more complicated than the GUI Search for Files program, you 
might question its use. However, keep in mind that the GUI program takes more resources 
to run and would be unavailable if you are accessing a Linux machine through a text-only 
interface. Additionally, the find command offers a greater degree of control. Finally, find 
can be used in a shell script or in a pipe and obviously the GUI search program cannot. It 
is worthwhile learning find, but be patient in learning to use it correctly.
3.4.3 Other Means of Locating Files
There are several other options to locate items in the file system. To locate an executable 
program, use 
which 
name
where 
name
is the program’s name. This works as long as 
the program is located in a directory that is part of the user’s PATH variable and as long 
as the program is accessible by the user. Try for instance 
which useradd
and you 
will receive an error because you, the user, do not have access to useradd. The program 
whereis
is similar in that it will locate a program’s location. But whereis does not rely 
on the PATH variable. Additionally, if available, whereis will also report on all locations 
relevant to the program: the executable program itself (binary), the source code (usually 
stored in a /lib subdirectory) and the manual page (usually stored under /usr/share/man).
*
See find’s man page to explore debugging options in more detail.


98

Linux with Operating System Concepts
Two other available programs are 
locate
and 
slocate
. Both of these commands 
access a database storing file locations. To update (or create) the database for the locate 
command, use the command 
updatedb
. The option -U allows you to specify a portion of 
the filespace to update. For instance, 
updatedb -U /home/foxr
would only update 
the portion of the database corresponding to user foxr’s home directory. Once the database 
is established, the locate instruction is simply
locate [
option

string
which responds with the location within the file system of all files that match the given 
string
. The common options are -c to count the number of matches found and output the 
count rather than the matched files, -d 
file
to use 
file
as a substitute database over the 
default database, -L to follow symbolic links, -i to ignore case, -n # to exit after # matches 
have been found, and -r 
regex
to use the regular expression (
regex
) instead of the string.
The slocate instruction is newer and is used with SELinux. Unlike locate, slocate can 
operate without updatedb by using the -u or -U option. With -u, the database is updated 
by examining the entire file system. With -U, as with updatedb, you can specify a portion 
of the file system.
Keep in mind that updating the database can be time consuming. Users are not allowed 
to update the database because they will not have write access to the database. Therefore, 
updating is done by the system administrator. And to prevent the update from taking too 
TABLE 3.7 
Find Actions

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   35   36   37   38   39   40   41   42   ...   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