ตั้งค่าการอ่าน

ค่าเริ่มต้น

  • เลื่อนอัตโนมัติ
    Easy Programing

    ลำดับตอนที่ #3 : Command Line Ⅰ - Handling Files and Folders

    • เนื้อหาตอนนี้เปิดให้อ่าน
    • 40
      0
      31 ธ.ค. 61

    Moving Files and Directories

    Working with Files and Directories

              From this point on, we're going to learn how to perform a variety of operations like moving, copying, and deleting files with commands.


    Moving a File

              Let's start with the command to move a file. To do this, we use the mv command. By typing mv file_to_move destination_directory, you can move a file to the specified directory.


    Moving a Directory

              With the mv command, you can also move directories, not just files. By entering mv directory_to_move destination_directory, you can move all the files and directories under that directory.



    Renaming Files and Directories

    Renaming a File

              The mv command, which we used to move files and directories earlier, can also be used to rename a file. You can rename a file by typing mv old_file_name new_file_name.



    Copying Files and Directories

    Copying a File

              Next, let's look at how to copy files. To do this, we use the cp command. You can copy a file by entering cp file_to_copy new_file_name.


    Copying a Directory

              With the cp command, you can also copy a directory by adding the -r option, like cp -r directory_to_copy new_directory_name.


    Error with the cp Command

              If you try to copy a directory without adding the -r option, you will get an error and the command will not be executed.



    Removing Files and Directories

    Removing a File

              Next, we'll look at how to remove a file. To do this, you can use the rm command, like rm file_to_remove.


    Removing a Directory

              You can also remove a directory by adding the -r option to the rm command, like rm -r directory_to_remove. Just like the cp command, you will get an error if you forget to add -r.



    Review

              The last exercise is the review of all the commands we've learned so far. We'll create a file structure like in the image below. But, before the exercise, there's one last thing that we should learn.


    The Commands History

    On the command line, you can go through the command history using the up arrow key . This is very convenient when you want to use a command that was executed before.







    ติดตามเรื่องนี้
    เก็บเข้าคอลเล็กชัน

    นิยายที่ผู้อ่านนิยมอ่านต่อ ดูทั้งหมด

    loading
    กำลังโหลด...

    อีบุ๊ก ดูทั้งหมด

    loading
    กำลังโหลด...

    ความคิดเห็น

    ×