Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»General Articles»How to Preserve Directory Path with CP Command

    How to Preserve Directory Path with CP Command

    RahulBy RahulJanuary 10, 20201 Min ReadUpdated:January 18, 2020

    The cp command is used to copy files from one directory to another directory. Some times you are required to copy a file with its parent directory structure.

    You can use -r option to copy files recursively. But if we need to copy a single file with the full directory structure. Use cp command with --parents option to use full source file name under the directory and create a similar directory structure on the destination.

    cp --parents ./dir1/dir2/myfile.txt /opt/
    

    Now list the file on the destination directory. You can see that the same directory structure is created in the destination directory.

    ls -l /opt/dir1/dir2/myfile.txt
    
    -rwxr-xr-x 1 root root 4864094 Jan 15 11:09 /opt/dir1/dir2/myfile.txt
    
    command cp
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleCentOS 8 – Initial Server Setup
    Next Article How to Install Gradle on CentOS 7

    Related Posts

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    (Resolved) – ReactJS 404 Error on Page Reload

    2 Mins Read

    Adding a New SSH Key in GitHub

    Updated:April 1, 20223 Mins Read

    13 Best Linux Terminal Emulators and Bash Editors

    8 Mins Read

    How To Install Oracle VirtualBox on Debian 11

    2 Mins Read

    10 Best Linux FTP Clients in 2022

    5 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.