Close Menu
    Facebook X (Twitter) Instagram
    • About
    • Privacy Policy
    • Write For Us
    • Newsletter
    • Contact
    Instagram
    About ChromebooksAbout Chromebooks
    • Linux
    • News
      • Stats
      • Reviews
    • AI
    • How to
      • DevOps
      • IP Address
    • Apps
    • Business
    • Q&A
      • Opinion
    • Gaming
      • Google Games
    • Blog
    • Podcast
    • Contact
    About ChromebooksAbout Chromebooks
    Linux

    How to Copy CP Directory Folder On Linux

    Dominic ReignsBy Dominic ReignsJanuary 12, 2026Updated:March 25, 2026No Comments5 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest

    The cp command copies files and directories in Linux. Unlike copying a single file, directories require the -r flag to recursively copy all contents — without it, the terminal returns an error and refuses to proceed. This guide covers every practical variation of the command.

    cp Command Syntax for Copying a Directory in Linux

    The basic syntax for using cp to copy a directory on Linux is straightforward:

    cp [options] source_directory destination_directory

    The source_directory is the folder you want to copy. The destination_directory is where the copy should go. Both accept absolute paths (starting with /) or relative paths from your current location.

    If you’re new to navigating directories in the terminal, the Linux command line basics guide covers cd and ls — two commands you’ll use constantly alongside cp.

    How to Copy a Directory in Linux with cp -r

    To copy a directory and everything inside it — subdirectories, files, nested folders — add the -r or -R flag (both are equivalent). Without it, cp exits with: cp: omitting directory 'dirname'.

    cp -r /path/to/source_directory /path/to/destination/

    When the Destination Directory Does Not Exist

    If the destination path doesn’t exist yet, Linux creates it and copies the entire contents of the source directory into it.

    cp -r projects/ backup_projects/

    Here, backup_projects/ gets created and the contents of projects/ are placed directly inside it.

    When the Destination Directory Already Exists

    This is where behavior changes. If backup_projects/ already exists, the source directory itself — not just its contents — gets placed inside the destination.

    # Result: backup_projects/projects/ (source becomes a subdirectory)
    cp -r projects/ backup_projects/

    To copy only the contents and skip the parent folder, add a trailing slash to the source path:

    cp -r projects/. backup_projects/

    The trailing /. tells cp to copy the directory contents rather than the directory itself.

    How to Preserve File Attributes When Copying a Directory

    By default, cp assigns the current timestamp and the running user’s ownership to copied files. The original permissions, timestamps, and ownership are not retained unless you ask for it.

    The -p flag preserves mode, ownership, and timestamps:

    cp -rp /var/www/html/ /backup/html/

    For a complete archive copy — including symbolic links, permissions, and all file attributes — use -a (archive), which is shorthand for -dR --preserve=all:

    cp -a /var/www/html/ /backup/html/

    The -a flag is the safest choice when copying directories for backup. It ensures the destination is an exact replica, which matters when you’re working on a Chromebook and need to run Linux alongside Chrome OS with consistent file states across containers.

    Copying a Linux Directory Without Overwriting Existing Files

    The cp command overwrites destination files silently by default. Two flags change this behavior.

    Use -n to skip files that already exist at the destination:

    cp -rn source_dir/ destination_dir/

    Use -i (interactive) to get a prompt before each overwrite:

    cp -ri source_dir/ destination_dir/

    The terminal asks overwrite 'filename'? for each conflict. Press y to overwrite, anything else to skip. This is particularly useful when merging two directories with overlapping file names.

    Note: When both -i and -n are passed together, the last one on the command line takes precedence.

    How to Copy Multiple Directories at Once with cp

    You can pass multiple source directories before the destination in a single cp command:

    cp -r dir1/ dir2/ dir3/ /destination/

    Each of the source directories gets copied into /destination/ as separate subdirectories. The destination must already exist when copying multiple sources.

    To monitor progress during large copies, the -v flag prints each file name as it’s copied:

    cp -rv source_dir/ destination_dir/

    This is particularly handy with large directory trees where the operation takes several seconds or longer. If you manage Linux on a Chromebook and want a smoother terminal experience, learning to customize the Linux Terminal app can make commands like these easier to work with.

    cp Command Options for Directory Copying on Linux

    cp Flag Usage — How Often Each Option Applies
    -r / -R
    Required for dirs
    Recursive copy (mandatory)
    -a
    Archive/backup
    Preserves all attributes
    -p
    Permissions copy
    Keeps mode, timestamps
    -n
    No overwrite
    Skips existing files
    -i
    Interactive
    Prompts before overwrite
    -v
    Verbose output
    Prints each filename
    -f
    Force
    Removes unwritable dest files
    Flag Full Name What It Does
    -r, -R –recursive Copies directories and all their contents recursively
    -a –archive Equivalent to -dR –preserve=all; ideal for backups
    -p –preserve Retains mode, ownership, and timestamps from source
    -n –no-clobber Does not overwrite any existing destination files
    -i –interactive Asks for confirmation before each overwrite
    -v –verbose Prints each file name as it is copied
    -f –force Forces the copy when destination files cannot be opened
    -u –update Copies only when source is newer than destination

    FAQs

    How do I copy a directory and all its contents in Linux?

    Use cp -r source_dir/ destination_dir/. The -r flag enables recursive copying, which includes all subdirectories and files inside the source directory.

    What is the difference between cp -r and cp -a on Linux?

    cp -r recursively copies files but does not preserve permissions or timestamps. cp -a does both, making it the right choice for backups where file attributes must be retained.

    Why does cp say “omitting directory” on Linux?

    The cp command requires the -r or -R flag to copy directories. Without it, the command refuses to process directories and prints the “omitting directory” error.

    How do I copy a folder in Linux without overwriting files?

    Add the -n flag: cp -rn source/ destination/. This skips any files that already exist at the destination, leaving them untouched.

    Can I copy a directory to another location with a different name in Linux?

    Yes. Specify the new name in the destination path: cp -r old_name/ /path/to/new_name/. If the destination path doesn’t exist, Linux creates it with that name.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr
    Dominic Reigns
    • Website
    • Instagram

    As a senior analyst, I benchmark and review gadgets and PC components, including desktop processors, GPUs, monitors, and storage solutions on Aboutchromebooks.com. Outside of work, I enjoy skating and putting my culinary training to use by cooking for friends.

    Related Posts

    How to Restart NGINX on Your Linux Server

    January 30, 2026

    How To Install NPM Linux

    January 26, 2026

    How To Check Linux List Processes

    January 24, 2026

    Comments are closed.

    Best of AI

    Pephop AI Statistics And Trends 2026

    February 26, 2026

    Gramhir AI Statistics 2026

    February 24, 2026

    Poe AI Statistics 2026

    February 21, 2026

    Joyland AI Statistics And User Trends 2026

    February 21, 2026

    Figgs AI Statistics 2026

    February 19, 2026
    Trending Stats

    Chrome Incognito Mode Statistics 2026

    February 10, 2026

    Google Penalty Recovery Statistics 2026

    January 30, 2026

    Search engine operators Statistics 2026

    January 29, 2026

    Most searched keywords on Google

    January 27, 2026

    Ahrefs Search Engine Statistics 2026

    January 19, 2026
    • About
    • Tech Guest Post
    • Contact
    • Privacy Policy
    • Sitemap
    © 2026 About Chrome Books. All rights reserved.

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