zoukankan      html  css  js  c++  java
  • Linux 命令:文件目录操作与实例

    来源: http://blog.51cto.com/yuanzhitang/2056994

    本文介绍基础的文件操作:创建,移动,编辑,删除 文件和文件夹

     

    命令与案例:

     

    mkdir 创建目录

     

    --创建两个目录

    tangym@ubuntu:~$ mkdir test2 test3
     

     

    --在test1下面创建一个新的目录mydir

    tangym@ubuntu:~$ mkdir test1/mydir
     

     

    --尝试在test100下面创建一个新的目录mydir,但不成功,因为test100这个目录不存在

    tangym@ubuntu:~$ mkdir test100/mydir 
    mkdir: cannot create directory `test100/mydir': No such file or directory
     

     

    -- 强制创建父子这两个文件, 尽管test100这个父目录不存在

    tangym@ubuntu:~$ mkdir -p test100/mydir
     

     

    touch 创建文件

     

    --创建hello文件在当前目录

    tangym@ubuntu:~$ touch hello 
    echo
     

     

    -- 写 "hello" 到这个目录

    tangym@ubuntu:~/test1$ cat hellobackup
    tangym@ubuntu:~/test1$ echo "hello" > hellobackup 
    tangym@ubuntu:~/test1$ cat hellobackup
    hello
     

     

     

    mv 移动或重命名文件

     

    -- 移动文件 hello到test1文件夹

    tangym@ubuntu:~$ mv hello test1
     

     

    --重命名文件hello为hellobackup

    tangym@ubuntu:~/test1$ mv hello hellobackup
     

     

    cp 拷贝文件

    tangym@ubuntu:~$ cp pse2 test2 -- copy file pse2 to test2 folder
     

     

    rm/rmdir 删除文件和文件夹

     

    --删除文件hello

    tangym@ubuntu:~$ rm hello
     

     

    --删除文件夹test2
    tangym@ubuntu:~$ rmdir test2

     

    输入重定向至文件:

     

    下面将会把界面的输入写入文件hellobackup文件

    tangym@ubuntu:~$ cat <<EOF >hellobackup
    > hello world!
    > real func
    > EOF
     
    常看文件内容
    tangym@ubuntu:~$ cat hellobackup
    hello world!
    real func
    tangym@ubuntu:~$
     


    完整的例子(创建和删除文件)

    tangym@ubuntu:~$ cd mhydir
    tangym@ubuntu:~/mhydir$ ls
    tangym@ubuntu:~/mhydir$ touch test
    tangym@ubuntu:~/mhydir$ ls
    test
    tangym@ubuntu:~/mhydir$ rm test
    tangym@ubuntu:~/mhydir$ ls
    tangym@ubuntu:~/mhydir$ touch test
    tangym@ubuntu:~/mhydir$ rm -i test   --Will Confirm whether delete the file
    rm: remove regular empty file `test'? n
    tangym@ubuntu:~/mhydir$ ls
    test
    tangym@ubuntu:~/mhydir$ rm -i test
    rm: remove regular empty file `test'? y
    tangym@ubuntu:~/mhydir$ ls
    tangym@ubuntu:~/mhydir$
  • 相关阅读:
    SAP S/4HANA extensibility扩展原理介绍
    SAP CRM系统订单模型的设计与实现
    使用nodejs代码在SAP C4C里创建Individual customer
    SAP Cloud for Customer Account和individual customer的区别
    Let the Balloon Rise map一个数组
    How Many Tables 简单并查集
    Heap Operations 优先队列
    Arpa’s obvious problem and Mehrdad’s terrible solution 思维
    Passing the Message 单调栈两次
    The Suspects 并查集
  • 原文地址:https://www.cnblogs.com/hahajava/p/10207029.html
Copyright © 2011-2022 走看看