day02-Amin linux-file, directory Management

Source: Internet
Author: User
Tags egrep

day02-Amin linux-file, directory Management

2.1 System directory Structure

    [[email protected] ~]# ls/bin Dev home lib64 mnt proc run SRV tmp var boot etc Lib Media  opt root sbin sys usryum install-y tree [[email protected] ~]# tree-l 1//├──bin  Usr/bin├──boot├──dev├──etc├──home├──lib, Usr/lib├──lib64, Usr/lib64├──media├──mnt├──opt├──proc├──root├──run├──sbin-    > Usr/sbin├──srv├──sys├──tmp├──usr└──var Common Command Storage directory/usr/bin/usr/sbin /bin/sbin/boot system boot related files Grub grub2 [[email protected] ~]# ls/boot config-3.10.0-693.el7.x 86_64 EFI Grub GRUB2 initramfs-0-rescue-8c52e199b0324c32b27d6a9e03982bde.img initramfs- 3.10.0-693.el7.x86_64.img initramfs-3.10.0-693.el7.x86_64kdump.img initrd-plymouth.img symvers-3.10.0      -693.el7.x86_64.gz  System.map-3.10.0-693.el7.x86_64 Vmlinuz-0-rescue-8c52e199b0324c32b27d6a9e03982bde Vmlinuz-3.10.0-693.el7. X86_64/dev device file storage Directory/etc system configuration file directory/home directory file system library file/lib/lib64ldd/bin/ls view the LS command dependent library file [[email&nbsp        ;p rotected] ~]# ls/home [[email protected] ~]# useradd user1 [[email protected] ~]# Ls/home User1

2.2 Under the System directory structure

/media  临时挂载目录,默认空的/mnt    临时挂载目录,默认空的/opt    默认空的/proc   系统进程,不占用磁盘空间,运行在内存中,默认空的/run    进程产生的临时文件,关机后会消失/srv    存一些服务产生的文件/sys    系统内核一些相关文件/tmp    系统临时文件目录/usr    系统用户会用到的一些命令/var    /var/log  系统日志常用目录/usr/bin  /usr/sbin  /bin  /sbin  /etc  /var/  /usr/local

2.3 ls Command

ls lh  -h人性化显示ls -i   -i显示inode信息ls -la   -a显示全部文件,.开头的文件是隐藏文件ls -lta   -t以时间排序ls -ld /root/  -d只显示root下的目录        [[email protected] ~]# ls -lih        总用量 8.0K        33580930 -rw-------. 2 root root 1.4K 2月  24 22:22 anaconda-ks.cfg        33580930 -rw-------. 2 root root 1.4K 2月  24 22:22 anaconda-ks.cfg.bak        inode  文件类型  权限 selinux开启 有硬链接 所有者 所属组 占用空间 日期  文件名称        [[email protected] ~]# which ls        alias ls=‘ls --color=auto‘            /usr/bin/ls        [[email protected] ~]# which ll        alias ll=‘ls -l --color=auto‘            /usr/bin/ls

2.4 File types

d  目录-  普通文件  可以使用cat查看c  字符串设备l  软连接文件 ,相当于Windows快捷方式b  块设备s  soket文件,通信功能

2.5 alias Command aliases

    [[email protected] ~]# alias alias cp= ' Cp-i ' Alias egrep= ' Egrep--color=auto ' Alias fgrep= ' Fgrep--colo R=auto ' Alias grep= ' grep--color=auto ' Alias l.= ' ls-d. *--color=auto ' Alias ll= ' ls-l--color=auto ' Alias ls = ' ls--color=auto ' alias mv= ' mv-i ' Alias rm= ' rm-i ' Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde ' [[email protected] ~]# alias aming= ' Ls-lha ' [[  Email protected] ~]# aming total dosage 32K dr-xr-x---.    3 root root 202 February 25 09:27. Dr-xr-xr-x.    Root root 245 February 24 22:55..  -RW-------.  2 root root 1.4K February 22:22 anaconda-ks.cfg-rw-------.  2 root root 1.4K February 22:22 anaconda-ks.cfg.bak lrwxrwxrwx.  1 root root 15 February 09:27 Anaconda-ks.cfg.rbak-ANACONDA-KS.CFG-RW-------.  1 root root 2.5K February 09:50. Bash_history-rw-r--r--.  1 root root 18 December bash_logout-rw-r--r--.  1 root root 176 December bash_profile-rw-r--r--. 1 Root root 176 December bashrc-rw-r--r--.  1 root root 100 December cshrc drwx------.  2 root root 80 February 00:40. Ssh-rw-r--r--.    1 root root 129 December TCSHRC [[email protected] ~]# unalias aming [[email protected] ~]# aming -bash:aming: Command not found

2.6 Absolute and relative paths

绝对路径:从根开始的    ls /etc/sysconfig/network-scripts/ifcfg-ens33    ls /root/.ssh/相对路径:相对于当前路径开始的路径    ls .ssh/authorized_keys    ls network-scripts/ifcfg-ens33pwd  查看当前路径

2.7 CD command

