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

The structure and Management of linux basic File Directory

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

Share

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

First, linux directory structure

Windows: organize files C:\ d:\ e:\ in a multi-root manner

Linux: organize files in a single root / (the starting point of all directories is /)

/ directory structure: FHS

[root@localhost /] # ls

Bin dev home lib64 mnt proc run srv tmp var

Boot etc lib media opt root sbin sys usr

HOME of the root root user

Home stores the user's home directory

Dev device file directory / dev/sda, / dev/tty, / dev/pts/1, / dev/zero, / dev/null, / dev/random

Proc virtual file system, which reflects the kernel, process information or real-time status, exists only in memory and has a size of 0

The sys pseudo file system (hardware information, kernel parameters, process information in memory) is similar to the proc directory

The directory where commands are stored by ordinary bin users

Directory stored by commands of the sbin administrator user

Lib library file, which stores the shared libraries needed by 32-bit applications, similar to the. dll in windows

Lib64 library file, which stores the shared libraries needed by 64-bit applications

Usr system files (application directory), equivalent to C:\ Windows

For example: / usr/local software installation directory, which is equivalent to C:\ Program

/ usr/bin applications used by ordinary users

/ applications used by usr/sbin administrators

/ usr/lib 32 bit library file Glibc Note: Glibc is the underlying api of the system, while api (English full name is application Programing Interface) application program interface

/ usr/lib64 64bit library file Glibc

Boot stores files related to system startup, such as kernel,grub (bootloader)

Etc configuration files (system-related files)

For example: / etc/sysconfig/network network-related configuration file

Tmp temporary files (mainly temporary data generated by the program)

Var stores changed files, such as databases, logs, and emails.

For example: / var/lib/mysql mysql database file

/ var/vsftp ftp sharing files

/ var/spool/mail mail file

/ var/spool/cron sets the files stored in scheduled tasks

/ var/log runs the log files stored by all programs

/ var/tmp (temporary files generated by the program)

Srv server data directory

Opt third Party Software (flush,splunk,openoffice)

= = device (mainly refers to storage device) mount directory =

/ run/media moves the default mounted directory

/ mnt Mount the directory of the device manually

Df-Thp to view mounts in the system

For example:

[root@localhost ~] # df-ThP

File system type capacity used available used mount point

/ dev/mapper/centos-root xfs 18G 4.3G 14G 25% /

Devtmpfs devtmpfs 470M 0 470M 0% / dev

Tmpfs tmpfs 487m 0 487m 0% / dev/shm

Tmpfs tmpfs 487m 7.7m 479m 2% / run

Tmpfs tmpfs 487m 0 487m 0% / sys/fs/cgroup

/ dev/sda1 xfs 497M 173M 324M 35% / boot

Tmpfs tmpfs 98M 36K 98m 1% / run/user/0

/ dev/sr0 iso9660 603M 603M 0100% / run/media/root/CentOS 7 x861464

Second, the location of command storage

/ bin commands used by ordinary users / bin/ls, / bin/date

Commands used by / sbin administrator

/ usr/bin applications used by ordinary users

/ applications used by usr/sbin administrator users

Storage location of library files:

/ lib 32-bit library file Glibc

/ lib64 64-bit library file Glibc

/ usr/lib 32bit application library file Glibc

/ usr/lib64 64-bit application library file Glibc

A little knowledge:

There are three times for Linux files:

Access time: atime, view content

Modification time: mtime, modify content

Change time: ctime, file attributes, such as permissions

For example:

[root@localhost ~] # touch gg.log

[root@localhost ~] # ll gg.log only view file modification time

-rw-r--r--. 1 root root 0 August 28 06:17 gg.log

[root@localhost ~] # stat gg.log to view the detailed properties of the file (including the file time attribute)

File: "gg.log"

Size: 0 block: 0 IO block: 4096 ordinary empty file

Device: fd00h/64768d Inode:73215767 hard link: 1

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

Environment: unconfined_u:object_r:admin_home_t:s0

Last visit: 2019-08-28 06 1715 16.030170315 + 0500

Last modified: 2019-08-28 06 1715 16.030170315 + 0500

Last modified: 2019-08-28 06VOR 1715 16.030170315 + 0500

Creation time:-

File type:

Judging the file type by color is not necessarily correct!

Linux file does not have an extension

How do I view file types?

Method 1:

[root@localhost ~] # ll anaconda-ks.cfg / / look at the first character

-rw-. 1 root root 955 August 19 23:36 anaconda-ks.cfg

