Common commands for Linux directory management and file management

Source: Internet
Author: User
Tags aliases

1. Directory Management

1.1, the directory structure of Linux

.: Current Directory

.. : Top level Directory

/: Root directory

/bin: binary, executable commands

/boot: Boot, the file that the operating system uses to boot the system, kernel, grub

/dev: Device files

Types of devices for Linux:

Character device: C, linear device

Block device: B, random device

/etc: Configuration file

/home: User's house directory,/home/username,jerry,/home/jerry

/root: Administrator's home directory

/LIB,LIB64: library file

/media: mount point directory, typically used to mount portable devices

/MNT: mount point directory, mount additional file system

/misc: Backup Directory

/OPT: Optional directory, usually third-party software installed occasionally under this path

/proc: Pseudo file System: Mapping of In-memory kernels

/selinux: Security-Enhanced Linux

/SRV: Pseudo file system, typically used to access hardware Device property information

/tmp: Temp file directory

/usr: Store read-only files

/var: Files that often change: for example, logs, etc.

1.2. Directory naming rules for files and files under Linux:

1. Length cannot exceed 255 characters

2. Cannot use/(slash) when file name, do not recommend using special characters

3. Strictly case-sensitive

1.3. Common commands for Directory management

CD Replacement working directory usage: cd [directory]

Cd.. Return to Parent Directory

CD ~ Return home Directory

CD Home Directory

CD-Toggles between the last directory and the current directory

CD ~username Switch to USERNAME's home directory

# Cd/usr/share #切换到share目录下

PWD: Show current directory

DirName: Displays the directory for the specified path

# dirname/usr/bin//usr# DirName a/b/a # dirname a.

mkdir Building directory usage: mkdir [OPTION] Directory

-P: Parent directory If we specify Z, the parent directory y of Z does not exist, and Y is created automatically first if the parent directory X of y is not saved

The x will be created automatically first

-V: Show creation process

# mkdir/tmp/x1 #在tmp下创建x1 # Mkdir/tmp/x2/hello #在tmp下的x2下创建hello, because X2 does not exist, so will error, cannot create, to use the-p option mkdir-pv/tmp/x2/he Llo command line expansion:/mnt/test2/a_b,a_c,d_b,d_c{a,d}_{b,c}# mkdir-pv/mnt/test2/{a,d}_{b,c}mkdir:created directory '/mnt/test2 ' mkdir:created directory '/mnt/test2/a_b ' mkdir:created directory '/mnt/test2/a_c ' mkdir:created directory '/mnt/test2 /d_b ' mkdir:created directory '/mnt/test2/d_c '

/mnt/test/x/m/mnt/test/y How can this be created at the same time?

[[email protected] ~]# mkdir-pv/mnt/test/x/m/mnt/test/y [[email protected] ~]# Mkdir-pv/mnt/test/{x/m,y} # {} flower Bracket expansion ~username Wavy line expansion

RmDir (remove directory): Delete directory, can only be used to delete empty directory

-P: Parent Directory

-V: Show detailed procedures

# rmdir-pv/root/x/y/z rmdir: Deleting directory "/root/x/y/z" rmdir: Deleting directory "/root/x/y" rmdir: Deleting directory "/ro ot/x "rmdir: Deleting directory"/root "rmdir: Delete directory"/root "failed: Directory not empty

Note: After adding-P, can only delete the first-line only son directory: that is, the z Delete, the y directory is empty, will be the Y directory is deleted, when y deleted, the x directory is empty, the X directory will be deleted, but root is not empty, so you cannot delete the root directory.


2, the management of documents

2.1. Type of File

Linux File types:

Normal file (-): A.html,b.txt,c.ppt,ls

Catalog file (d):

Special files:

Block device file (b):

Character device file (c):

Symbolic link file (l):

Named pipe file (p): Pipe

Socket file (s): socket

To determine the content type of an ordinary file, use the file command: #file command

2.2. Permissions for files

Directory Permissions:

R: The LS command can be executed on the directory, but the-l option is not allowed, and cannot be CD-to-directory;

W: can create files in directory;

X: You can execute the ls-l command on the directory and be able to CD in.

File system security Model:

Belong to the main group other

U, G, O

---: 0

--X:001-1

-W-:010-2

-wx:011-3

R--:100-4

R-X:101-5

RW-:110-6

rwx:111-7

3-bit binary corresponds to a 8 binary

4-bit binary corresponds to a 16-bit binary

0,9,a,b,c,d,e,f

f:1111

9:1001


2.2. Common commands for File management

Cat, TAC, more, less, head, tail display files

Cat sequence displays entire file cat filename

-N: Show line numbers

# cat-n/etc/sysctl.conf

Create a file from the keyboard: cat > FileName can only create new files and cannot edit existing files.

Merge several files into one file: Cat file1 file2 > file

TAC Reverse Display file

More full screen display the contents of the file, turn back, before turning to the end of the file to allow the rear to knock the space bar: Next screen, press Q to finish

-N: Show N rows

+n: Starting from Nth line

# more/etc/sysctl.conf

Less: Forward, before turning to the head of the file to allow the forward tapping of the B key: Go ahead and turn the return line

Head: The file's first n rows n defaults to 10, and the filename is not displayed by default

-Q: Hide file names

-V: Show file name

-N OR-N:: N rows are displayed

-C N: Show N bytes

Head-v -8/etc/sysctl.conf==>/etc/sysctl.conf <== ...

Tail: The following n rows of the file

-N OR-N:: N rows are displayed

-F: After viewing the tail content of a file, do not exit, wait and display the new line; Quit using CTRL + C to end


