• shell文件相关指令


    文件解压缩tar

    请参考文档:http://blog.csdn.net/eroswang/article/details/5555415/

    tar -zcvf ${standardpath}${filename}.tar.gz ${filename}

    文件删除rm

    rm -r /dir
    rm file
    rm -rf /dir
    -r, -R, --recursive
                  remove directories and their contents recursively
    -f, --force
                  ignore nonexistent files and arguments, never prompt
     -i     prompt before every removal
    View Code

    文件复制cp

    cp /sourcefile /destinationfile
    cp sources /directory
    -R, -r, --recursive
                  copy directories recursively
    -n, --no-clobber
                  do not overwrite an existing file (overrides a previous -i option)
    -f, --force
                  if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also
                  used)
    View Code

    文件移动,重命名mv

    mv sourcefile destfile/path
    mv sourcedir destdir
    Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
    -f, --force
                  do not prompt before overwriting
    -i, --interactive
                  prompt before overwrite
    -n, --no-clobber
                  do not overwrite an existing file
    View Code

    改变工作目录cd

    cd -   回到上一次的工作目录
    cd
    cd ~
    cd /

    创建目录mkdir

    mkdir dirname
    -p, --parents
                  no error if existing, make parent directories as needed
    mkdir -P /path
    View Code

    创建文件touch

    touch file

    查看文件路径pwd

    pwd

    查看文件大小du

    du -h 
    du -h /path
    stat -c%s /home/hadoop/test.txt

    查看目录下文件数量

    ls -l | grep '^-' | wc -l

    查看目录下子目录的数量

    ls -l | grep '^d' | wc -l

    查看文件详细信息ls

    ls
    ls -l   /   ll
    ls -ash
    -a, --all
                  do not ignore entries starting with .
    -h, --human-readable
                  with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)
    -s, --size
                  print the allocated size of each file, in blocks
    -l     use a long listing format
    View Code

    查找文件find,which

    find [路径] [参数]
    参数说明:
     时间:
       -atime n    :在 n*24小时内被 access 即存取过的文件列出来!
       -ctime n    :在 n*24小时内被 changed 即改变、新增的文件或目录印出
       -mtime n    :在 n*24小时内被 modified 即修改过的文件印出
       -newer file :比 file 还要新的文件就列出来!
    
    使用名称:
    
       -gid n     :寻找 群组 ID 为 n 的文件
       -group name :寻找群组名称为 name的文件
       -uid n     :寻找拥有者 ID 为 n 的文件
       -user name :寻找使用者名称为 name 的文件
       -name file :寻找档名为 file 的文件名称(可以使用万用字符)
       -type type :寻找档案属性为 type 的档案,type 包含了 b, c, d, p, l, s,这些与前一章的属性相同!例如 l 为 Link而 d 为路径之意!
    
    
    which ls(which也可以查找)
    例如
    
    [root@bestlinux ~]# find / -nametesting           //查找名为 testing  的文件
    [root@bestlinux ~]# find / -name'test*'         //查找以test开头的文件
    [root@bestlinux ~]# find . -ctime1                //查找当前目录下一天内新增的文件
    [root@bestlinux ~]# find /home -usertest      //查找 /home下拥有者为 test 的文件
    View Code

    查看文件内容cat,head,tail

    cat /etc/services
    head -n /etc/services(查看文件前n行的内容)
    tail -n /etc/services(查看文件后n行内容)
    more /etc/services (文件内容会一屏一屏的显示出来,你只需用空格键就可以下翻了)
    cat /etc/services | more(cat显示出来的内容重新输出给 more 命令就可以达到想要效果)

    查看文件内容的行数

     wc -l /etc/services

    以上内容参考了:http://www.cnblogs.com/lanse-yan/archive/2012/11/29/2794300.html

  • 相关阅读:
    Vue Errors
    npm学习笔记二
    npm安装package.json文件中的模块依赖
    浅析对浏览器内核的理解
    JavaScript中的匿名函数、立即执行函数和闭包
    ECMAScript中的函数
    JavaScript中的构造函数
    如何配置Tomcat上web.xml让浏览器能直接下载txt,xml类型文件
    Caused by: java.sql.SQLException: GC overhead limit exceeded处理百万数据出现的异常
    第3篇 Scrum 冲刺博客(专✌️团队)
  • 原文地址:https://www.cnblogs.com/husky/p/6428192.html
Copyright © 2020-2023  润新知