Analysis of System File and Directory Management in CentOS 7

Linux directory structure

Linux directory structure is a tree-like directory structure

root directory

  • The starting point of all partitions, directories, files, etc.

  • In the entire tree directory structure, a separate "/" is used.

Common subdirectories

Catalog Directory name Catalog Directory name
/root Administrator's Home Directory /bin Directory of executable command files for all users
/boot System Kernel, Startup File Directory /dev Equipment files
/etc configuration file /home User Home File Directory
/var Variable file (log file) /usr User Application File Directory
/sbin Administrator executable management commands /proc Hardware Information Storage Directory

View and Retrieve File Command

cat command

  • cat command: Display and connect file contents

  • format

cat [Options] File Name...

[root@localhost ~]# Cat/mnt/tast02.txt//Enter commands to view file contents
this is tast02                                   //Display file content
[root@localhost ~]#

more and less commands

  • more command: Page-by-page display of file content in full screen mode (automatically quit reading mode when finished, can not directly look back)

  • format

more [Options] File Name...

  • Interactive operation method

    Press Enter to scroll down line by line

    Press the space bar to turn down a screen

    Press key b to turn up a screen

    Press q to exit

[root@localhost ~]# more /etc/httpd/conf/httpd.conf 
#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see 
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# Configuration and logfile names: If the filenames you specify for many
# The server's control files beg...//
  • less command: Same as more command, but with more extensions (page up after reading, continue reading)

  • format

    less [Option] File Name...

  • Interactive operation method

    Page up page up

    Page down to page down

    "/" key to find content

    The next content of "n"

    A Content on "N"

    Other functions are similar to more commands

[root@localhost ~]# less /etc/httpd/conf/httpd.conf 
#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see 
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online...//The following omissions...

head and tail commands

  • head command: View the content at the beginning of the file (default 10 lines)

  • format

    head [Option] File Name...

    Command word option Effect
    head Look at the beginning of the file (default 10 lines)
    head - n (Number) View the contents of the first n lines
    [root@localhost ~]# Head/etc/passwd//View the top 10 lines of directory files
    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   //View the first three lines of a directory file
    [root@localhost ~]# head -3 /etc/passwd       
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    
  • tail command: View a small portion of the end of the file (default is 10 lines)

  • format

    tail [Options] File Name...

    Command word option Effect
    tail View a small portion of the end of the file (default is 10 lines)
    tail -n View the end n lines
    tail -f Tracking dynamic updates of the content at the end of a file (used in public logs, etc.)
[root@localhost ~]# tail /etc/passwd // / View 10 lines at the end of the directory file
setroubleshoot:x:993:988::/var/lib/setroubleshoot:/sbin/nologin
sssd:x:992:987:User for sssd:/:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:991:986::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
sun:x:1000:1000:sun:/home/sun:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@localhost ~]# Tail-3/etc/passwd//View the contents of the three lines at the end of the directory file
tcpdump:x:72:72::/:/sbin/nologin
sun:x:1000:1000:sun:/home/sun:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@localhost ~]# 

Statistical Document Content Command

  • wc command: information about the number of words in the statistics file

  • format

    wc [options]... target file...

    Command word option Effect
    wc Default count of rows, words, bytes
    wc -l Statistical rows
    wc -w Number of words counted
    wc -c Statistical byte count
[root@localhost ~]# Wc/etc/httpd/conf/httpd.conf//Statistical file line number, word number, byte number
  353  1801 11753 /etc/httpd/conf/httpd.conf            //Display the number of rows, words, bytes
[root@localhost ~]# Wc-l/etc/httpd/conf/httpd.conf//Statistical file line count only
353 /etc/httpd/conf/httpd.conf                          //Display the number of rows
[root@localhost ~]# Wc-w/etc/httpd/conf/httpd.conf//Statistical document word count only
1801 /etc/httpd/conf/httpd.conf                         //Display the number of words
[root@localhost ~]# Wc-c/etc/httpd/conf/httpd.conf//Statistics only the number of bytes of files
11753 /etc/httpd/conf/httpd.conf                        //Display bytes
[root@localhost ~]# 

Retrieval and Filtration of File Content Command

  • grep command: Find and display lines containing specified strings in a file

  • format

    grep [Options] Find Conditional Object Files

    Command word option Effect
    grep Find files in the directory (forward search, find the information we need)
    grep -i Ignore case when looking up
    grep -v Reverse lookup, output rows that do not match the lookup condition
  • Find Conditions Settings

    The strings to be looked up are enclosed in double quotation marks

    "^... "Expressed by... Beginning,"... $'means... Ending

    "^$" means blank line