Normal files (text files, binary files, compressed files)

Such as:

-rw-. 1 root root 955 August 19 23:36 anaconda-ks.cfg

D directory files (general directories are shown in blue)

Such as:

Drwxr-xr-x. 2 root root June 26 06:56 desktop

B device file (block device) storage device hard disk, u disk for example: / dev/sda,/dev/sda1

Such as:

Brw-rw----. 1 root disk 8, August 28 05:19 sda1

C character device file (character device) printer, terminal / dev/tty1

Such as:

Crw--w----. 1 root tty 4, August 28 05:19 tty1

S socket file

Such as: / dev/log

Srw-rw-rw-. 1 root root 0 August 28 05:19 log

P pipe file

L linked file (light blue)

Method 2: file

[root@localhost ~] # file anaconda-ks.cfg

Anaconda-ks.cfg: ASCII text text files, binary files, compressed files

[root@localhost ~] # file / bin/cd

/ bin/cd: POSIX shell script, ASCII text executable executable file

[root@localhost ~] # file / home

/ home: directory directory

[root@localhost ~] # file / dev/sda

/ dev/sda: block special block device

[root@localhost ~] # file / dev/tty1

/ dev/tty1: character special character device

[root@localhost ~] # file / etc/grub2.cfg

/ etc/grub2.cfg: symbolic link to `.. / boot/grub2/grub.cfg' symbolic link

[root@localhost ~] # file / var/spool/postfix/public/pickup

/ var/spool/postfix/public/pickup: socket socket

Path (location file)

Absolute path: the path starting from / such as / home/file1, ~ / alice

Relative path: start Desktop/file file1 relative to the current directory. ..

. Current directory

.. Higher-level directory

~ the home directory of the current directory

Useradd alicetouch / home/alice/file1touch ~ alice/file2ls / home/alicemkdir / home/abctouch.. / file3touch file4. / file5touch / home/abc/file5lsls / home/abc

Third, document management

Cd changes the directory

Cd absolute path cd / home/alice cd ~ alice

Cd relative path cd Desktop/abc cd.. Cd. Cd-

Cd-returns to the last directory

Cd went straight home.

Create / copy / move / delete / view

1) create

Directory mkdir

# mkdir [option]

[root@localhost ~] # mkdir / tmp/bj

[root@localhost ~] # mkdir sh

[root@localhost ~] # mkdir / linux

Option

Create directory at-p level

[root@localhost] # mkdir-p / uplooking/linux

1) document management

1 View Fil

# ls [option] [directory name]

-l display file information in the form of detailed information

[root@localhost ~] # ls-l

Total dosage 4

-rw-. 1 root root 955 August 19 23:36 anaconda-ks.cfg

-file d directory l soft connection file (link) b block device (block), hard disk, hard disk partition, u disk, CD c character device file (character) keyboard and mouse, monitor

[root@localhost ~] # ls-l / etc/passwd

-rw-r--r--. 1 root root 2444 August 20 17:19 / etc/passwd

-h displays the file information in a humanized way

[root@localhost ~] # ls-lh / etc/passwd

-rw-r--r--. 1 root root 2.4K August 20 17:19 / etc/passwd

-d displays the information of the directory itself

[root@localhost ~] # ls-ldh / etc

Drwxr-xr-x. 143 root root 8.0K August 30 06:53 / etc

-a shows all files and hides them (with. File at the beginning)

[root@localhost] # ls-a

. Download video .bash _ history .bashrc .cshrc .ICEauthority .tcshrc

.. .bash _ logout .cache .dbus .local public picture music

Anaconda-ks.cfg .bash _ profile .config .esd _ auth .pki template document desktop

-t is sorted in descending order by file modification time

[root@localhost ~] # ls-lt

Total dosage 4

-rw-r--r--. 1 root root 0 August 30 07:21 1.txt

Drwxr-xr-x. 2 root root June August 30 06:55 Public

Drwxr-xr-x. 2 root root June August 30 06:55 video

Drwxr-xr-x. 2 root root June 30 06:55 Picture

Drwxr-xr-x. 2 root root June August 30 06:55 document

Drwxr-xr-x. 2 root root June August 30 06:55 Music

Drwxr-xr-x. 2 root root June August 30 06:55 template

Drwxr-xr-x. 2 root root 6 August 30 06:55 download

Drwxr-xr-x. 2 root root June August 30 06:55 Desktop

-rw-. 1 root root 955 August 19 23:36 anaconda-ks.cfg

-S is sorted in descending order of file size

[root@localhost ~] # ls-lhS

Total dosage 4.0K

-rw-. 1 root root 955 August 19 23:36 anaconda-ks.cfg

Drwxr-xr-x. 2 root root June August 30 06:55 Public

Drwxr-xr-x. 2 root root June August 30 06:55 template

Drwxr-xr-x. 2 root root June August 30 06:55 video

Drwxr-xr-x. 2 root root June 30 06:55 Picture

Drwxr-xr-x. 2 root root June August 30 06:55 document

Drwxr-xr-x. 2 root root 6 August 30 06:55 download

Drwxr-xr-x. 2 root root June August 30 06:55 Music

Drwxr-xr-x. 2 root root June August 30 06:55 Desktop

-rw-r--r--. 1 root root 0 August 30 07:21 1.txt

2) Statistical catalog size

[root@localhost ~] # du-sh / etc/passwd

4.0K / etc/passwd

-a displays the size of individual files in the directory

[root@localhost ~] # du-ah / etc/

3) create a file

# touch

Curly braces show {}:

[root@localhost ~] # touch / tmp/1.txt

[root@localhost ~] # touch / tmp/ {1jpg only creates files in jpg format that are in the format of 1jpg.

[root@localhost ~] # touch / tmp/ {1.. 10} .mp3 create .mp3 files from 1 to 10

[root@localhost ~] # touch / tmp/ {ameme bpene c} .txt

[root@localhost ~] # date

Friday, August 30, 2019, 07:59:13 PKT

[root@localhost ~] # date +% F

2019-08-30

[root@localhost ~] # date +% T

08:02:33

[root@localhost ~] # date +% H shows hours only

08

[root@localhost ~] # date +% M shows minutes only

05

[root@localhost ~] # date +% m shows seconds only

08

[root@localhost ~] # date +% Fmuri% T specific year, month, day-specific time

2019-08-30-08:08:31

Command reference:

Method 1 Vol $(command)

[root@localhost ~] # touch / tmp/$ (date +% FMI% T). Log

[root@localhost ~] # ls / tmp

2019-08-30-08:13:42.log

Method 2: backquotation marks

[root@localhost ~] # touch / tmp/date +% F-%T.log

[root@localhost ~] # ls / tmp

2019-08-30-08:23:08.log

4) copy the file directory

# cp [option] Source file target file

Options:

-r when copying a directory

[root@localhost] # cp-r / linux/ / windows/

-f forced overlay

[root@localhost ~] # cp-fn / linux/1.txt / windows/

5) move the file directory

# mv source file target file

[root@localhost ~] # mv / linux/1.txt / linux/66.txt

6) Delete the file directory

# rm [option] File name

[root@localhost ~] # rm / linux/66.txt

Rm: do you want to delete the normal empty file "/ linux/66.txt"?

-r when deleting a directory

[root@localhost] # rm-r / linux/66.txt

Rm: do you want to delete the normal empty file "/ linux/66.txt"?

-f forcibly delete directories

[root@localhost ~] # rm-rf / linux/66.txt

7) count the number of lines in the file

[root@localhost ~] # wc-l / etc/passwd

46 / etc/passwd

[root@localhost ~] # wc / etc/passwd

46 96 2444 / etc/passwd View file lines, words, bytes

8) View the contents of the file-cat/more/less/head/tail

Cat

[root@localhost ~] # cat / etc/fstab

#

/ etc/fstabCreated by anaconda on Tue Aug 20 02:30:01 2019

#

Accessible filesystems, by reference, are maintained under'/ dev/disk'See man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info

#

/ dev/mapper/centos-root / xfs defaults 0 0

UUID=72251e67-7f60-4598-99cd-67f415c4496d / boot xfs defaults 0 0

/ dev/mapper/centos-swap swap swap defaults 0 0

[root@localhost ~] # cat-n / etc/fstab shows all flights

one

2 #

3 # / etc/fstab

4 # Created by anaconda on Tue Aug 20 02:30:01 2019

5 #

6 # Accessible filesystems, by reference, are maintained under'/ dev/disk'

7 # See man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info

8 #

9 / dev/mapper/centos-root / xfs defaults 0 0

10 UUID=72251e67-7f60-4598-99cd-67f415c4496d / boot xfs defaults 0 0

11 / dev/mapper/centos-swap swap swap defaults 0 0

[root@localhost ~] # cat / etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

More/less paging content

[root@localhost ~] # more / etc/fstab turn the page with b

[root@localhost] # less / etc/fstab can turn the page with the arrow keys

Head/tail

Head-n specific lines to show how many lines start from the beginning

[root@localhost ~] # head-n 3 / etc/passwd displays the first three lines

Root:x:0:0:root:/root:/bin/bash

Bin:x:1:1:bin:/bin:/sbin/nologin

Daemon:x:2:2:daemon:/sbin:/sbin/nologin

[root@localhost ~] # head / etc/passwd displays the first 10 lines by default

Root:x:0:0:root:/root:/bin/bash

Bin:x:1:1:bin:/bin:/sbin/nologin

Daemon:x:2:2:daemon:/sbin:/sbin/nologin

Adm:x:3:4:adm:/var/adm:/sbin/nologin

Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

Sync:x:5:0:sync:/sbin:/bin/sync

Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

Halt:x:7:0:halt:/sbin:/sbin/halt

Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

Operator:x:11:0:operator:/root:/sbin/nologin

[root@localhost ~] # tail-n 3 / etc/passwd last 3 lines

Avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin

Tcpdump:x:72:72::/:/sbin/nologin

Roo:x:1000:1000:root:/home/roo:/bin/bash

[root@localhost ~] # tail / etc/passwd 10 lines after the default prompt

Rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin

Nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

Pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin

Saned:x:988:982:SANE scanner daemon user:/usr/share/sane:/sbin/nologin

Sssd:x:987:981:User for sssd:/:/sbin/nologin

Gdm:x:42:42::/var/lib/gdm:/sbin/nologin

Gnome-initial-setup:x:986:980::/run/gnome-initial-setup/:/sbin/nologin

Avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin

Tcpdump:x:72:72::/:/sbin/nologin

Roo:x:1000:1000:root:/home/roo:/bin/bash

9) View file types

[root@localhost ~] # file / etc/passwd

/ etc/passwd: ASCII text

[root@localhost ~] # which ls

Alias ls='ls-color=auto'

/ usr/bin/ls

[root@localhost ~] # file / usr/bin/ls

/ usr/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID [sha1] = aa7ff68f13de25936a098016243ce57c3c982e06, stripped

The use of pipe characters: |

[root@localhost ~] # ls-hlS / etc/ | head-n 5

Total dosage 1.5m

-rw-r--r--. 1 root root 655K June 7 2013 services

-rw-r--r--. 1 root root 79K August 20 23:52 ld.so.cache

-rw-r--r--. 1 root root 25K August 6 2015 dnsmasq.conf

-rw-r--r--. 1 root root 22K April 11 2018 brltty.conf

[root@localhost ~] # ls-lt / etc/ | head-n 11

The total dosage is 1496

Drwxr-xr-x. 5 root lp 4096 August 30 12:46 cups

-rw-r--r--. 1 root root 73 August 30 06:53 resolv.conf

Drwxr-xr-x. 6 root root 4096 August 30 06:53 sysconfig

Drwx-. 5 root root 4096 August 21 00:12 libvirt

-rw-r--r--. 1 root root 80791 August 20 23:52 ld.so.cache

Drwxr-xr-x. 2 root root 4096 August 20 23:52 alternatives

Drwxr-xr-x. 2 root root 4096 August 20 23:52 bash_completion.d

Drwxr-xr-x. 2 root root 54 August 20 23:52 cron.daily

Drwxr-xr-x. 2 root root 21 August 20 23:52 cron.hourly

Drwxr-xr-x. 6 root root 95 August 20 23:52 yum

10) find the file directory

Find path search method

Find by file name

[root@localhost ~] # find / etc/-name "* .conf"

[root@localhost ~] # find / etc/-name "* .conf" | wc-l

four hundred and fifty two

Find by file size

[root@localhost ~] # find / etc/-size + 500k

[root@localhost ~] # find / etc/-size + 1m

Find by file modification time

[root@localhost ~] # find / etc-mtime + 5 modified for more than 5 days

[root@localhost ~] # find / etc-mtime 5 modification time is equal to 5 days

[root@localhost ~] # find / etc/-mtime-5 is modified within 5 days

File type lookup

[root@localhost ~] # find / dev/-type b looks up the block device type

/ dev/dm-1

/ dev/dm-0

/ dev/sr0

/ dev/sda2

/ dev/sda1

/ dev/sda

[root@localhost ~] # find / dev/-type l find files of link type

Expand knowledge:

Dos2unix converts files in windows format to unix

Unix2dos converts files in unix format to windows

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