file system: Access files by name
Files and directories are organized into a single inverted tree structure
The file system starts with the root directory, denoted by "/"; Root file System (ROOTFS): root filesystem
Files with a . Start as hidden files
There are two types of data in a file:
Metadata (metadata): Data describing Data properties: file name, size, property, date ... For example: A person's height and weight
Data: Real data within a file
File system hierarchy: LSB Linux standard Base
Fhs:filesystem Hierarchy Standard
(Example: The disk is divided into a, b two partitions, once a is defined as the root partition, the B partition wants to be accessed, must be connected to a directory already existing on the root partition, as the portal of the B partition, can be accessed)
File name rules
File name up to 255 bytes
Filenames, including brutishness, have a maximum of 4,095 bytes. 2^10*4=4k
(ANSI color file name color standard) blue-to-catalog, green-to-executable, red-to-zip, light blue-to-link, purple-to-socket (socket) file, gray-to-other files
Standard Linux file System (mainstream file system such as EXT4,XFS), file name case sensitive
File system Structure
/boot: Boot file directory, kernel file (vmlinuz), boot loader (bootloader,grub), Initramfs are stored in this directory
/bin: A basic command for all users to use, a program that is used by OS startup and cannot be associated to a separate partition
/sbin: A basic command to store management classes; A program that is used by OS startup and cannot be associated to a separate partition
/lib: Basic shared library files that the program relies on at startup and kernel module files (/lib/modules)
/LIB64: storage location for secondary shared library files dedicated to x86_64 systems
/etc: Configuration file directory (Linux philosophy, with text files to store configuration files)
/home/username: Normal User home directory
/root: Administrator's home directory
/media: Portable Mobile device mount point (for example, USB flash drive is associated with media access)
/MNT: Temporary file system mount point
Shorthand for/dev:devices, all device files and special file storage locations
B:block device (block device) random access, such as disk
C:character device (character devices) linear access, such as keyboard
/opt:optional (optional) third-party application installation directory
/srv:services, data used by services running on the system
/tmp:temporary abbreviated, temporary file location (file system that is not used for more than 30 days is automatically deleted)
/usr:universal shared,read-only Data Global shared read-only
Bin: An application that ensures that the system has full functionality
Sbin
Lib:32 bit use
LIB64: Only 64-bit systems exist
Include:c header file for the program (header files)
Share: structured independent data such as Doc, man, etc.
Local: Installation location for third-party applications, 3rd Party:bin, Sbin, lib, lib64, etc, share
Cache: The application caches the data directory
LIB: Application state information data (that is, not a library file)
Local: Dedicated to storing variable data for applications under/usr/local;
Lock: Lock file
LOG: Logs directory and files
OPT: Dedicated to storing variable data for applications under/OPT;
Run: Process-related data in progress, typically used to store process PID files
Spool: Application Data Pool
TMP: Save temporary data generated between system two reboots
/proc: For the output kernel and the process I west to the related virtual file system
/sys: For outputting information about hardware devices on the current system virtual file system
/selinux: storage location for information such as security enhanced linux,selinux related safety policies
Most of the cases, the/selinux is off , it's too strict
All applications on Linux 4 class main constituent files
Binaries (applications):/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin
Library files :/lib,/lib64 ...
configuration Files :/etc,/etc/directory, ...
Help file :/usr/share/man,/usr/share/doc ...
Types of files under Linux (Distinction on metadata)
-: Normal file
D: Catalog Files directory
L: Symbolic Link file Symbolic link
B: Block devices blocks device (randomly accessed device files)
C: Character device character device (linear access to the corresponding equipment file)
P: Pipe file Pipe,fifo (first in,first out). /Advanced after the call stack/
S: Socket file socket
Show current working directory PWD
Absolute path and relative path
Do not start with /
Specify a location relative to the current working directory or a directory
You can specify a file name as a short form, such as ./
Base name: basename, a file path to the right of the filename,
Directory Name: dirname, all except basename name Directory name
Change Directory
CD changes directory; (change directory)
Use absolute path or relative paths
Switch to Parent directory: CD.
Switch to the current user home directory: CD
Switch to the first working directory: CD-
Command ls
Usage: LS [options] [Files_or_dirs]
Example:
Ls-a: List contains hidden files
Ls-l: Displays additional information (Metadate metadata),
Ls-r: Recursive display of all files, including sub-directories under sub-files and subdirectories ... (generally using tree)
LS-LD:-D indicates that the path itself is displayed and is typically used with-l
Example: Ls-a, Ls-l
A total of 10, the first letter for the file type, rwx 3 for the group, is the main/group/other user's use rights
Indicates the number of hard links to a file
Indicates who is the owner and the group
Represents file size, special files are displayed as 2-bit
Represents a modified timestamp (modify Time/mtime) and a file name
Example: Ls-ld
View file status
Stat
File: metadata, data
Three time stamps:
Access time: Atime, reading the contents of a file
Modify Time: Modified, Mtime, change file contents (data)
Change time: Changing times, ctime, meta data changes
(The data changes the metadata must change, the metadata changes the data may not change)
File name wildcard character, Glob,globing,wildcard
* Match 0 or more characters
? Match any single character
[0-9] Matching number range
[A-Z]: letters (case insensitive)
[A-Z]: letters (case insensitive)
[ABCD] matches any one of the characters in the list
[^ABCD] matches characters other than all characters in the list (de-inverting)
Pre-defined character class: Man 7 glob
[:d Igit:]: Any number, equivalent to 0-9
[: Lower:]: Any lowercase letter
[: Upper:]: Any uppercase letter
[: Alpha:]: Any case letter
[: Alnum:]: Any number or letter
[: Blank:]: horizontal white space character
[: Space:]: Horizontal or vertical whitespace characters
[:p UNCT:]: Punctuation
[:p rint:]: Printable characters
[: Cntrl:]: Control (nonprinting) character
[: Graph:]: Graphic character
[: Xdigit:]: hexadecimal character
Create File and Refresh time
Touch Command : Change 3 timestamps at the same time; Create an empty file if the file does not exist
Touch [OPTION] ... FILE ...
-A changes atime and CTime to the current time only
-M only changes mtime and CTime to the current time
-t specifies timestamps for atime and Mtime [[CC]YY]MMDDHHMM[.SS]
-C If the file does not exist, it is not created
copy :cp [OPTION] source target
-I: Pre-overwrite hint –n: Do not overwrite, note both order
-R,-r: recursively replicate directories and all internal content
-A: Archive, equivalent to-DR--preserv=all
-d:--no-dereference--preserv=links does not copy the original file, only the link name is copied
--preserv[=attr_list]
Mode: Permissions
Ownership: Belong to the main group
Timestamp
Links
Xattr
Context
All
-P: Equivalent--preserv=mode,ownership,timestamp
-V:--verbose, more information
-F:--force
-u:--update only copy files that do not exist for the source than the target update file or destination
--backup=numbered Target exists, back up plus digital suffix before overwriting
Move and rename files
MV Command common option (options):
-I: Interactive
-F: Mandatory
-T: Source behind, target position in front
Delete
RM [OPTION] ... FILE ... (delete files only)
Common options:
-I: Interactive
-F: Force delete
-R: Recursive (used when you want to delete a folder)
--no-preserve-root
Example:
RM-RF/(Delete the root file, i.e. delete all data)
Directory Operations
Tree Display directory trees
-D: Show only directories
-L Level: Specify display layer progression
-P Pattern: Displays only the paths that are matched by the specified pattern
mkdir Creating a directory
-P: exists in no error, and can automatically create the required directories (create an empty directory of purchased only son
-V: Show more information
-M MODE: Create a directory to specify permissions directly
rmdir Delete empty directories (rarely used)
-P: Recursive deletion of empty parent directory (delete empty directory of one vein only son)
-V: Show more information
rm-r Recursively delete a directory tree (used when a non-empty directory is deleted)
PS: Production environment in not 100% clear what you are doing do not delete any directory (can be manually established to recycle Bin, using the MV command to move to the Recycle Bin)
Inode (Index node)
The inode(Index node) table contains a list of all file system files
A node (an index node) is a table item that contains information about the file (metadata), including:
File type, permissions, Uid,gid
Number of links (pointing to the number of path names for this file name)
The size of the file and the different timestamps
Data block pointer to file on disk
Additional data about the file
ls-i Display inode number
Directory
File reference is an inode number (cross file system/partition, Inode number cannot be shared)
A person is referring to a file by file name
A directory is a mapping between a file name and an inode number in a directory
CP and Inode
Allocate a free inode number to generate a new entry in the Inode table
Create a catalog entry in the directory, associating the name with the inode number
Copy data to generate a new file
RM and Inode
The number of links is decremented, thus releasing the inode number can be reused
Put data blocks in the free list
Delete a catalog entry
RM data is not actually deleted immediately, but is overwritten when another file uses a block of data
MV and Inode
If the target and source of the MV command are in the same file system,
Create a corresponding directory entry with a new file name
Delete old directory entry pairs for older file names
Does not affect the Inode table (except timestamp) or data location on disk: No data is moved
If the target and source are in a different file system, MV is equivalent to CP and RM 2 steps
Hard links and soft links (symbolic links)
Hard Links: Different file paths point to the same inode
ln filename [linkname]
Creating a hard link adds an additional record entry to reference the file (increasing the reference count of the Inode)
Hard links correspond to the same file system as the same physical file
Directory does not support hard links
Increased number of links when creating hard links
When deleting files:
RM command reduces number of hard links
File to exist, with at least one link number
When the number of links is 0 o'clock, the file is deleted
Symbolic link/Soft Link:
ln-s filename [Linkename]
(Original path, link path) The link path does not point to the inode, but instead points to the original path
The path of a symbolic link to another file
Ls-id display the name of the link and the referenced file
Soft links can be used for directory
Can span partitions
A path to another file whose size points to the length of the path string, without increasing or decreasing the target file Inode reference count
Standard inputs and outputs
Program: Instruction + data
Read-in data: Input
Outputs data: Output
The open file is also a file descriptor (Fd:file descriptor)
3 Types of I/O devices for Linux programs
input, default. Standard input: (STDIN)-0 accepts input from the keyboard by default
/dev/stdin,keyboard
output, default. Standard output: (STDOUT)-1 Default output to terminal window
/dev/stdout,terminal Monitor
error, default. Standard error: (STDERR)-2 default output to Terminal
/dev/stdout,
I/O redirection: Changing the default location
Re-export the output and errors to the file
StdOut and stderr can be redirected to a file
Command Action Symbol file name
Supported operational symbols include:
> >> redirect stdout to file
2> 2>> redirect stderr to file
&> &>> (Command >/path/to/file.out 2>&1, Command >>/path/to/file.out 2>&1) Redirect all output to file
> Overwrite file,>> not overwrite file, append later
Standard output and error outputs are directed to different locations : COMMAND >/path/to/file.out 2>/path/to/error.out
StdOut for merging multiple programs:(Cal 2007;cal) > All.txt
Files can contain multiple types of data
Check the file type, and then determine the appropriate open command or application to use
file [options] <filename>
Pipe (using the symbol "|" Used to connect commands
Command 1 | Command 2 | Command 3 | ...
Send stdout of command 1 to stdin of command 2, stdout of command 2 to stdin of command 3
StdErr cannot be piped forward by default and can be implemented with 2>&1 or |&
The last command executes in the child shell process of the current shell process to
The ability to combine multiple tools
ls | Tr ' A-Z ' A-Z
Basic knowledge of Linux Primer 2