[root@localhost ~]# grep "ftp" /etc/passwd // / Find the "ftp" file in passwd
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin       //Find out the file information
[root@localhost ~]# Cd/etc/httpd/conf//Enter the conf file directory
[root@localhost conf]# ls // / View the configuration file in the directory
httpd.conf  magic                                 //show contents
[root@localhost conf]# grep -v "#" httpd.conf     //Find files in httpd.conf file that do not carry #.
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache                                      //Display the contents of the lookup
ServerAdmin root@localhost
//The following is omitted.
[root@localhost conf]# Grep "bash $"/ etc / passwd // / Find bash ending in passwd file
root:x:0:0:root:/root:/bin/bash                    Documents
sun:x:1000:1000:sun:/home/sun:/bin/bash          //Display files ending with bash
[root@localhost conf]# grep "^n" /etc/passwd // / Find files starting with N in passwd files
nobody:x:99:99:Nobody:/:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin              //Display file content starting with n

Using compression and decompression tools

  • gzip command and bzip2 command

    The default extension for compressed files made by gzip is ".gz"

    The default extension of the compressed file produced by bzip2 is ".bz2"“

    (gzip format bzip2 format creates compressed packages or unzips the original files of compressed packages will disappear)

  • format

    Command word option Effect
    gzip/bzip2 -9 Compressed file (default "-9" when no options are entered after the command word)
    gzip/bzip2 -d Unzip the file
[root@localhost conf]# Cd/mnt//Enter MNT file directory
[root@localhost mnt]# ls // View directory files
demo02.txt  demo.jpg  tast01.txt  tast02.txt      //Display catalog files
[root@localhost mnt]# Gzip-9 demo02.txt//Compress Demo02 file in gzip format
[root@localhost mnt]# ls // View
demo02.txt.gz  demo.jpg  tast01.txt  tast02.txt   //demo02 compressed file in gz format
[root@localhost mnt]# Gzip-d demo02.txt.gz//decompression Demo02
[root@localhost mnt]# ls // View
demo02.txt  demo.jpg  tast01.txt  tast02.txt      //demo02 decompression
[root@localhost mnt]# Bzip2-9 demo02.txt//Compress Demo02 file in bzip2 format
[root@localhost mnt]# ls // View
demo02.txt.bz2  demo.jpg  tast01.txt  tast02.txt  //demo02 compressed file in bz2 format
[root@localhost mnt]# Bzip2-d demo02.txt.bz2//decompression Demo02
[root@localhost mnt]# ls // View
demo02.txt  demo.jpg  tast01.txt  tast02.txt      //demo02 decompression

Archiving Order

  • tar command: make and release archives

  • format

    tar [options].... File name, source file or directory

    or

    tar [option]... filename [-C target directory]

    Command word- option Effect
    tar -c Create compression packages
    tar -x decompression
    tar -v Display details
    tar -f implement
    tar -p Retain original authority
    tar -t View the contents of compressed packages
    tar -C Decompression target path
    tar -z gzip format
    tar -j bzip2 format
[root@localhost mnt]# tar czvf demo.tar.gz demo02.txt tast01.txt 
demo02.txt                    //Compress demo02 and tast02 files to gz format. The command of compression file is demo.
tast01.txt
[root@localhost mnt]# ls // View
demo02.txt  demo.jpg  demo.tar.gz  tast01.txt  tast02.txt  //Display demo compressed file
[root@localhost mnt]# Mkdir/data//Create a new folder data
[root@localhost mnt]# tar xzvf demo.tar.gz -C /data/
demo02.txt                    //Unzip demo to a new data folder
tast01.txt
[root@localhost mnt]# cd /data // Clip into the data file
[root@localhost data]# ls // View
demo02.txt  tast01.txt              //Display decompressed content

Supplementary knowledge points

  • ">": Application of redirection symbols (output redirected to a file or device overwriting the original file)
  • ">": Output redirected to a file or device to append the original file

  • "|": Pipeline Symbol (Format: Command A | Command B, that is, the correct output of Command 1 as the operation object of Command B)

Keywords: Linux Apache ftp less

Added by wombatee on Thu, 10 Oct 2019 16:06:09 +0300