linux system administration Chapter Linux file directory management
Outline
In the Linux system, all files and directories are organized in a tree structure with a root node inverted began.
3.1 Contents Introduction
/: Root directory
/ Etc: almost entirely on the system configuration files in this directory.
/ Boot: storage file used to start the Linux operating system kernel and system, which begins with vmlinuz is the linux kernel. If the boot loader (loader) chose grub, in that directory will have a subdirectory of grub (/ boot / grub).
/ Dev: is stored in the server for all devices in Unix or linux system everything is seen as a file, which also reported hardware.
/ Usr: data storage system applications and commands related system, wherein the system comprises a number of libraries. Somewhat similar to windows in C: \ Program Files folder. It should be noted that, usr is the abbreviation of unix system resources.
Lost + found: when the system is abnormal shutdown, crash or error occurs, the system will lose some of the fragments placed in the directory.
/ Var: storing the system is running in that change frequently, such as log files.
/ Proc: the operating system is running, process (running program in the) information and kernel information (such as cpu, hard disk partitions, memory information, etc.) stored in here. / Proc directory is disguised proc file system mount directory, proc is not a real file system. Therefore, this directory is a virtual directory, which is the system memory map, we can get system information directly access this directory through. In other words, the contents of this directory on the hard disk but not in memory.
/ Bin: Here 's where the standard (or is the default) linux tools, like "ls", "vi" as well as "more" and so on.
/ Libs: is stored in libraries, library that is used by the system. Many programs will call some shared library functions from these libraries are in the process of running.
3.2 relative path and absolute path
Absolute path: the path of writing, with effect from certain directories / write, for example: / usr / share / doc directory
Relative path: the path of the wording, not by / write from, for example, usr / share / doc to the / usr / share / man. You can be written cd ../man. This is the wording of a relative path, relative path refers to the current working directory path is relative.
Comparing the relative path absolute path is more convenient, but when writing a program (shell), be sure to use absolute paths.
The representative of this layer directory
.. On behalf of parent directory
- Representatives before a working directory
- on behalf of the user's home directory
/etc/yum.repos.d
cd. directory unchanged
[root@RHCE7 yum.repos.d]# cd .
[root@RHCE7 yum.repos.d]#
cd.. the parent directory
[root@RHCE7 yum.repos.d]# cd ..
[root@RHCE7 etc]# pwd
home directory cd ~
[root@RHCE7 etc]# cd ~
[root@RHCE7 ~]# pwd
/root
cd - before a directory
[root@RHCE7 ~]# cd -
/etc
3.3 directory management
3.3.1 ls and ll display the directory file command
Ls function is to list the contents of a directory
Ls –options directions|files
-l Detailed information display
-a Show all files, hidden files dunks
Humanized display -h (hommization)
ll is an abbreviation ls -l
[root@Redhat7 ~]# ll -ah /
The total amount of 44K
dr-xr-xr-x. 18 root root 4.0K 7月 22 21:41 .
dr-xr-xr-x. 18 root root 4.0K 7月 22 21:41 ..
-rw-r--r-- 1 root root 0 7月 17 06:47 .autorelabel
lrwxrwxrwx. 1 root root 7 7月 17 03:51 bin -> usr/bin
3.3.2 du calculation file space use
estimate file space usage
-h: displays a human-readable manner
-a: Displays the directory of disk space occupied, but also to show its directory and files take up disk space size
-s: display disk space occupied by the directory, do not display the size of its disk space occupied by files and subdirectories
[root@Redhat7 ~]# du -sh /
du: inaccessible "/ proc / 4831 / task / 4831 / fd / 4": No such file or directory
du: inaccessible "/ proc / 4831 / task / 4831 / fdinfo / 4": No such file or directory
du: inaccessible "/ proc / 4831 / fd / 4": No such file or directory
du: inaccessible "/ proc / 4831 / fdinfo / 4": No such file or directory
11G /
And a switching determination 3.3.3pwd directory and cd
Pwd command to display the absolute path of the current directory.
[root@RHCE7 targeted]# pwd
/etc/selinux/targeted
Cd switch the current directory
[root@RHCE7 targeted]# cd ..
[root@RHCE7 selinux]#
[root@RHCE7 selinux]# cd /opt/rh/
[root@RHCE7 rh]# pwd
/opt/rh
3.3.4 mkdir command to create a directory
mkdir is (the abbreviation make directory) is the meaning of the roll call directory. -P recursive directory build,
[root@Redhat7 ~]# mkdir /syj
[root@Redhat7 ~]# mkdir /hct/syj
mkdir: Unable to create directory "/ hct / syj": No such file or directory
[root@Redhat7 ~]# mkdir -p /hct/syj
3.3.5 cp Copy a file or directory
Cp Copy command function is to copy the files (one or more) to a specified file or the specified target directory. Directory file or directory cp command must be the last parameter
cp –options sources target
sources one or more files, it can be one or more directory names.
Target (purpose): a file or directory
-r (recursive recursive): recursively copy the directory, when you copy a directory, copy all the contents of the catalog, which also includes the entire contents of subdirectories.
-v, --verbose: display detailed step
-p --preserve: maintain the specified attributes (default: mode, ownership, timestamps)
-f, --force: If the destination file already exists mandatory coverage, the system does not ask.
[root@Redhat7 ~]# cp -rvp /run/media/root/RHEL-7.2\ Server.x86_64/* /syj
All files in this directory /run/media/root/RHEL-7.2 \ Server.x86_64 / *, copy to / syj.
3.3.6 mv move and modify files and directories
Usage: mv [option] ... [-T] source file destination
Or: mv [options] source ... directory ...
[root@Redhat7 ~]# mv /syj/* /hct
[root@Redhat7 ~]# ll /syj
0 Total amount
[root@Redhat7 ~]# ll /hct
The total amount of 372
dr-xr-xr-x 4 root root 52 10月 30 2015 addons
dr-xr-xr-x 3 root root 17 10月 30 2015 EFI
3.3.7 rm delete files or directories
rm command is a command destructive, because rm command will permanently delete files or directories.
rm –options files|directions
-i interactive: prompt before you delete the
-r recursive: recursively delete a directory, delete a directory, delete everything.
-f Force: The system does not ask forcibly removed.
[root@Redhat7 ~]# rm -r /hct
rm: whether to enter the directory "/ hct" y?
rm: whether to enter the directory "/ hct / addons" y?
rm: whether to enter the directory "/ hct / addons / HighAvailability"?
[Root @ Redhat7 ~] # rm -rf / hct-sec.
3.4 File Management
3.4.1 touch command to create a file
Use the touch command to create an empty file, or you can create multiple files simultaneously
[root@Redhat7 syj]# touch syjhct.txt hctsyj.txt
3.4.2 file to view the file types
In linux system, the file extension (ie suffix) does not represent the type of file, use the file command to view the type of file.
[root@Redhat7 syj]# file syjhct.txt
syjhct.txt: empty
3.4.3 cat command displays the contents of the file (for less content file)
-n Display line numbers
[root@Redhat7 syj]# cat -n /etc/selinux/config
1
2 # This file controls the state of SELinux on the system.
3 # SELINUX= can take one of these three values:
4 # enforcing - SELinux security policy is enforced.
5 # permissive - SELinux prints warnings instead of enforcing.
6 # disabled - No SELinux policy is loaded.
7 SELINUX=disabled
3.4.4 more page display file contents
display files on a page-by-page basis
Spacebar: Move a page (screen)
Enter: a moving line.
b: a tab upward movement
/ String: forward search string
q: Quit command more
[root@Redhat7 syj]# more /etc/selinux/semanage.conf
3.4.5 less paging file contents command (you can turn pages)
Spacebar or pageup: moving a page (screen)
Enter: a moving line.
/ String: forward search string
n: Find search string
q: Quit less command
[root@Redhat7 syj]# less /etc/selinux/semanage.conf
3.4.6 head display file contents of the command (specify the number of rows)
[root@Redhat7 syj]# head -n 5 /etc/selinux/semanage.conf
# Authors: Jason Tang <[email protected]>
#
# Copyright (C) 2004-2005 Tresys Technology, LLC
#
# This library is free software; you can redistribute it and/or
3.4.7 tail inverted file contents of the command (the file can be updated real-time dynamic display, used to display the log file)
Syntax: tail [filename]
-n specifies the maximum number of lines
-f dynamic display the end of file contents (ie file changes in real time, it will also change the display contents)
To the front of the -f -n
[root@Redhat7 syj]# tail -fn 5 /etc/selinux/semanage.conf
# semanage fcontext -a -e /home /althome
usepasswd=False
bzip-small=true
bzip-blocksize=5
ignoredirs=/root
3.5 file search command
3.5.1 whereis command position inquiry
whereis positioning commands executable, source code files, help file location in the file system.
-b locate the executable file.
-m help locate the file.
-s locate the source code files.
[root@Redhat7 ~]# whereis vim
vim: /usr/bin/vim /usr/share/vim /usr/share/man/man1/vim.1.gz
[root@Redhat7 ~]# whereis -b vim
vim: /usr/bin/vim /usr/share/vim
[root@Redhat7 ~]# whereis -m vim
vim: /usr/share/man/man1/vim.1.gz
3.5.2 which to view the location of the executable file
[root@Redhat7 ~]# which vim
/usr/bin/vim
3.5.3 find the most powerful command
find files find command to search for files in a directory structure, and perform the specified action.
find path -option [ -print ] [ -exec -ok command ] {} \;
parameter |
description |
path |
find the directory path command looking for. For example . To indicate the current directory, / is represented root system. |
|
find file command to match output to standard output. |
-exec |
find command given by the parameter files matching shell command. -exec command {}; the found file performs command operations, attention {} and ; space between |
-ok |
And -exec action is the same, but in a more secure mode to perform the given parameters of shell commands, before executing each command will prompt allows users to determine whether to perform |
3.5.3.1 -name Find the file name
[root@Redhat7 etc]# find /etc -iname SELI*
/etc/selinux
/etc/selinux/targeted/modules/active/modules/selinuxutil.pp
/etc/sysconfig/selinux
Find the beginning of AC ignore case
[root@Redhat7 etc]# find /etc -iname "[A-C]*"
/etc/crypttab
/etc/fonts/conf.d
/etc/X11/fontpath.d/cjkuni-uming-fonts
/etc/X11/applnk
3.5.3.2 user options for users to find and nouser
[root@Redhat7 etc]# find / -user yxy
/home/yxy/.local/share
/home/yxy/.local/share/gvfs-metadata
/home/yxy/.local/share/gvfs-metadata/root
/home/yxy/.local/share/gvfs-metadata/home
Use -nousr without specifying a user name, are looking for is not part of the current equal to the user's files
[root@Redhat7 etc]# find / -nouser
find: '/ proc / 6726 / task / 6726 / fd / 6': No such file or directory
find: '/ proc / 6726 / task / 6726 / fdinfo / 6': No such file or directory
find: '/ proc / 6726 / fd / 6': No such file or directory
find: '/ proc / 6726 / fdinfo / 6': No such file or directory
find: '/ run / user / 42 / gvfs': enough authority
3.5.3.3 time option
-amin n |
Find system recently n be read within minutes file. |
-atime n |
Find system recently n days has been read file |
-cmin n |
Find system recently n is changed files file status within minutes |
-ctime n |
Find system recently n days is changed files file status |
-mmin n |
Find system recently n are changed file data files within minutes |
-mtime n |
Find system recently n days is changing the file data file |
Find 1 days, was to change the status of the file
[root@Redhat7 etc]# find / -ctime 1
/syj/syjhct.txt
/syj/hctsyj.txt
3.5.3.4 -perm Options Options file permissions
Press file permissions mode to find the file, then. The best use of decimal notation rights.
Linux file permissions are divided into three user group other rwx maximum 777 each
x=2^0*1|0=1|0,w=2^1*1|0 =2|0,r=2^2*1|0 =4|0
Using two kinds of common -perm
find -perm mode closely matched
find -perm -mode large matching such permission mode = 644 is then converted to a binary 110 100 100 if there is also matching mode = 744, as long as there is a match on the line.
[root@Redhat7 etc]# find / -perm 770
/ Var / cache / cups
[root@Redhat7 etc]# find / -perm -770
A group of particularly large
3.5.3.5 size depending on the file size Find
find / -size +10M
Herein means greater than + n, -n means less than, n represents a number equal
[root@Redhat7 ~]# find / -size +80M
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/usr/lib/locale/locale-archive
/iso7.2/LiveOS/squashfs.img
/iso7.2/Packages/kde-wallpapers-4.10.5-2.el7.noarch.rpm
3.5.3.6 -a -o combination search
-a represents two conditions are met (and)
-o represents any one of two conditions are satisfied to (or)
Example: Find / etc directory files larger than 80MB to 100MB less than the same time
Find / -size +80M -a -size -100M
[root@Redhat7 ~]# find / -iname *4.10* -a -size +50M
/iso7.2/Packages/kde-wallpapers-4.10.5-2.el7.noarch.rpm
3.5.3.7 exec command execution
Behind -exec parameter with the command is a command, its termination is based; to end as flags, following the command sentence semicolon is indispensable, taking into account the various systems semicolon have different meanings, it is preceded by backslash. {} Braces front of representatives find the file name to find out.
1 Find a current directory and display
[root@Redhat7 ~]# find /etc -iname console.h* -exec cat {} \;
# /etc/security/console.handlers
#
# This file is provided for configuration of handlers which will be
# executed when user obtains console lock and when he loses it.
# Additionally it is used for a configuration of console device names.
#
# Format:
# name consoledevs regex regex ...
# binary lock|unlock flag flag ...
# See man console.handlers
Find ja iso file name in the directory, copy into the rmiso
[root@Redhat7 /]# find /rmiso -iname *ja* -exec cp -prv {} /rmiso \;