1. Trang chủ
  2. » Thể loại khác

Tài Liệu - Võ Tấn Dũng (votandung) Unit7 Linux ITC

27 67 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 27
Dung lượng 2,42 MB

Nội dung

Tài Liệu - Võ Tấn Dũng (votandung) Unit7 Linux ITC tài liệu, giáo án, bài giảng , luận văn, luận án, đồ án, bài tập lớn...

Information Technology College of HoChiMinh city Faculty of Information Technology Course: Fundamentals of Linux OS Unit File Utilities Lecturer: Võ Tấn Dũng votandung@yahoo.com http://sites.google.com/site/votandungsg/ Inode Numbers • Inode numbers are identifiers of a file on a file system, an inode number is unique for each file in a file system • Each file and directory has an inode number assigned to it by the system These numbers can be seen by using the following ls command • The numbers to the left of the file name are the inode numbers $ ls -i ~ 12110 dante 12115 dante_1 67773 dir1 68349 dir3 68451 dir4 12169 file1 12118 file3 12119 file4 68552 practice VÕ TẤN DŨNG Linking Files and Directories • Links are used to create alternate names or aliases for files and directories on a system • In this way, different users can refer to the same file or directory by names they are more comfortable with or names that are shorter • There are two kinds of links: hard and symbolic (or soft) VÕ TẤN DŨNG Hard Links • Hard links : – are used to link files on the same file system – files that are hard linked share the same inode number – refer to the same data on the hard disk • Hard links are not used: – to link directories and cannot cross file systems, as the inode number is only unique for that file in its current file system – a completely different file may have the same inode number on a different file system VÕ TẤN DŨNG Hard Links (cont.) • The output of the ls -l command shows a link count following the permissions This is a count of how many files are hard linked to the same inode number $ ls -l ~ -rw torey -rw torey drwx x x torey drwx x x torey staff staff staff staff 1320 368 512 512 Oct 19 dante Oct 19 dante_1 Oct 19 dir1 Oct 19 dir2 • The link count on directories includes a link to the current directory (.) and from the parent ( ) directory, and a number for each file or subdirectory included in the directory VÕ TẤN DŨNG Hard Links (cont.) • All hard-linked files share the same inode number and therefore the same data • This data can be displayed using an appropriate command; for example, cat or more • In the case of hard links, as long as one file that refers to the inode number remains, the data remains available on the system • For this reason, File1 and File3 could be deleted, leaving the information referred to intact, as File2 would still exist VÕ TẤN DŨNG Symbolic Links • Symbolic links are used to link a file or directory across file systems • Since symbolically linked files not share a single inode, these links can cross file system boundaries • The following commands indicate that the file symlink is a symbolically linked file: $ ls -l Test -rw-r r-lrwxrwxrwx torey staff torey staff 35 May linktest May 12 symlink > linktest $ ls -F linktest symlink@ VÕ TẤN DŨNG Symbolic Links (cont.) • The structure of a symbolic link is as follows: • The data contained in File2 is the absolute pathname to File1, but displaying either File1 or File2 will produce the same output • If File2 is deleted, there is no effect on File1 • If File1 is deleted File2 will still exist, but it will point to an invalid file name and therefore be of no practical use VÕ TẤN DŨNG The ln Command • Use the ln command to create hard or symbolic links Command Format ln [-s] source_file target_file • By default, the ln command will create a hard link • The -s option is used to create a symbolic link • The source_file is the existing file and the target_file is the new file to be linked to the source_file VÕ TẤN DŨNG The ln Command (cont.) Attention: - Can not create a hard link to a directory - Can only create hard link within a same partition - Can create a symbolic link even if the file linked not exist - When creating a symbolic link, target_file and source_file must be specified in absolute pathnames cp command: - The cp command can be used to create links - With option -i: cp creates hard links for files instead of copying - With option -s: cp creates a symbolic link to the file instead of copying VÕ TẤN DŨNG The find Command (cont.) VÕ TẤN DŨNG The find Command (cont.) VÕ TẤN DŨNG Using the find Command • You can: Search for openwin starting at the /usr directory $ find /usr -name openwin /usr/openwin /usr/openwin/bin/openwin Search for files ending in tif starting at the /usr directory $ find /usr -name ’*tif’ /usr/openwin/demo/kcms/images/tiff/ireland.tif /usr/openwin/demo/kcms/images/tiff/new_zealand.tif VÕ TẤN DŨNG Using the find Command (cont.) Search for core files starting at the user’s home directory and delete them $ find ~ -name core -exec rm {} \; Look for all files, starting at the current directory, that have not been modified in the last 90 days $ find -mtime +90 Find files larger than 400 blocks (512-byte blocks) starting at /etc $ find /etc -size +400 VÕ TẤN DŨNG Additional Features of the find Command You can: • Find files with open permissions starting at the user’s home directory $ find ~ -perm 777 -depth > holes • Find files owned by a specific user or group in the current directory hierarchy, list them, and put the listing in a file for later viewing $ find -user billw -o -group staff -ls > review • Find files, starting at /etc, which share the same inode number $ find /etc -inum 769 VÕ TẤN DŨNG The grep Command • Use the grep command to search a file for a specified text string • A string is one or more characters; it can be a character, a word, or a sentence A string can include white space or punctuation if these are enclosed in quotations • The grep command searches a file for a character string and prints all lines that contain that pattern to the screen • The grep command can be used as a filter with other commands • The grep command is case sensitive You must match the pattern with respect to uppercase and lowercase letters, unless you use the –i option VÕ TẤN DŨNG The grep Command (cont.) Command Format grep [option(s)] string filename Options: • -i : ignore case of string when searching • -v : search for all lines that not match string The following examples show how to search lines in a file or standard output $ grep root /etc/passwd root:x:0:1:Super-User:/:/sbin/sh $ ls -la | grep -i ’jun 11’ drwxr-xr-x user1 staff 512 Jun 11 13:13 dir4 If the date is a single numeral date, the grep string needs to have two spaces between the month and the numeral; for example, Jun VÕ TẤN DŨNG The sort Command • The sort command provides a quick and easy way for operators to organize data in either numerical or alphabetical order • This command uses the ASCII character set as its sorting order, working from left to right on a character-by-character basis • By default, sort relies on white space to delimit the various fields within the data of a file Some sort features include: – Multilevel sorting – Field-specific sorting – Accepting standard input – Producing standard output VÕ TẤN DŨNG The sort Command Command Format sort [ options] [input_filename] options : • The various options available with the sort command enable the operator to define the type of sort to perform as well as the field on which to begin sorting (see in the next slide) VÕ TẤN DŨNG The sort Command (cont.) VÕ TẤN DŨNG Using sort With Different Options • The following examples show the sort command in a simple format The first sort command produces an ASCII type of sort, beginning with the first character of each line The second example is a numerical sort on the second field (sort skips one separator with the +1 syntax) $ cat fileA Annette 48486 Jamie 48481 Clarence 48487 Sondra 48483 Janet 48482 $ $ sort fileA Annette 48486 Clarence 48487 Jamie 48481 Janet 48482 Sondra 48483 $ sort +1n fileA Jamie 48481 Janet 48482 Sondra 48483 Annette 48486 Clarence 48487 VÕ TẤN DŨNG Using sort on Different Fields Within a File $ ls -ld f* > list $ cat list -rw - melissao staff -rw - melissao staff -rw - melissao staff -rw - melissao staff -rw - melissao staff -rw - melissao staff -rw - melissao staff 218 218 1696 105 218 56 57 Jul Jul Oct Oct Oct Mar Mar 15 16:47 15 16:48 19 1998 19 1998 19 1998 09:52 09:53 feathers feathers_6 file1 file2 file3 fruit fruit2 VÕ TẤN DŨNG Using sort on Different Fields Within a File (cont.) $ sort -rn +4 list -o num.list $ cat num.list -rw - melissao staff 1696 -rw - melissao staff 218 -rw - melissao staff 218 -rw - melissao staff 218 -rw - melissao staff 105 -rw - melissao staff 57 -rw - melissao staff 56 Oct 19 1998 Oct 19 1998 Jul 15 16:48 Jul 15 16:47 Oct 19 1998 Mar 09:53 Mar 09:52 file1 file3 feathers_6 feathers file2 fruit2 fruit • This example represents beginning a sort on some field other than the first, and shows a numeric, reverse-order example The sort command line would read as, “Do a reverse order, numeric sort on the fifth field of the data in the file list, and place the output into a file called num.list.” VÕ TẤN DŨNG Using sort on Different Fields Within a File (cont.) $ sort +5M +6n list -o update.list $ cat update.list -rw - melissao staff 56 Mar 09:52 -rw - melissao staff 57 Mar 09:53 -rw - melissao staff 218 Jul 15 16:47 -rw - melissao staff 218 Jul 15 16:48 -rw - melissao staff 105 Oct 19 1998 -rw - melissao staff 218 Oct 19 1998 -rw - melissao staff 1696 Oct 19 1998 fruit fruit2 feathers feathers_6 file2 file3 file1 • This example represents a multilevel sort showing how the M option would work This command would read as “Do a Month order sort beginning with the sixth field Do a second-level sort in numeric order and begin on the seventh field (this will sort the numeric day of the month correctly), name the output file update.list.” VÕ TẤN DŨNG END OF UNIT • remember to your homework (see http://sites.google.com/site/votandungsg/) VÕ TẤN DŨNG ... 48487 VÕ TẤN DŨNG Using sort on Different Fields Within a File $ ls -ld f* > list $ cat list -rw - melissao staff -rw - melissao staff -rw - melissao staff -rw - melissao staff -rw - melissao... fruit fruit2 VÕ TẤN DŨNG Using sort on Different Fields Within a File (cont.) $ sort -rn +4 list -o num.list $ cat num.list -rw - melissao staff 1696 -rw - melissao staff 218 -rw - melissao... files VÕ TẤN DŨNG The find Command (cont.) VÕ TẤN DŨNG The find Command (cont.) VÕ TẤN DŨNG Using the find Command • You can: Search for openwin starting at the /usr directory $ find /usr -name

Ngày đăng: 15/12/2017, 16:49

TỪ KHÓA LIÊN QUAN