File creation and deletion: Under Linux, directories and files cannot have the same name, under Windows, and cannot, because files under windows have suffixes

Touch

# Touch a #创建a文件

Touch: The primary command is not used to create a file, it is used to modify the timestamp

Timestamp: Access time, modification time, change time

-C: Do not create any files

-A: Change access time changes and change time

-M: Change the modification time only change, change the time will also change

-T: Specifies the modification time to a specified time in the format [CC]YYMMDDHHMM.SS

Stat: Displays status information for a file or file system

# Stat A #显示a文件或a文件系统的状态信息 File: ' A ' size:0 blocks:0 IO block:4096 Regular Empty filedevice:80 2h/2050dinode:131089 links:1access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) access:2015-03 -05 06:17:01.535994188-0500 #访问时间Modify: 2015-03-05 06:17:01.535994188-0500 #修改时间Change: 2015-03-05 06:17:01.53599 4188-0500 #

To create a file, you can use the File Editor text editor to simply edit the pure ASCII code

Word is not a file editor, just a word processor

Nano, vim: Text editor

RM: Deleting files

-I: Reminder before deleting

-F: Forcibly removed

-r: Delete all files under directory delete directory

# rm Hello Delete Hello

Note: Why will prompt, because here the RM command is not the source of the RM command, is the modified RM command, is the alias of the Rm-i, (command alias),-I interactive, if you delete, you can interact with you, ask you to delete because now is the administrator, in order to avoid accidental deletion, so there is this hint, No prompt for normal users

# \rm a #加了 \ After there is no prompt, is the original RM command # rm-rf/#删除根目录, so be sure to use it carefully

Command aliases:

Alias

\command: Using the command itself instead of using aliases with the same name as the command names

Cp:copy copying and moving files CP srcfile DEST

-R or-r: replication of files in directories and directories for recursive replication

-F: Forcibly copied, if the target file has a direct overwrite; If the file target cannot be opened, delete it first and try again

-I: Interactive, pre-overwrite reminder confirmation

-P: Retain original owner, group, permission, and timestamp after copying files

-A: Copy all, archive

Copy files can be copied to a file as another file (can), can you copy a file as multiple files (not), to copy a file as multiple targets (not), can be copied to a file (not), can be multiple files to a directory (could), Can you copy multiple files to multiple files (CP cannot be implemented using scripting)

CP file1 File2 File3

CP command only the last one is the target, before all is the source, does not allow one source multiple targets, also does not allow multiple sources multiple targets

# cp/etc/passwd/tmp/#把etc目录下passwd文件复制到tmp目录下, and keep the original name # Cp/etc/passwd/tmp/test #复制etc目录下passwd文件到tmp目录下.

Note: If the target test does not exist, it is copied to TMP and named Test. If the test exists, then whether it is a directory or a file, is the file is not covered, that is, delete the original test file, the passwd copied over to rename to test, is the directory, then put passwd in the test directory, and save as the original name

# CP/ETC/PASSWD/ETC/ISSUE/ETC/INITTAB/TMP/ABCCP: Target "/TMP/ABC" is not a directory #说明多个源 target must be a directory

The CP command does not replicate the directory by default, and if you want to copy the directory, the CP has a recursive option:-R or-R all, that is, copy all files in directory and directory

# cp/etc/init.d//TMP/CP: Skip Directory "/etc/init.d/" [[email protected] ~]# cp-r/etc/init.d/tmp/passwd passwd is a file under TMP PA SSWD-RC.D/INIT.D

Note: A link was created, and it is pointing to the current link file, but it is wrong, because there is no INIT.D under TMP This file displays a bit red on Linux

# cp-r/etc/init.d//tmp/hello #复制etc目录下init. D directory to the TMP directory, created and named Hello

MV Moving files and directories usage: MV [OPTION] ... SOURCE DEST

-F: Forcibly moved, if the target file has a direct overwrite; If the file target cannot be opened, delete it first and try again

-I: Interactive, mobile pre-overwrite reminder confirmation

-B: Overwrite the previous backup if you need to overwrite the file.

# mv/etc/abc/tmp/def #将/etc/abc move to/tmp/and rename to Def

Wildcard: Bash supports file name wildcard, globbing

*: Any character of any length

? : Any single character

[]: Any single character within the specified range

[0-9]: all the numbers

[A-z] or [a-z] all letters

[0-9a-z] or [0-9a-z] all the numbers and letters

Character Sets and:

[:d Igit:]: All numbers, equivalent to 0-9 [0-9],[[:d igit:]]

[: Lower:]: All lowercase letters

[: Upper:]: All caps

[: Alpha:]: All numbers

[: Alnum:]: equivalent to [0-9a-z] all the numbers and letters

[: Space:]: blank symbol

[:p UNCT:]: All punctuation

[^]: caret, inverse, any but one character outside the specified range

# cp-v/etc/i*/tmp/#将etc目录下以i开头的文件复制到tmp下 # cp/etc/*.conf/tmp/#将所有已. conf End file copied to TMP # cp/etc/i*.conf/tmp/ #以i开头, followed by any character, end with. conf # cp/etc/i?. conf/tmp/#以i开头, followed by any character, and finally ending with. conf # cp/etc/i[abcd].conf/tmp/#以i开头, followed by any character in ABCD, End with. conf # CP/ETC/I[ABCD ]*.conf/tmp/#以i开头, followed by any character in ABCD, followed by any character, and ended with. conf


This article is from the "three elder brother" blog, please be sure to keep this source http://523958392.blog.51cto.com/9871195/1617539

Common commands for Linux directory management and file management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.