zoukankan      html  css  js  c++  java
  • 💌文件查找📥 上传下载🔌 输出重定向

    一、查看命令所属文件

            which ip

         / usr / sbin / ip

         一些命令的路径都被配置到了环境变量PATH里

    二、查找文件

         find [options] [path...] [expression]

    按文件名查找

    [root@localhost ~]# find /etc -name "ifcfg-eth0"
    [root@localhost ~]# find /etc -iname "ifcfg-eth0" # -i忽略大小写
    [root@localhost ~]# find /etc -iname "ifcfg-eth*" 
    

      按文件大小

    [root@localhost ~]# find /etc -size +3M #大于3m
    [root@localhost ~]# find /etc -size 3M
    [root@localhost ~]# find /etc -size -3M
    [root@localhost ~]# find /etc -size +3M -ls # -ls找到处理动作 
    

      指定查找的目录深度

    -maxdepth levels
    [root@localhost ~]# find / -maxdepth 5 -a -name "ifcfg-eth0" # -a并且-o或
    者,不加-a,默认就是-a
    

      按时间查找(atime,mtime,ctime)

    [root@localhost ~]# find /etc -mtime +3 # 修改时间超过三天
    [root@localhost ~]# find /etc -mtime 3 # 修改时间等于三天
    [root@localhost ~]# find /etc -mtime -3 # 修改时间三天以内
    

      按文件属主、属组查找

    [root@localhost ~]# find /home -user 用户名      #属主是用户的文件 
    [root@localhost ~]# find /home -group it          #属组是it组的文件 
    [root@localhost ~]# find /home -user 用户-group it
    [root@localhost ~]# find /home -user 用户 -a -group it # 同上
    [root@localhost ~]# find /home -user  用户-o -group it
    [root@localhost ~]# find /home -nouser # 用户还存在,在/etc/passwd中删除记录
    [root@localhost ~]# find /home -nogroup # 用户还在,在/etc/group中删除记录
    [root@localhost ~]# find /home -nouser -o -nogroup
    

      按文件类型查找

    [root@localhost ~]# find /dev -type f # f 普通
    [root@localhost ~]# find /dev -type d # d 目录
    [root@localhost ~]# find /dev -type l # l 链接
    [root@localhost ~]# find /dev -type b # b 块设备
    [root@localhost ~]# find /dev -type c # c字符设备
    [root@localhost ~]# find /dev -type s # s 套接字
    [root@localhost ~]# find /dev -type p # p 管道文件
    

      根据inode号查找:-inum n

    [root@localhost ~]# find / -inum 1811
    

      按文件权限查找

    [root@localhost ~]# find . -perm 644 -ls
    [root@localhost ~]# find . -perm -644 -ls
    [root@localhost ~]# find . -perm -600 -ls
    [root@localhost ~]# find /sbin -perm -4000 -ls # 包含set uid
    [root@localhost ~]# find /sbin -perm -2000 -ls # 包含set gid
    [root@localhost ~]# find /sbin -perm -1000 -ls # 包含sticky
    

      找到后处理动作

    -print
    -ls
    -delete
    -exec
    -ok
    [root@localhost ~]# find /etc -name "ifcfg*" -print # 必须加引号
    [root@localhost ~]# find /etc -name "ifcfg*" -ls
    [root@localhost ~]# find /etc -name "ifcfg*" -exec cp -rvf {} /tmp ; # 非交互
    [root@localhost ~]# find /etc -name "ifcfg*" -ok cp -rvf {} /tmp ; # 交互
    [root@localhost ~]# find /etc -name "ifcfg*" -exec rm -rf {} ;
    [root@localhost ~]# find /etc -name "ifcfg*" -delete # 同上
    

    三、上传下载

    1.下载

    wget命令

    wget -O 本地路径 远程包地址# 将远程包下载到本地-O指定下载到哪里,可以生路-O 本地路径
    # ps:如果wget下载提示无法建立SSL连接,则加上选项--no-check-certificate
    wget --no-check-certificate -O 本地路径 远程包连接地址
    

      curl命令

    curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按照传统,习惯称curl为下载工具。作为一款强力工具,curl支持包括HTTP,HTTPS,[ftp]等众多协议,还支持POST,cookis,认证,从指定偏移处下载部分文件,用户代理字符串,限速,文件大小,进度条等特征。做网页处理流程和数据检索自动化,curl可助一臂之力。

    [root@localhost ~]# curl -o 123.png https://www.xxx.com/img/hello.png
    # ps: 如果遇到下载提示无法建立SSL连接,使用-k选项或者--insecure
    curl -k -o 123.png https://www.xxx.com/img/hello.png
    

      sz命令

    系统默认没有该命令,要下载:yum install lrzsz -y
    将服务器上选定的文件下载/发送到本机
    [root@localhost ~]# sz bak.tar.gz
    

         2.上传

    rz命令

    系统默认没有该命令,要下载:yum install lrzsz -y
    运行该命令会弹出一个窗口,从本地选择文件上传到服务器。
    rz  如果文件已经存在,则上传失败,可以用-E选项解决
    rz -E   -E如果目标文件已经存在,则重命名传入文件。新文件将添加一个点和一个数字(0..99)
    

    四、输出与重定向

    输出即把相关对象通过输出设备(显示器等)显示出来,输出又分正确输出和错误输出,一般情况下标准输出设备为显示器,标准输入设备为键盘

    linux中

    • 0代表标准输入
    • 1代表标准正确输出
    • 2代表标准错误输出

     输出重定向

    正常输出是把内容输出到显示器上,而输出重定向是把内容输出到文件中,>代表覆盖,>>代表追加

    ps:标准输出的1 可以省略

     例如:ifconfig > test.log即把ifconfig执行显示的正确内容写入test.log。当前页面不再显示执行结果。

    注:错误输出重定向>与>>后边不加空格

     

     注:

    • 下述两个命令作用相同
    命令>>file.log 2>&1
    命令 &>>file.log
    • 正确日志和错误日志分开保存
    命令 >>file1.log 2>>file2.log
    
    • 系统有个常见用法ls &>/dev/null正确输出或错误输出结果都不要。(null可以理解为黑洞或者垃圾站)

    输入重定向

    没有改变输入的方向,默认键盘,此时等待输入
    [root@123 ~]# tr 'N' 'n'
    No
    no
    [root@123 ~]# tr 'N' 'n' < file.txt
    
    没有改变输入的方向,默认键盘,此时等待输入
    [root@123 ~]# grep 'root'
    oldboy
    root
    root
    
    [root@123 ~]# grep 'root' < /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    
    读写块设备
    [root@123 ~]# dd if=/dev/zero of=/file1.txt bs=1M count=20
    [root@123 ~]# dd </dev/zero >/file2.txt bs=1M count=20
    
    
    # mysql如何恢复备份
    [root@qls ~]# mysql -uroot -p123 < bbs.sql
    

      

  • 相关阅读:
    浅谈系统调用与库函数
    由代码到可执行程序----浅谈程序的编译链接
    初识信号---进程间的交流
    内部排序总结之----选择类排序(选择、堆)
    僵死进程
    父子进程那些事儿
    fok函数
    面试-css样式
    面试-javascript知识
    面试--数据库
  • 原文地址:https://www.cnblogs.com/ChuangShi-HolySpirit/p/13881307.html
Copyright © 2011-2022 走看看