Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to Linux system directories and commands

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Describe the naming rules and uses of the system directory names for Linux distributions.

Directory naming rules:

(1) the maximum file name is 255 bytes.

(2) the maximum length of file name, including path, is 4095 bytes.

(3) all characters are valid except slash and NUL. However, directory names and files that use special characters are not recommended, and some characters need to be referenced in quotation marks

(4) Standard Linux file system (such as ext4) with case-sensitive file names

System directory name and purpose

[root@centos7 /] # tree-d-L 1 /

/

├── bin-> usr/bin / / basic commands used by all users; programs that cannot be associated to a separate partition and will be used when OS starts

├── boot / / boot files are stored in this directory, and kernel files (vmlinuz) and boot loaders (bootloader, grub) are all stored in this directory

├── data / / this folder is self-built for users

├── dev / / device files and special file storage location

├── etc / / configuration file directory

├── home / / ordinary user home directory

├── lib-> basic shared library files and kernel module files that the program depends on at startup (/ lib/modules)

├── lib64-> usr/lib64 / / is dedicated to the location of auxiliary shared library files on x86 shared 64 systems

├── media / / Portable mobile device mount point

├── mnt / / temporary file system mount point

Installation location of ├── opt / / third-party applications

├── proc / / is used to output kernel virtual file systems related to process information

├── root / / administrator's home directory

├── run / / is home to all kinds of data in order to better organize run-time data in the Linux file system.

├── sbin-> basic commands of the usr/sbin / / management class; programs that cannot be associated to a separate partition and will be used when OS starts

Data used by services running on the ├── srv / / system

├── sys / / is used to output information about hardware devices on the current system, virtual file system

├── tmp / / temporary file storage location

├── usr / / universal shared, read-only data

└── var / / includes data to be changed while the system is running

2. What is the metadata information of the description file, what does it mean, and how to view it? How to modify the timestamp information of a file?

View file metadata

[root@centos7 data] # stat test.txt

File: 'test.txt'-- filename

Size: 0-- size Blocks: 0-- number of blocks occupied IO Block: 4096-- Block size regular empty file-- File type

Device: fd02h/64770d-- device Inode: 67-- inode number Links: 1-- number of hard links

Access: (0644)-- access permission Uid: (0 / root)-- owner Gid: (0 / root)-- subordinate group

Context: unconfined_u:object_r:etc_runtime_t:s0

Access: 2020-02-13 19rig 46purl 00.164949782 + 0800-the last time the file was accessed

Modify: 2020-02-13 19rig 46purl 00.164949782 + 0800-the modification time of the file

Change: 2020-02-13 19ore46Rich 00.164949782 + 0800-the time the file was changed

Birth:-

Modify file timestamp

Touch [OPTION]... FILE...

OPTION:

-a change only atime and ctime

-m changes only mtime and ctime

-t [[CC] YY] MMDDhhmm [.ss] specifies the timestamp of atime and mtime

3. Summarize the difference between soft connection and hard connection, and illustrate it with an example. Hard links and soft links are essentially the same file with multiple different names, and soft links only point to the corresponding files, similar to whether shortcuts in windows can cross disk partitions, can't link directories, can't be equal to each other. Relatively independent file type with the same number of links as the source file, increase the number of links after being linked, do not increase the number of links 4, what are the file management commands on the Linux, their commonly used methods and related examples demonstrate. Pwd displays the absolute path of the current shell CWD

Syntax:

Pwd (option)

Options:

-P shows the real physical path

-L displays the link path (default)

Example:

[root@localhost ~] # pwd

/ root

Cd changes the directory

Syntax:

Cd (option) (parameter)

Options:

-p if the target directory you want to switch to is a symbolic link, switch directly to the target directory that the symbolic link points to

-L if the target directory you want to switch is a symbolic connection, switch directly to the directory represented by the character connection name, rather than the target directory that the symbolic link points to.

When only the "-" option is applied, the current working directory will be changed to the directory represented by the environment variable "OLDPWD".

Example:

Cd enters the user's home directory

Cd ~ enter the user's home directory

Cd-return to the directory where you were before entering this directory

