• Creating a Directory
  • Let’s create newfile with  touch : kali > touch newfile




    Download 7,3 Mb.
    Pdf ko'rish
    bet39/125
    Sana14.05.2024
    Hajmi7,3 Mb.
    #232858
    1   ...   35   36   37   38   39   40   41   42   ...   125
    Bog'liq
    linuxbasicsforhackers

    15
    Let’s create newfile with 
    touch
    :
    kali >
    touch newfile
    Now when I then use 
    ls –l
    to see the long list of the directory, I see that 
    a new file has been created named newfile. Note that its size is 
    0
    because there 
    is no content in newfile.
    Creating a Directory
    The command for creating a directory in Linux is 
    mkdir
    , a contraction of 
    make directory. To create a directory named newdirectory, enter the following 
    command:
    kali >
    mkdir newdirectory
    To navigate to this newly created directory, simply enter this:
    kali >
    cd newdirectory
    Copying a File
    To copy files, we use the 
    cp
    command. This creates a duplicate of the file in 
    the new location and leaves the old one in place.
    Here, we’ll create the file oldfile in the root directory with 
    touch
    and 
    copy it to /root/newdirectory, renaming it in the process and leaving the ori-
    ginal oldfile in place:
    kali >
    touch oldfile
    kali >
    cp oldfile /root/newdirectory/newfile
    Renaming the file is optional and is done simply by adding the name 
    you want to give it to the end of the directory path. If you don’t rename the 
    file when you copy it, the file will retain the original name by default.
    When we then navigate to newdirectory, we see that there is an exact 
    copy of oldfile called newfile:
    kali >
    cd newdirectory
    kali >
    ls
    newfile oldfile
    Renaming a File
    Unfortunately, Linux doesn’t have a command intended solely for renaming 
    a file, as Windows and some other operating systems do, but it does have the 
    mv
    (move) command.


    16
    Chapter 1
    The 
    mv
    command can be used to move a file or directory to a new loca-
    tion or simply to give an existing file a new name. To rename newfile to 
    newfile2, you would enter the following:
    kali >

    Download 7,3 Mb.
    1   ...   35   36   37   38   39   40   41   42   ...   125




    Download 7,3 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Let’s create newfile with  touch : kali > touch newfile

    Download 7,3 Mb.
    Pdf ko'rish