-  返回上一次打开的目录~  返回家目录 或 直接cd 功能一样.  当前目录.. 返回上级目录

2.8 Creating and deleting directories mkdir rmdir

mkdir    -p 递归创建目录    -v 显示过程    mkdir -p /tmp/aming/123rmdir  删除非空目录

2.9 rm command, use with caution

-r 连续多级文件夹删除-f 强制,直接删除不提示-v 显示过程    rm -rf /tmp/aming/123    [[email protected] ~]# which rm    alias rm=‘rm -i‘        /usr/bin/rm

2.10 environment variable PATH

    [[email protected] ~]# echo $PATH    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin添加环境变量    [[email protected] ~]# PATH=$PATH:/tmp/    [[email protected] ~]# echo $PATH    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/改回默认环境变量    [[email protected] ~]# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin    [[email protected] ~]# echo $PATH    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

2.11 CP Copy

-r 递归复制目录     复制目录过程中,目标路径存在相同名称的目录,直接覆盖,不存在则自动创建这个名称的目录        [[email protected] ~]# cp /etc/passwd /tmp/1.txt        [[email protected] ~]# cp -r /etc/passwd/ /tmp/aming/        [[email protected] ~]# ls /tmp        1.txt        aming!$ 上一条命令的,最后一个参数        [[email protected] ~]# tree !$        tree /tmp        /tmp        ├── 1.txt        ├── aming    [[email protected] ~]# which cp    alias cp=‘cp -i‘        /usr/bin/cp

2.12 MV Move

移动并改名    mv 目标文件 新文件名称    mv 目标目录 新目录名称移动到目标文件到目标目录    mv 目标文件 目标目录

2.13 Document View cat more less head tail

cat 目标文件    -A  行尾显示结束符    -n  显示行号tac 目标文件,倒序查看more 多屏显示less 查看文件时,可以上下滚动浏览head 查看文件的头十行     head -n 20tail 查看文件的后十行     tail -n 5     tail -f /var/log/messages  动态显示日志

2.14 chmod modify file or directory permissions

-R recursively Change permissions for all directories and files within a folder

rwxr=4  w=2  x=1chmod 700 2.txtchmod u=rwx,g=r,o=r 2.txtchmod a+x 2.txtchmod ugo-x 2.txt

2.15 Chown Change owner and owning group

chown -R username:group filename-R 递归更改文件夹内所有目录和文件的所属        [[email protected] tmp]# chown aming /tmp/yum.log         [[email protected] tmp]# ll /tmp/yum.log         -rw-------. 1 aming root 0 2月  24 22:17 /tmp/yum.log        [[email protected] tmp]# chgrp user1 /tmp/yum.log         [[email protected] tmp]# ll /tmp/yum.log         -rw-------. 1 aming user1 0 2月  24 22:17 /tmp/yum.log        [[email protected] tmp]# chown user1:aming /tmp/yum.log         [[email protected] tmp]# ll /tmp/yum.log         -rw-------. 1 user1 aming 0 2月  24 22:17 /tmp/yum.log

2.16 Umask

创建文件默认权限 644创建目录默认权限 755    [[email protected] tmp]# umask    0022022 644 755002 664 775目录  777 - 022 = 755文件  666 - 022 = 644   遇到奇数+1

2.17 lsattr chattr Hidden permissions

chattr  设置隐藏权限    +i 不允许对文件进行任何操作,可以更改目录内文件的内容    +a 可以对文件进行追加内容和修改时间,不能更改名字、删除、更改原有内容       可以对目录和目录里的文件进行修改内容和修改时间,不能更改目录名字、删除,可更改目录里内容        [[email protected] tmp]# chattr +i 1.txt        [[email protected] tmp]# lsattr 1.txt        ----i----------- 1.txt        [[email protected] tmp]# mv 1.txt 3.txt        mv: 无法将"1.txt" 移动至"3.txt": 不允许的操作        [[email protected] tmp]# chattr -i 1.txt        [[email protected] tmp]# mv 1.txt 3.txt

2.18 Special permissions Set UID

普通用户在执行带S权限的这个命令时,临时获得root的权限执行命令        [[email protected] tmp]# ls -l /usr/bin/passwd        -rwsr-xr-x. 1 root root 27832 6月  10 2014 /usr/bin/passwd        [[email protected] ~]$ ls /root/        ls: 无法打开目录/root/: 权限不够        [[email protected] tmp]# chmod u+s /usr/bin/ls        [[email protected] tmp]# ls -l /usr/bin/ls        -rwsr-xr-x. 1 root root 117656 11月  6 2016 /usr/bin/ls        [[email protected] ~]$ ls /root/        anaconda-ks.cfg  anaconda-ks.cfg.bak  anaconda-ks.cfg.rbak        [[email protected] tmp]# chmod u=rws /usr/bin/ls        [[email protected] tmp]# ls -l /usr/bin/ls        -rwSr-xr-x. 1 root root 117656 11月  6 2016 /usr/bin/ls        [[email protected] tmp]# chmod u+x /usr/bin/ls        [[email protected] tmp]# ls -l /usr/bin/ls        -rwsr-xr-x. 1 root root 117656 11月  6 2016 /usr/bin/ls

