zoukankan      html  css  js  c++  java
  • Liunx快捷命令(别名)与快捷方式(软/硬链接)

    一.快捷命令(别名)-临时生效
    1.命令:
    alias 别名='原命令'

    2.举例:给检查防火墙的命令设置别名

    [root@localhost ~]# alias fhq='firewall-cmd --state'
    [root@localhost ~]# fhq
    not running

    注:重新登陆入窗口后别名会失效

    Connecting to 192.168.37.8:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.
    
    WARNING! The remote SSH server rejected X11 forwarding request.
    Last login: Mon Sep 20 16:00:43 2021 from 192.168.37.1
    [root@localhost ~]# fhq
    -bash: fhq: command not found

     

    二.快捷命令(别名)-永久生效
    需要写入环境变量配置文件~/.bashrc(该文件中的配置只对当前用户有效,而/ect/profile的配置是对所有用户有效的)

    [root@localhost ~]# vi ~/.bashrc 
    # .bashrc
    
    # User specific aliases and functions
    
    alias rm='rm -i'
    alias cp='cp -i'
    alias mv='mv -i'
    
    # Source global definitions
    if [ -f /etc/bashrc ]; then
            . /etc/bashrc
    fi
    
    alias fhq='firewall-cmd --state'

    source ~/.bashrc  #source使其生效,重新连接机器后仍生效

    [root@localhost ~]# source ~/.bashrc  #source使其生效
    [root@localhost ~]# fhq
    not running
    [root@localhost ~]# exit
    logout
    Connection closing...Socket close.
    
    Connection closed by foreign host.
    
    Disconnected from remote host(192.168.37.8) at 09:30:26.
    
    Type `help' to learn how to use Xshell prompt.
    [D:~]$ 
    
    Connecting to 192.168.37.8:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.
    
    WARNING! The remote SSH server rejected X11 forwarding request.
    Last login: Mon Sep 20 16:04:28 2021 from 192.168.37.1
    [root@localhost ~]# fhq
    not running

    三.快捷方式-软链接

    1.概念

    符号连接(Symbolic Link),也叫软连接。软链接文件有类似于Windows的快捷方式。它实际上是一个特殊的文件。在符号连接中,文件实际上是一个文本文件,其中包含的有另一文件的位置信息

    2.建立软链接:(ln -s)

    [root@localhost test20211009]# ll
    total 0
    [root@localhost test20211009]# ln -s /opt/bktest/ bktest  #建立文件夹软链
    [root@localhost test20211009]# ln -s /etc/profile profile  #建立文件软链
    [root@localhost test20211009]# ll
    total 0
    lrwxrwxrwx. 1 root root 12 Sep 20 16:23 bktest -> /opt/bktest/
    lrwxrwxrwx. 1 root root 12 Sep 20 16:23 profile -> /etc/profile

    3.修改软链接:(ln -snf)

    [root@localhost test20211009]# ll bktest
    lrwxrwxrwx. 1 root root 12 Sep 20 16:26 bktest -> /opt/bktest/
    [root@localhost test20211009]# ln -snf /opt/bktest/1 bktest
    [root@localhost test20211009]# ll bktest
    lrwxrwxrwx. 1 root root 13 Sep 20 16:26 bktest -> /opt/bktest/1

    4.删除软链接:(rm -rf)

    [root@localhost test20211009]# ll bktest
    lrwxrwxrwx. 1 root root 13 Sep 20 16:26 bktest -> /opt/bktest/1
    [root@localhost test20211009]# rm -rf bktest
    [root@localhost test20211009]# ll bktest
    ls: cannot access bktest: No such file or directory

    四.快捷方式-硬链接

    1.概念

    硬连接指通过索引节点来进行连接。在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index)。在Linux中,多个文件名指向同一索引节点是存在的。一般这种连接就是硬连接。硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要文件,以防止“误删”的功能。其原因如上所述,因为对应该目录的索引节点有一个以上的连接。只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个连接被删除后,文件的数据块及目录的连接才会被释放。也就是说,文件真正删除的条件是与之相关的所有硬连接文件均被删除

    2.建立硬链接(ln)

    [root@localhost test20211009]# touch hardlink1
    [root@localhost test20211009]# ln hardlink1 hardlink2
    [root@localhost test20211009]# ll
    total 0
    -rw-r--r--. 2 root root 0 Sep 20 16:32 hardlink1
    -rw-r--r--. 2 root root 0 Sep 20 16:32 hardlink2
    [root@localhost test20211009]# echo helloworld >> hardlink1
    [root@localhost test20211009]# cat hardlink1
    helloworld
    [root@localhost test20211009]# cat hardlink2
    helloworld

    注:硬链接只能针对文件

    [root@localhost test20211009]# mkdir hardlink3
    [root@localhost test20211009]# ln hardlin3 hardlink4
    ln: failed to access ‘hardlin3’: No such file or directory

    3.修改硬链接

    注:硬链接修改其中一个文件后,其他均发生改变,链接本身不能修改

    [root@localhost test20211009]# cat hardlink1
    ok
    [root@localhost test20211009]# cat hardlink2
    ok

    4.删除硬链接

    注:删除其中一个硬链接文件不会影响其他文件,直到文件全部删除,目录才会释放

    [root@localhost test20211009]# ll
    total 8
    -rw-r--r--. 2 root root 3 Sep 20 16:39 hardlink1
    -rw-r--r--. 2 root root 3 Sep 20 16:39 hardlink2
    [root@localhost test20211009]# rm -rf hardlink1
    [root@localhost test20211009]# ll
    total 4
    -rw-r--r--. 1 root root 3 Sep 20 16:39 hardlink2
  • 相关阅读:
    pdf工具类之合并pdf文件
    Java 处理不可见特殊字符的坑
    将本地的jar包加到maven中,pom添加依赖
    SQLServer常用个技巧(一):根据某字符截取后面的字符串,String转int
    java下载文件写的工具类
    使用SWFTools将pdf转成swf
    使用openOffice将office文件转成pdf
    poi处理excel基本操作时写的工具类
    poi处理excel的合并单元格写的工具类,支持xlsx和xls
    java有关正则表达式的工具方法集合1
  • 原文地址:https://www.cnblogs.com/mrwhite2020/p/15380782.html
Copyright © 2011-2022 走看看