Cd.. Return to the parent directory (if the current directory is "/", it will still be "/"; ".." after execution. " For the meaning of the superior directory)

Cd.. /.. Return to the upper two-level directory

Cd! $uses the parameter of the previous command as the cd parameter.

Ls lists the contents of the current directory or specifies a directory

Syntax:

Ls (option) (parameter)

Example:

Ls-a contains hidden files

Ls-l displays additional information

Ls-R directory recursion

Ls-ld directory and symbolic link information

Ls-1 file branch display

Ls-S is sorted from largest to smallest

Ls-t sort by mtime

Ls-u with the-t option, display and sort by atime from new to old

Ls-U is displayed in directory storage order

Ls-X sorts by file suffix

Stat is used to display the status information of the file.

Syntax:

Stat (option) (parameter)

Options:

-L: supports symbolic connections

-f: displays the file system status instead of the file status

-t: output information in a concise way

-- help: displays the help information for the instruction

-- version: displays the version information of the instruction.

Example:

[root@localhost ~] # stat myfile

File: "myfile"

Size: 0 Blocks: 8 IO Block: 4096 General empty file

Device: fd00h/64768d Inode: 194805815 Links: 1

Access: (0644) Uid: (0 / root) Gid: (0 / root)

Access: 2010-12-12 12 purl 22 purl 35.000000000 + 0800

Modify: 2010-10-09 20 4415 21 0000000 + 0800

Change: 2010-10-09 20 4415 21 0000000 + 0800

[root@localhost] # stat-f myfile

File: "myfile"

Id: 0 Namelen: 255 type: ext2/ext3

Block size: 4096 Fundamental block size: 4096

Blocks: Total: 241555461 free: 232910771 Available: 220442547

Inodes: Total: 249364480 Free: 249139691

[root@localhost] # stat-t myfile

Myfile 0 8 81a4 00 fd00 194805815 1 00 1292127755 1286628261 1286628261 4096

Touch creates empty files and refresh time

Syntax:

Touch [OPTION]... FILE...

Options:

-a change only atime and ctime

-m changes only mtime and ctime

-t [[CC] YY] MMDDhhmm [.ss] specifies the timestamp of atime and mtime

-c if the file does not exist, it will not be created

Cp copies files and directories

Syntax:

Cp [OPTION]... [- T] SOURCE DEST

Cp [OPTION]... SOURCE... DIRECTORY

Cp [OPTION]... -t DIRECTORY SOURCE...

Cp SRC DEST

Options:

-a: the effect of this parameter is the same as specifying the "- dpR" parameter at the same time

-d: when copying a symbolic connection, the destination file or directory is also established as a symbolic link and points to the original file or directory connected to the source file or directory

-f: forcibly copy a file or directory, regardless of whether the target file or directory already exists

-I: ask the user before overwriting existing files

-l: establish a hard connection to the source file instead of copying the file

-p: preserve the attributes of the source file or directory

-Rbarb r: recursive processing that processes all files in the specified directory with subdirectories

-s: establish a symbolic connection to the source file instead of copying the file

-u: after using this parameter, the file will be copied only when the change time of the source file is newer than that of the target file, or when the target file with corresponding names does not exist.

-S: when backing up a file, replace the default suffix of the file with the specified suffix "SUFFIX"

-b: back up the target file before overwriting the existing file destination

-v: displays the actions performed by the command in detail.

Example:

Cp aaa/* / bbb

Copy all the files under the aaa directory to the / bbb directory. If there are files with the same name as aaa in the / bbb directory, press Y to confirm and skip the subdirectories under the aaa directory.

Cp-r aaa/* / bbb

This time you still need to press Y to confirm the operation, but no subdirectories are ignored.

Cp-r-an aaa/* / bbb

You still need to press Y to confirm the operation, and the aaa directory and subdirectories and file attributes are also passed to / bbb.

\ cp-r-an aaa/* / bbb

Successful, no prompt to press Y, passed directory properties, did not skip the directory.

Mv moves and renames files

Syntax:

Mv [OPTION]... [- T] SOURCE DEST

Mv [OPTION]... SOURCE... DIRECTORY

Mv [OPTION]... -t DIRECTORY SOURCE...

Options:

-I interactive

-f compulsion

-b destination exists. Backup before overwriting

Example:

Rename the file ex3 to new1

Mv ex3 new1

Move all files in the directory / usr/men to the current directory (with. Represents):

Mv / usr/men/*.

Rm deletion

Syntax:

Rm [OPTION]... FILE...

Options:

-I interactive

-f forcibly delete

-r recursion

-- no-preserve-root deletion /

Example:

Delete files test and example in the current directory interactively

Rm-i test example

Remove test? n (do not delete file test)

Remove example? y (delete file example)

Delete all files and subdirectories except implied files in the current directory

Rm-r *

5. Copy / etc/profile to the / tmp/ directory and delete the white space character at the beginning of the line in the / tmp/profile file with the find replace command.

Cp / etc/profile / tmp/ / copy / etc/profile to / tmp/ directory

Vim / tmp/profile / / Open the profile file with vim

:% s / ^\ s input in extended command mode

6. Set tab indentation to 4 characters in vim

Vim ~ / .vimrc / / vim open .vimrc in the user's home directory, and modify the / etc/vimrc file if you need to change the global variable

Set tabstop=4 / / add the following fields

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report