Learning shell together (8-1) File Processing
Seven summaries: List Files, update modification time using touch, create and use temporary files, search for files, execute commands: xargs, file system space information, and compare files.
Ls
Syntax: ls [options] [file (s)]
Purpose: list the contents of a file directory.
Main options: Baidu result, which can be viewed by man ls.
-------------------------------------------------------------------------------
-A lists all files in the directory, including hidden files starting.
-B lists non-output characters in the file name in the form of a backslash and a character number (just like in C.
-C: the time when the I node of the output file is modified and sorted accordingly.
-D: display the directory like a file instead of the file under it.
-E outputs all the information of the time, rather than the brief information.
-F-U does not sort the output files.
-G is useless.
-I: index information of the I node of the output file.
-K indicates the file size in the form of k bytes.
-L list the details of a file.
-M horizontal output file name, with "," as a grid character.
-N is replaced by the UID and GID of the number.
-O displays the details of the file except the group information.
-P-F attaches a character to each file name to indicate the type of the file. "*" indicates the executable normal
File; "/" indicates a directory; "@" indicates a symbolic link; "|" indicates operating OS; "=" indicates a set
Ets ).
-Q used? Replace non-printable characters.
-R sorts directories in reverse order.
-S outputs the file size after each file name.
-T is sorted by time.
-U is sorted by the time when the file was last accessed.
-X is output by column and sorted horizontally.
-A displays all files except "." and.
-B does not output "~" End of the backup file.
-C is output by column and vertically ordered.
-G indicates the group information of the output file.
-L list the link file names instead of the linked files.
-N does not limit the file length.
-Q: Enclose the output file name in double quotation marks.
-R: list all files in subdirectories.
-S is sorted by file size.
-X is sorted by the file extension (the character after the last.
-One Line outputs only one file.
-- Color = no: Do not display color file names
-- Help displays help information on the standard output.
-- Version outputs the version information on the standard output and exits.
-----------------------------------------------------------------
Note: The Ls result is adaptive to the shell window size.
------------------------------------------------
# Hiding files
-L the first character on each line is described as the file type:-For general files, d for directories, l for symbolic connections, and the next 9 for file permissions, w write x execute r as read.
The Fifth Column is the file size in bytes, and the sixth column is the last modification time, month, day, and year. Indicates
----------------------
Display complete time precision:
[Root @ localhost ~] # Ls-l -- full-time/bin/kill
-Rwxr-xr-x 1 root 14864 03:52:31. 000000000 + 0800/bin/kill
Use touch to update the modification time: Baidu Parameters
----------------------------------------------------------------------------------
Touch-Modify the time stamp of a file.
Overview
Touch [-acm] [-r ref_file (reference file) |-t time (time value)] file (file Name )...
Obsolete version:
Touch [-acm] [ugly_time] file (file )...
GNU version:
Touch [-acfm] [-r file (reference file)] [-t decimtime (time Value)] [-d time (time value)] [-- time = {atime, access, use, mtime, modify}] [-- date = time] [-- reference = file] [-- no-create] [-- help] [-- version] [--] file (file )...
-------------------------------------------------
[Root @ localhost ~] # Touch-t 195002030000.00
[Root @ localhost ~] # Ls-l -- full-time
-Rw-r -- 1 root 0 00:00:00. 000000000 + 0800
-R replication time
[Root @ localhost ~] # Touch-r a B
[Root @ localhost ~] # Ls-l -- full-time B
-Rw-r -- 1 root 0 00:00:00. 000000000 + 0800 B
Establishment and use of temporary files:
/Tmp and/var/tmp
Introduction:/tmp will be cleared when the system is started, while/var/tmp still exists because some text editing programs will store their backup files here, in this way, data can be recovered after the system is damaged. Most systems place/tmp in the file system of ordinary storage for quick access. Set/tmp permissions for security issues.
$ Variable:
Trap
Mktemp: create a secure file name.
/Dev/random and/dev/urandom special files
Search for files:
Search for files quickly:
Locate
--------------------------
View gcc location
[Root @ localhost ~] # Locate gcc
/Lib/libgcc_s-4.1.2-20080825.so.1
/Lib/libgcc_s.so.1
/Lib64/libgcc_s-4.1.2-20080825.so.1
/Lib64/libgcc_s.so.1
/Root/nginx/nginx-0.8.46/auto/cc/gcc
........................................ ........
Search for the command storage location type:
When a command without a path is used for flavor, it is located in the file system.
Find
The biggest difference between Find and other UNIX commands is that the files and directories to be searched must be placed first in the parameter list, and the directories are almost recursively drilled down (for search ), the option or operation of the selected name to be displayed is placed at the end of the command line.
1. The common form of the find command is;
Find pathname-options [-print-exec-OK...]
2. Parameters of the find command;
Pathname: directory path searched by the find command. For example, use "." To represent the current directory, and use "/" to represent the root directory of the system.
-Print: The find command outputs matching files to the standard output.
-Exec: The find command executes the shell command given by this parameter on the matching file. The corresponding command is in the form of 'command' {}\;. Note the space between {} And.
-OK: The Role of-exec is the same, but the shell command given by this parameter is executed in a safer mode. A prompt is displayed before each command is executed, let the user determine whether to execute.
---------------------------------------------------------
-Name
Search for files by file name.
-Perm
Find the file according to the file permission.
-Prune
This option can make the find command not to be searched in the specified directory. If the-depth option is used at the same time,-prune will be ignored by the find command.
-User
Search for files by file owner.
-Group
Find the file according to the file group.
-Mtime-n + n
Find the file according to the file change time.-n indicates that the file change time is less than n days from now, and + n indicates that the file change time is earlier than n days from now. The find command also has the-atime and-ctime options, but they both have the-m time options.
-Nogroup
Find the file with no valid group, that is, the group to which the file belongs does not exist in/etc/groups.
-Nouser
Find a file without a valid owner, that is, the owner of the file does not exist in/etc/passwd.
-Newer file1! File2
Find the file whose modification time is newer than file1 but earlier than file2.
-Type
Find a type of file, such:
B-block device files.
D-directory.
C-character device file.
P-MPs queue file.
L-Symbolic Link file.
F-common file.
-Size n: [c] searches for files with a length of n blocks. If a file contains c, the file length is measured in bytes.
-Depth: when searching for a file, first find the file in the current directory and then find it in its subdirectory.
-Fstype: searches for files in a certain type of file system. These file system types can usually be found in the configuration file/etc/fstab, this configuration file contains information about the file system in the system.
-Mount: the mount point of the file system is not crossed during file search.
-Follow: If the find command encounters a symbolic link file, it will trace the file to which the link points.
-Cpio: Use the cpio command to back up the files to the tape device.
----------------------------------------------
Find is different from ls and shell: it does not have the concept of hiding files, and the file name starting with a dot can also be found by find. In addition, find does not sort file names. It is displayed sequentially as it reads the directory. Random sorting. When the final find process directory, it will automatically dive into the directory structure to find anything under it, unless you do not want to do so using the-prune option.
Note: You must thoroughly execute debugging when using find to execute a destructive shell script, for example, insert echo before the command.
.
Note:
-The size option must be followed by a numeric parameter. The default value is 512 bytes.
-The type option must be followed by a parent parameter to indicate the file type.
-The follow option requires the find to connect to the symbolic connection. You can use this to locate the disconnected connection:
-The links option requires an integer to be connected. If no plus or minus sign is specified, it only selects a specified number of directly connected files, if it is a negative number, only the files with the number of connections less than this number (absolute value) will be searched. If it is a positive number, the files with the number of connections greater than this number will be selected. Find.-links + 1
-The atime \-ctime \-mtime option must be connected to an integer in the unit of days. If the positive and negative signs are not specified, that is, if they are negative a few days ago, it means less than the number of days (absolute value ). If it is positive, it is later than the specified number of days. Generally, use find.-mtime-7 to query and modify the files modified a week ago.