2.19 Set GID

普通用户临时拥有所属组的权限,目录的所属组设置了S权限后,在这个目录下创建的子文件或子目录所属组和该目录的所属组相同        [[email protected] tmp]# chmod g+s /usr/bin/ls        [[email protected] tmp]# ls -l /usr/bin/ls        -rwxr-sr-x. 1 root root 117656 11月  6 2016 /usr/bin/ls        [[email protected] tmp]# mkdir 234        [[email protected] tmp]# chmod g+s 234        [[email protected] tmp]# ls -ld 234        drwxr-sr-x. 2 root root 6 2月  25 20:42 234        [[email protected] tmp]# chown :user1 234        [[email protected] tmp]# ls -ld 234        drwxr-sr-x. 2 root user1 6 2月  25 20:42 234        [[email protected] tmp]# touch 234/aminglinux        [[email protected] tmp]# mkdir 234/am        [[email protected] tmp]# ls -l 234/        总用量 0        drwxr-sr-x. 2 root user1 6 2月  25 20:44 am        -rw-r--r--. 1 root user1 0 2月  25 20:44 aminglinux

2.20 Special Permissions Stick_bit

chmod o+t /tmp/aming带t特殊权限的目录,防止别人删除该目录里的文件        [[email protected] tmp]# ls -ld /tmp/        drwxrwxrwt. 13 root root 4096 2月  25 20:42 /tmp/

2.21 Soft Connection files

ln -s 源filename 目标filename ln -s 源dir  目标dir        [[email protected] tmp]# ls -l /bin        lrwxrwxrwx. 1 root root 7 2月  24 22:18 /bin -> usr/bin软连接:节省空间,尽量使用绝对路径,源文件改名或者路径改名,会找不到,通过软链接,可以把文件占用空间转移到其他分区,inode不同        [[email protected] tmp]# ln -s /tmp/yum.log /root/yum.txt        [[email protected] tmp]# ls -l /root/        总用量 8        lrwxrwxrwx. 1 root root   12 2月  25 21:06 yum.txt -> /tmp/yum.log

2.22 Hard Links

ln source filename, target filename

The inode is the same, the directory cannot be hard-linked, hard links cannot be created across partitions, and the file itself exists after the source file is deleted

    [[email protected] tmp]# ln 2.txt 5.txt    [[email protected] tmp]# ls -lih    总用量 12K    16784510 -rw-------. 2 root  root    0 2月  25 19:25 2.txt    17377740 -rw-r--r--. 1 root  root  887 2月  25 18:21 3.txt    16784510 -rw-------. 2 root  root    0 2月  25 19:25 5.txt

2.23-24-25 Find

    Which search in environment variables Whereis search for a library, not all locate yum install mlocate, updatedb Update library-name-type f\d\l\b\s\c-atime last access time Access-mtime Most recent change time Modify changed the contents of the file, Mtime and CTime will certainly edge-ctime Recent changes change the file permissions CTime change, mtime unchanged-o or, rarely used-mmin-60 minutes        -size +size [[email protected] tmp]# find/dev-type b/dev/sr0/dev/sda3/dev/sda2 /DEV/SDA1/DEV/SDA [[email protected] tmp]# find/etc/-type f-mtime-1 within 1 days [[EMAIL PR        Otected] tmp]# find/etc/-type f-mtime +1 1 days ago [[email protected] tmp]# find/etc/-type f-o-mtime-1        [[email protected] tmp]# find/root/-type f-mmin-120-exec ls-l {} \;        [[email protected] tmp]# find/root/-type f-mmin-150-exec mv {} {}.bak \; [[email protected] tmp]# find/root/-type f-mmin-150/root/.lesshst.bak [[email protected] tmp]        # find/root/-type f-size-50k-exec ls-lh {} \; -rw-r--r--. 1 root root 18 12Moon 2013/root/.bash_logout-rw-r--r--. 1 root root 176 December 2013/root/.bash_profile-rw-r--r--. 1 root root 176 December 2013/root/.bashrc-rw-r--r--. 1 root root 100 December 2013/root/.cshrc-rw-r--r--. 1 root root 129 December 2013/ROOT/.TCSHRC [[email protected] tmp]# find/root/-type f-size +1k-exec LS-LH        {} \; -RW-------. 2 root root 1.4K February 22:22/root/anaconda-ks.cfg-rw-------. 1 root root 2.5K February 09:50/root/.bash_history-rw-r--r--. 1 root root 1.3K February 00:17/root/.ssh/authorized_keys-rw-------. 1 root root 1.7K February 00:34/root/.ssh/id_rsa-rw-------. 2 root root 1.4K February 22:22/root/anaconda-ks.cfg.bak

2.26 file name suffix

2.27 Linux and Windows inter-pass files

[[email protected] tmp]# yum install -y lrzszsz filename   linux文件传输到Windowsrz 选择文件     Windows文件传输到linux

day02-Amin linux-file, directory 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.