ā¹ļø Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 1.2 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.redhat.com/en/blog/move-copy-files-linux |
| Last Crawled | 2026-03-11 19:40:12 (1 month ago) |
| First Indexed | 2024-10-28 07:20:18 (1 year ago) |
| HTTP Status Code | 200 |
| Meta Title | Linux fundamentals: How to copy, move, and rename files and directories |
| Meta Description | Copying, moving, and renaming files and directories are standard tasks for sysadmins and end users. Depending on your Linux distribution, you can accompl... |
| Meta Canonical | null |
| Boilerpipe Text | Copying, moving, and renaming files and directories are standard tasks for sysadmins and end users. Depending on your Linux distribution, you can accomplish these operations in various ways.
The
Bash shell
is usually the most efficient tool for file management. This article assumes you already have a basic understanding of how to open a Linux terminal and enter commands. (SeeĀ
How to access the Linux terminal
if you want a refresher.)Ā Connect to your Linux terminal with your regular user account, and get ready to reorganize.
Change to your home directory and
create a new directory
named
mydir
for the exercises. The command to create a new directory is
mkdir
:
$ mkdir mydir
$ cd mydir/
Move files and directories
The
mv
command moves both directories and files. Check its options and parameters from the
--help
results below:
$ mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
or: mv [OPTION]... SOURCE... DIRECTORY
or: mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
-f, --force do not prompt before overwriting
-i, --interactive prompt before overwrite
-n, --no-clobber do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-S, --suffix=SUFFIX override the usual backup suffix
-t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
-T, --no-target-directory treat DEST as a normal file
-u, --update move only when the SOURCE file is newer
than the destination file or when the
destination file is missing
-v, --verbose explain what is being done
-Z, --context set SELinux security context of destination
file to default type
--help display this help and exit
--version output version information and exit
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:
none, off never make backups (even if --backup is given)
numbered, t make numbered backups
existing, nil numbered if numbered backups exist, simple otherwise
simple, never always make simple backups
Rename files and directories
You also use the
mv
command to rename directories and files if the destination doesn't already exist. If the destination exists, then they're moved using the syntax
mv {source} {destination}
. Here is an example of moving existing files to existing directories:
$ ls -l
total 0
drwxrwxr-x. 2 localuser localuser 6 Jun 9 14:57 dir1
drwxrwxr-x. 2 localuser localuser 6 Jun 9 17:52 dir2
drwxrwxr-x. 2 localuser localuser 6 Jun 9 17:52 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:31 file1
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file2
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file3
$ mv file1 dir1/
$ mv file2 dir2/
$ mv file3 dir3/
$ ls -l
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir1
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir2
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
[mydir]$ ls -lR
.:
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir1
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir2
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
./dir1:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:31 file1
./dir2:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file2
./dir3:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file3
./dir4:
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:35 subdir1
./dir4/subdir1:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:35 file4
[ Boost your Bash skills. Download theĀ
Bash shell scripting cheat sheet
. ]
And you can use the
mv
command to move directories into other directories:
$ ls -1
dir1
dir2
dir3
dir4
$ mv dir1/ dir2/
$ mv dir2/ dir3/
$ ls -1
dir3
dir4
The
dir1
and
dir2
directories still exist; you've just moved them. See what it looks like for yourself:
$ ls -R
dir3
dir4
./dir3:
dir2
file3
./dir3/dir2:
dir1
file2
./dir3/dir2/dir1:
file1
./dir4:
subdir1
./dir4/subdir1:
file4
Copy files and directories
The
cp
command copies both files and directories. This command has many options, but the basic syntax is simple. Run
cp {source} {destination}
to copy from one place (source) to another (destination). Consider the following example:
$ ls -1
dir3
dir4
$ cp dir4/subdir1/file4 .
$ ls -1
dir3
dir4
file4
$ ls -R dir4/
dir4/:
subdir1
dir4/subdir1:
file4
[ Download the freeĀ
Linux commands cheat sheet
. ]
To copy an entire directory with its contents, use the
-R
option, as seen below:
$ cp -R dir3/ dir4/
$ ls -R
dir3
dir4
file4
./dir3:
total 0
dir2
file3
./dir3/dir2:
dir1
file2
./dir3/dir2/dir1:
file1
./dir4:
dir3
subdir1
./dir4/dir3:
dir2
file3
./dir4/dir3/dir2:
file2
./dir4/dir3/dir2/dir1:
file1
./dir4/subdir1:
file4
When you copy empty directories into other directories, there's no need for the
-R
parameter.
More to explore
For each command I've demonstrated, there are many more options I've left out for the sake of brevity.
As a sysadmin, you must know how to copy, move, and rename files and directories. These file-management commands are the basis of much of what you do on the system and are the building blocks for effective Linux administration. I hope this article aids you in understanding this topic, helps your Linux certification path, and adds to your general sysadmin knowledge. |
| Markdown | [Skip to content](https://www.redhat.com/en/blog/move-copy-files-linux#rhdc-main-content)
## Navigation
Menu
AI
- ### Overview
- [AI news](https://www.redhat.com/en/blog/channel/artificial-intelligence)
- [Technical blog](https://developers.redhat.com/blog?field_tax_product_target_id%5B37288%5D=37288&extIdCarryOver=true&intcmp=7013a000003Sl59AAC&sc_cid=RHCTG0250000454096&_gl=1%2A1jal9i8%2A_gcl_au%2ANjU2NDY1NTAwLjE3NjQ2MTY4NTU.&percmp=RHCTG0250000466729)
- [Live AI events](https://www.redhat.com/en/events/ai)
- [Inference explained](https://www.redhat.com/en/ai/inference/what-you-should-know-about-inference)
- [See our approach](https://www.redhat.com/en/artificial-intelligence)
- ### Products
- [Red Hat AI Enterprise](https://www.redhat.com/en/products/ai/enterprise)
- [Red Hat AI Inference Server](https://www.redhat.com/en/products/ai/inference-server)
- [Red Hat Enterprise Linux AI](https://www.redhat.com/en/products/ai/enterprise-linux-ai)
- [Red Hat OpenShift AI](https://www.redhat.com/en/products/ai/openshift-ai)
- [Explore Red Hat AI](https://www.redhat.com/en/products/ai)
- ### Engage & learn
- [Learning hub](http://docs.redhat.com/en/learn/ai)
- [AI topics](https://www.redhat.com/en/topics/ai)
- [AI partners](https://catalog.redhat.com/categories/ai#ai-partners)
- [Services for AI](https://www.redhat.com/en/services/consulting/red-hat-consulting-for-ai)
Hybrid cloud
- ### Platform solutions
- [Artificial intelligence](https://www.redhat.com/en/hybrid-cloud-solutions/ai)
Build, deploy, and monitor AI models and apps.
- [Linux standardization](https://www.redhat.com/en/hybrid-cloud-solutions/linux-standardization)
Get consistency across operating environments.
- [Application development](https://www.redhat.com/en/hybrid-cloud-solutions/application-development)
Simplify the way you build, deploy, and manage apps.
- [Automation](https://www.redhat.com/en/hybrid-cloud-solutions/automation)
Scale automation and unite tech, teams, and environments.
- ### Use cases
- [Virtualization](https://www.redhat.com/en/hybrid-cloud-solutions/virtualization)
Modernize operations for virtualized and containerized workloads.
- [Digital sovereignty](https://www.redhat.com/en/products/digital-sovereignty)
Control and protect critical infrastructure.
- [Security](https://www.redhat.com/en/solutions/trusted-software-supply-chain)
Code, build, deploy, and monitor security-focused software.
- [Edge computing](https://www.redhat.com/en/products/edge)
Deploy workloads closer to the source with edge technology.
- [Explore solutions](https://www.redhat.com/en/hybrid-cloud-solutions)
- ### Solutions by industry
- [Automotive](https://www.redhat.com/en/solutions/automotive)
- [Financial services](https://www.redhat.com/en/solutions/financial-services)
- [Healthcare](https://www.redhat.com/en/solutions/healthcare)
- [Industrial sector](https://www.redhat.com/en/solutions/industrial-sector)
- [Media and entertainment](https://www.redhat.com/en/solutions/media-entertainment)
- [Public sector (Global)](https://www.redhat.com/en/solutions/public-sector)
- [Public sector (U.S.)](https://www.redhat.com/en/solutions/public-sector/us)
- [Telecommunications](https://www.redhat.com/en/solutions/telecommunications)
### [Discover cloud technologies](https://www.redhat.com/en/hybrid-cloud-console)
Learn how to use our cloud products and solutions at your own pace in the Red HatĀ® Hybrid Cloud Console.
Products
- ### Platforms
- [Red Hat AI](https://www.redhat.com/en/products/ai)
Develop and deploy AI solutions across the hybrid cloud.
- [Red Hat Enterprise Linux](https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux)
Support hybrid cloud innovation on a flexible operating system.
- [Red Hat OpenShift](https://www.redhat.com/en/technologies/cloud-computing/openshift)
Build, modernize, and deploy apps at scale.
- [Red Hat Ansible Automation Platform](https://www.redhat.com/en/technologies/management/ansible)
Implement enterprise-wide automation.
- ### Featured
- [Red Hat OpenShift Virtualization Engine](https://www.redhat.com/en/technologies/cloud-computing/openshift/virtualization-engine)
- [Red Hat OpenShift Service on AWS](https://www.redhat.com/en/technologies/cloud-computing/openshift/aws)
- [Microsoft Azure Red Hat OpenShift](https://www.redhat.com/en/technologies/cloud-computing/openshift/azure)
- [See all products](https://www.redhat.com/en/technologies/all-products)
- ### Try & buy
- [Start a trial](https://www.redhat.com/en/products/trials)
- [Buy online](https://www.redhat.com/en/store)
- [Integrate with major cloud providers](https://www.redhat.com/en/partners/certified-cloud-and-service-providers)
- ### Services & support
- [Consulting](https://www.redhat.com/en/services/consulting)
- [Product support](https://www.redhat.com/en/services/support)
- [Services for AI](https://www.redhat.com/en/services/consulting/red-hat-consulting-for-ai)
- [Technical Account Management](https://www.redhat.com/en/services/support/technical-account-management)
- [Explore services](https://www.redhat.com/en/services)
Training
- ### Training & certification
- [Courses and exams](https://www.redhat.com/en/services/training/all-courses-exams)
- [Certifications](https://www.redhat.com/en/services/certifications)
- [Skills assessments](https://skills.ole.redhat.com/en)
- [Red Hat Academy](https://www.redhat.com/en/services/training/red-hat-academy)
- [Learning subscription](https://www.redhat.com/en/services/training/learning-subscription)
- [Explore training](https://www.redhat.com/en/services/training-and-certification)
- ### Featured
- [Red Hat Certified System Administrator exam](https://www.redhat.com/en/services/training/ex200-red-hat-certified-system-administrator-rhcsa-exam)
- [Red Hat System Administration I](https://www.redhat.com/en/services/training/rh124-red-hat-system-administration-i)
- [Red Hat Learning Subscription trial (No cost)](https://www.redhat.com/en/services/training/learning-subscription/trial)
- [Red Hat Certified Engineer exam](https://www.redhat.com/en/services/training/ex294-red-hat-certified-engineer-rhce-exam-red-hat-enterprise-linux)
- [Red Hat Certified OpenShift Administrator exam](https://www.redhat.com/en/services/training/red-hat-certified-openshift-administrator-exam)
- ### Services
- [Consulting](https://www.redhat.com/en/services/consulting)
- [Partner training](https://connect.redhat.com/en/training)
- [Product support](https://www.redhat.com/en/services/support)
- [Services for AI](https://www.redhat.com/en/services/consulting/red-hat-consulting-for-ai)
- [Technical Account Management](https://www.redhat.com/en/services/support/technical-account-management)
Learn
- ### Build your skills
- [Documentation](https://docs.redhat.com/en)
- [Hands-on labs](https://www.redhat.com/en/interactive-labs)
- [Hybrid cloud learning hub](https://cloud.redhat.com/learn)
- [Interactive learning experiences](https://www.redhat.com/en/interactive-experiences)
- [Training and certification](https://www.redhat.com/en/services/training-and-certification)
- ### More ways to learn
- [Blog](https://www.redhat.com/en/blog)
- [Events and webinars](https://www.redhat.com/en/events)
- [Podcasts and video series](https://www.redhat.com/en/red-hat-original-series)
- [Red Hat TV](https://tv.redhat.com/)
- [Resource library](https://www.redhat.com/en/resources)
### [For developers](https://developers.redhat.com/)
Discover resources and tools to help you build, deliver, and manage cloud-native applications and services.
Partners
- ### For customers
- [Our partners](https://www.redhat.com/en/partners)
- [Red Hat Ecosystem Catalog](https://catalog.redhat.com/)
- [Find a partner](https://catalog.redhat.com/partners)
- ### For partners
- [Partner Connect](https://connect.redhat.com/)
- [Become a partner](https://connect.redhat.com/en/benefits-of-being-a-partner)
- [Training](https://connect.redhat.com/en/training)
- [Support](https://connect.redhat.com/en/support)
- [Access the partner portal](https://connect.redhat.com/partner-admin/dashboard)
### [Build solutions powered by trusted partners](https://catalog.redhat.com/en/solutions)
Find solutions from our collaborative community of experts and technologies in the Red HatĀ® Ecosystem Catalog.
Search
### I'd like to:
- [Start a trial](https://www.redhat.com/en/products/trials)
- [Buy a learning subscription](https://www.redhat.com/en/services/training/learning-subscription/how-to-buy)
- [Manage subscriptions](https://access.redhat.com/management)
- [Contact sales](https://www.redhat.com/en/contact)
- [Contact customer service](https://www.redhat.com/en/contact/customer-service)
- [See Red Hat jobs](https://www.redhat.com/en/jobs)
### Help me find:
- [Documentation](https://docs.redhat.com/en)
- [Developer resources](https://developers.redhat.com/)
- [Tech topics](https://www.redhat.com/en/topics)
- [Architecture center](https://www.redhat.com/architect/portfolio/)
- [Security updates](https://access.redhat.com/security/security-updates/cve)
- [Customer support](https://access.redhat.com/support)
### I want to learn more about:
- [AI](https://www.redhat.com/en/topics/ai)
- [Application modernization](https://www.redhat.com/en/topics/application-modernization)
- [Automation](https://www.redhat.com/en/topics/automation)
- [Cloud-native applications](https://www.redhat.com/en/topics/cloud-native-apps)
- [Linux](https://www.redhat.com/en/topics/linux)
- [Virtualization](https://www.redhat.com/en/topics/virtualization)
[Console](https://www.redhat.com/en/hybrid-cloud-console)
[Docs](https://docs.redhat.com/en)
[Support](https://access.redhat.com/)
New For you
### Recommended
We'll recommend resources you may like as you browse. Try these suggestions for now.
- [Product trial center](https://www.redhat.com/en/products/trials)
- [Courses and exams](https://www.redhat.com/en/services/training/all-courses-exams)
- [All products](https://www.redhat.com/en/technologies/all-products)
- [Tech topics](https://www.redhat.com/en/topics)
- [Resource library](https://www.redhat.com/en/resources)
Log in
### Get more with a Red Hat account
- Console access
- Event registration
- Training & trials
- World-class support
A subscription may be required for some services.
[Log in or register](https://sso.redhat.com/)
Change page language
[Contact us](https://www.redhat.com/en/contact)
### \[\[name\]\]
[Edit avatar](https://access.redhat.com/user/edit)
Login: \[\[login\]\]
Account number: \[\[account\_number\]\]
\[\[email\]\]
Change page language
Log out
[Red Hat Blog](https://www.redhat.com/en/blog)
- [By product]()
- [Red Hat AI](https://www.redhat.com/en/blog/channel/red-hat-ai "Red Hat AI")
- [Red Hat Ansible Automation Platform](https://www.redhat.com/en/blog/channel/red-hat-ansible-automation "Red Hat Ansible Automation Platform")
- [Red Hat Enterprise Linux](https://www.redhat.com/en/blog/channel/red-hat-enterprise-linux "Red Hat Enterprise Linux")
- [Red Hat OpenShift](https://www.redhat.com/en/blog/channel/red-hat-openshift "Red Hat OpenShift")
***
[More products](https://www.redhat.com/en/blog/products "More products")
- [By topic]()
- [AI](https://www.redhat.com/en/blog/channel/artificial-intelligence "AI")
- [Virtualization](https://www.redhat.com/en/blog/channel/red-hat-virtualization "Virtualization")
- [Digital sovereignty](https://www.redhat.com/en/blog/channel/digital-sovereignty "Digital sovereignty")
- [Applications](https://www.redhat.com/en/blog/channel/applications "Applications")
- [Automation](https://www.redhat.com/en/blog/channel/management-and-automation "Automation")
- [Cloud services](https://www.redhat.com/en/blog/channel/cloud-services "Cloud services")
- [Edge computing](https://www.redhat.com/en/blog/channel/edge-computing "Edge computing")
- [Infrastructure](https://www.redhat.com/en/blog/channel/infrastructure "Infrastructure")
- [Open hybrid cloud](https://www.redhat.com/en/blog/channel/hybrid-cloud-infrastructure "Open hybrid cloud")
- [Original shows](https://www.redhat.com/en/red-hat-original-series "Original shows")
- [Security](https://www.redhat.com/en/blog/channel/security "Security")
***
[All topics](https://www.redhat.com/en/blog/channels "All topics")
- [Podcasts]()
- [Technically Speaking with Chris Wright](https://www.redhat.com/en/technically-speaking "Technically Speaking with Chris Wright")
- [Code Comments](https://www.redhat.com/en/code-comments-podcast "Code Comments")
- [Command Line Heroes](https://www.redhat.com/en/command-line-heroes "Command Line Heroes")
- [Compiler](https://www.redhat.com/en/compiler-podcast "Compiler")
- [More blogs]()
- [Red Hat Developer blog](https://developers.redhat.com/blog "Red Hat Developer blog")
- [Red Hat Partner Connect blog](https://connect.redhat.com/en/blog "Red Hat Partner Connect blog")
# Linux fundamentals: How to copy, move, and rename files and directories
July 21, 2022[Alexon Oliveira](https://www.redhat.com/en/authors/alexon-oliveira "See more by Alexon Oliveira")*5*\-minute read
[Linux](https://www.redhat.com/en/blog?f[0]=taxonomy_topic_tid:27061#rhdc-search-listing)
[Application development and delivery](https://www.redhat.com/en/blog?f[0]=taxonomy_topic_tid:27031#rhdc-search-listing)
Share
Subscribe to RSS
- [Back to all posts](https://www.redhat.com/en/blog)
***
Copying, moving, and renaming files and directories are standard tasks for sysadmins and end users. Depending on your Linux distribution, you can accomplish these operations in various ways.
The [Bash shell](https://www.redhat.com/sysadmin/bash-navigation) is usually the most efficient tool for file management. This article assumes you already have a basic understanding of how to open a Linux terminal and enter commands. (See [How to access the Linux terminal](https://www.redhat.com/sysadmin/access-linux-terminal) if you want a refresher.) Connect to your Linux terminal with your regular user account, and get ready to reorganize.
Change to your home directory and [create a new directory](https://www.redhat.com/node/6007) named `mydir` for the exercises. The command to create a new directory is `mkdir`:
```
$ mkdir mydir
$ cd mydir/
```
## Move files and directories
The `mv` command moves both directories and files. Check its options and parameters from the `--help` results below:
```
$ mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
or: mv [OPTION]... SOURCE... DIRECTORY
or: mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
-f, --force do not prompt before overwriting
-i, --interactive prompt before overwrite
-n, --no-clobber do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-S, --suffix=SUFFIX override the usual backup suffix
-t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
-T, --no-target-directory treat DEST as a normal file
-u, --update move only when the SOURCE file is newer
than the destination file or when the
destination file is missing
-v, --verbose explain what is being done
-Z, --context set SELinux security context of destination
file to default type
--help display this help and exit
--version output version information and exit
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:
none, off never make backups (even if --backup is given)
numbered, t make numbered backups
existing, nil numbered if numbered backups exist, simple otherwise
simple, never always make simple backups
```
## Rename files and directories
You also use the `mv` command to rename directories and files if the destination doesn't already exist. If the destination exists, then they're moved using the syntax `mv {source} {destination}`. Here is an example of moving existing files to existing directories:
```
$ ls -l
total 0
drwxrwxr-x. 2 localuser localuser 6 Jun 9 14:57 dir1
drwxrwxr-x. 2 localuser localuser 6 Jun 9 17:52 dir2
drwxrwxr-x. 2 localuser localuser 6 Jun 9 17:52 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:31 file1
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file2
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file3
$ mv file1 dir1/
$ mv file2 dir2/
$ mv file3 dir3/
$ ls -l
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir1
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir2
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
[mydir]$ ls -lR
.:
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir1
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir2
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
./dir1:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:31 file1
./dir2:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file2
./dir3:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file3
./dir4:
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:35 subdir1
./dir4/subdir1:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:35 file4
```
***\[ Boost your Bash skills. Download the [Bash shell scripting cheat sheet](https://developers.redhat.com/cheat-sheets/bash-shell-cheat-sheet?intcmp=701f20000012ngPAAQ). \]***
And you can use the `mv` command to move directories into other directories:
```
$ ls -1
dir1
dir2
dir3
dir4
$ mv dir1/ dir2/
$ mv dir2/ dir3/
$ ls -1
dir3
dir4
```
The `dir1` and `dir2` directories still exist; you've just moved them. See what it looks like for yourself:
```
$ ls -R
dir3
dir4
./dir3:
dir2
file3
./dir3/dir2:
dir1
file2
./dir3/dir2/dir1:
file1
./dir4:
subdir1
./dir4/subdir1:
file4
```
## Copy files and directories
The `cp` command copies both files and directories. This command has many options, but the basic syntax is simple. Run `cp {source} {destination}` to copy from one place (source) to another (destination). Consider the following example:
```
$ ls -1
dir3
dir4
$ cp dir4/subdir1/file4 .
$ ls -1
dir3
dir4
file4
$ ls -R dir4/
dir4/:
subdir1
dir4/subdir1:
file4
```
***\[ Download the free [Linux commands cheat sheet](https://developers.redhat.com/cheat-sheets/linux-commands-cheat-sheet?intcmp=701f20000012ngPAAQ). \]***
To copy an entire directory with its contents, use the `-R` option, as seen below:
```
$ cp -R dir3/ dir4/
$ ls -R
dir3
dir4
file4
./dir3:
total 0
dir2
file3
./dir3/dir2:
dir1
file2
./dir3/dir2/dir1:
file1
./dir4:
dir3
subdir1
./dir4/dir3:
dir2
file3
./dir4/dir3/dir2:
file2
./dir4/dir3/dir2/dir1:
file1
./dir4/subdir1:
file4
```
When you copy empty directories into other directories, there's no need for the `-R` parameter.
## More to explore
For each command I've demonstrated, there are many more options I've left out for the sake of brevity.
As a sysadmin, you must know how to copy, move, and rename files and directories. These file-management commands are the basis of much of what you do on the system and are the building blocks for effective Linux administration. I hope this article aids you in understanding this topic, helps your Linux certification path, and adds to your general sysadmin knowledge.
***
### About the author
[](https://www.redhat.com/en/authors/alexon-oliveira)
[Alexon Oliveira](https://www.redhat.com/en/authors/alexon-oliveira)
Alexon has been working as a Senior Technical Account Manager at Red Hat since 2018, working in the Customer Success organization focusing on Infrastructure and Management, Integration and Automation, Cloud Computing, and Storage Solutions. He is a part of the TAM Practices LATAM team based in SĆ£o Paulo, Brazil, where his job is partnering with, advocating, trust-advising, and supporting customers in their success goals while making use of the complete portfolio. He also contributes to produce and enhance documentation, knowledge-base articles, blog posts, presentations, webinars, and workshops. He is a member of numerous communities in addition to the Sudoers, like Red Hat Academy and Red Hat Accelerators. When heās not at work, he enjoys spending quality time with his family (wife, daughter, and cat) and participating in several volunteer jobs.
[Read full bio](https://www.redhat.com/en/authors/alexon-oliveira)
## More like this
Blog post
### [More than meets the eye: Behind the scenes of Red Hat Enterprise Linux 10 (Part 6)](https://www.redhat.com/en/blog/more-meets-eye-behind-scenes-red-hat-enterprise-linux-10-part-6)
Blog post
### [Metrics that matter: How to prove the business value of DevEx](https://www.redhat.com/en/blog/metrics-matter-how-prove-business-value-devex)
Original podcast
### [OS Wars\_part 2: Rise of Linux \| Command Line Heroes](https://www.redhat.com/en/command-line-heroes/season-1/os-wars-part-2-rise-of-linux)
Original podcast
### [Where Coders Code \| Command Line Heroes](https://www.redhat.com/en/command-line-heroes/season-5/where-coders-code)
## Browse by channel
[Explore all channels](https://www.redhat.com/en/blog/channels "Explore all channels")

### [Automation](https://www.redhat.com/en/blog/channel/management-and-automation)
The latest on IT automation for tech, teams, and environments

### [Artificial intelligence](https://www.redhat.com/en/blog/channel/artificial-intelligence)
Updates on the platforms that free customers to run AI workloads anywhere

### [Open hybrid cloud](https://www.redhat.com/en/blog/channel/hybrid-cloud-infrastructure)
Explore how we build a more flexible future with hybrid cloud

### [Security](https://www.redhat.com/en/blog/channel/security)
The latest on how we reduce risks across environments and technologies

### [Edge computing](https://www.redhat.com/en/blog/channel/edge-computing)
Updates on the platforms that simplify operations at the edge

### [Infrastructure](https://www.redhat.com/en/blog/channel/infrastructure)
The latest on the worldās leading enterprise Linux platform

### [Applications](https://www.redhat.com/en/blog/channel/applications)
Inside our solutions to the toughest application challenges

### [Virtualization](https://www.redhat.com/en/blog/channel/red-hat-virtualization)
The future of enterprise virtualization for your workloads on-premise or across clouds
[](https://www.redhat.com/en)
[LinkedIn](https://www.linkedin.com/company/red-hat)
[YouTube](https://www.youtube.com/user/RedHatVideos)
[Facebook](https://www.facebook.com/RedHat/)
[X](https://twitter.com/RedHat)
### Platforms
- [Red Hat AI](https://www.redhat.com/en/products/ai)
- [Red Hat Enterprise Linux](https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux)
- [Red Hat OpenShift](https://www.redhat.com/en/technologies/cloud-computing/openshift)
- [Red Hat Ansible Automation Platform](https://www.redhat.com/en/technologies/management/ansible)
- [See all products](https://www.redhat.com/en/technologies/all-products)
### Tools
- [Training and certification](https://www.redhat.com/en/services/training-and-certification)
- [My account](https://www.redhat.com/wapps/ugc/protected/personalInfo.html)
- [Customer support](https://access.redhat.com/)
- [Developer resources](https://developers.redhat.com/)
- [Find a partner](https://catalog.redhat.com/partners)
- [Red Hat Ecosystem Catalog](https://catalog.redhat.com/)
- [Documentation](https://docs.redhat.com/en)
### Try, buy, & sell
- [Product trial center](https://www.redhat.com/en/products/trials)
- [Red Hat Store](https://www.redhat.com/en/store)
- [Buy online (Japan)](https://www.redhat.com/en/about/japan-buy)
- [Console](https://www.redhat.com/en/hybrid-cloud-console)
### Communicate
- [Contact sales](https://www.redhat.com/en/contact/sales)
- [Contact customer service](https://www.redhat.com/en/contact/customer-service)
- [Contact training](https://www.redhat.com/en/services/training-and-certification/contact-us)
- [Social](https://www.redhat.com/en/about/social)
### About Red Hat
Red Hat is an open hybrid cloud technology leader, delivering a consistent, comprehensive foundation for transformative IT and artificial intelligence (AI) applications in the enterprise. As a [trusted adviser to the Fortune 500](https://www.redhat.com/en/about/company), Red Hat offers cloud, developer, Linux, automation, and application platform technologies, as well as [award-winning](https://access.redhat.com/recognition) services.
- [Our company](https://www.redhat.com/en/about/company)
- [How we work](https://www.redhat.com/en/about/our-culture)
- [Customer success stories](https://www.redhat.com/en/success-stories)
- [Analyst relations](https://www.redhat.com/en/about/analysts)
- [Newsroom](https://www.redhat.com/en/about/newsroom)
- [Open source commitments](https://www.redhat.com/en/about/open-source)
- [Our social impact](https://www.redhat.com/en/about/community-social-responsibility)
- [Jobs](https://www.redhat.com/en/jobs)
### Change page language
### Red Hat legal and privacy links
- [About Red Hat](https://www.redhat.com/en/about/company)
- [Jobs](https://www.redhat.com/en/jobs)
- [Events](https://www.redhat.com/en/events)
- [Locations](https://www.redhat.com/en/about/office-locations)
- [Contact Red Hat](https://www.redhat.com/en/contact)
- [Red Hat Blog](https://www.redhat.com/en/blog)
- [Inclusion at Red Hat](https://www.redhat.com/en/about/our-culture/inclusion)
- [Cool Stuff Store](https://coolstuff.redhat.com/)
- [Red Hat Summit](https://www.redhat.com/en/summit)
Ā© 2026 Red Hat
### Red Hat legal and privacy links
- [Privacy statement](https://www.redhat.com/en/about/privacy-policy)
- [Terms of use](https://www.redhat.com/en/about/terms-use)
- [All policies and guidelines](https://www.redhat.com/en/about/all-policies-guidelines)
- [Digital accessibility](https://www.redhat.com/en/about/digital-accessibility) |
| Readable Markdown | Copying, moving, and renaming files and directories are standard tasks for sysadmins and end users. Depending on your Linux distribution, you can accomplish these operations in various ways.
The [Bash shell](https://www.redhat.com/sysadmin/bash-navigation) is usually the most efficient tool for file management. This article assumes you already have a basic understanding of how to open a Linux terminal and enter commands. (See [How to access the Linux terminal](https://www.redhat.com/sysadmin/access-linux-terminal) if you want a refresher.) Connect to your Linux terminal with your regular user account, and get ready to reorganize.
Change to your home directory and [create a new directory](https://www.redhat.com/node/6007) named `mydir` for the exercises. The command to create a new directory is `mkdir`:
```
$ mkdir mydir
$ cd mydir/
```
## Move files and directories
The `mv` command moves both directories and files. Check its options and parameters from the `--help` results below:
```
$ mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
or: mv [OPTION]... SOURCE... DIRECTORY
or: mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
-f, --force do not prompt before overwriting
-i, --interactive prompt before overwrite
-n, --no-clobber do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-S, --suffix=SUFFIX override the usual backup suffix
-t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
-T, --no-target-directory treat DEST as a normal file
-u, --update move only when the SOURCE file is newer
than the destination file or when the
destination file is missing
-v, --verbose explain what is being done
-Z, --context set SELinux security context of destination
file to default type
--help display this help and exit
--version output version information and exit
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:
none, off never make backups (even if --backup is given)
numbered, t make numbered backups
existing, nil numbered if numbered backups exist, simple otherwise
simple, never always make simple backups
```
## Rename files and directories
You also use the `mv` command to rename directories and files if the destination doesn't already exist. If the destination exists, then they're moved using the syntax `mv {source} {destination}`. Here is an example of moving existing files to existing directories:
```
$ ls -l
total 0
drwxrwxr-x. 2 localuser localuser 6 Jun 9 14:57 dir1
drwxrwxr-x. 2 localuser localuser 6 Jun 9 17:52 dir2
drwxrwxr-x. 2 localuser localuser 6 Jun 9 17:52 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:31 file1
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file2
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file3
$ mv file1 dir1/
$ mv file2 dir2/
$ mv file3 dir3/
$ ls -l
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir1
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir2
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
[mydir]$ ls -lR
.:
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir1
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir2
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:53 dir3
drwxrwxr-x. 3 localuser localuser 21 Jun 9 16:57 dir4
./dir1:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:31 file1
./dir2:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file2
./dir3:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:33 file3
./dir4:
total 0
drwxrwxr-x. 2 localuser localuser 19 Jun 9 17:35 subdir1
./dir4/subdir1:
total 0
-rw-rw-r--. 1 localuser localuser 0 Jun 9 17:35 file4
```
***\[ Boost your Bash skills. Download the [Bash shell scripting cheat sheet](https://developers.redhat.com/cheat-sheets/bash-shell-cheat-sheet?intcmp=701f20000012ngPAAQ). \]***
And you can use the `mv` command to move directories into other directories:
```
$ ls -1
dir1
dir2
dir3
dir4
$ mv dir1/ dir2/
$ mv dir2/ dir3/
$ ls -1
dir3
dir4
```
The `dir1` and `dir2` directories still exist; you've just moved them. See what it looks like for yourself:
```
$ ls -R
dir3
dir4
./dir3:
dir2
file3
./dir3/dir2:
dir1
file2
./dir3/dir2/dir1:
file1
./dir4:
subdir1
./dir4/subdir1:
file4
```
## Copy files and directories
The `cp` command copies both files and directories. This command has many options, but the basic syntax is simple. Run `cp {source} {destination}` to copy from one place (source) to another (destination). Consider the following example:
```
$ ls -1
dir3
dir4
$ cp dir4/subdir1/file4 .
$ ls -1
dir3
dir4
file4
$ ls -R dir4/
dir4/:
subdir1
dir4/subdir1:
file4
```
***\[ Download the free [Linux commands cheat sheet](https://developers.redhat.com/cheat-sheets/linux-commands-cheat-sheet?intcmp=701f20000012ngPAAQ). \]***
To copy an entire directory with its contents, use the `-R` option, as seen below:
```
$ cp -R dir3/ dir4/
$ ls -R
dir3
dir4
file4
./dir3:
total 0
dir2
file3
./dir3/dir2:
dir1
file2
./dir3/dir2/dir1:
file1
./dir4:
dir3
subdir1
./dir4/dir3:
dir2
file3
./dir4/dir3/dir2:
file2
./dir4/dir3/dir2/dir1:
file1
./dir4/subdir1:
file4
```
When you copy empty directories into other directories, there's no need for the `-R` parameter.
## More to explore
For each command I've demonstrated, there are many more options I've left out for the sake of brevity.
As a sysadmin, you must know how to copy, move, and rename files and directories. These file-management commands are the basis of much of what you do on the system and are the building blocks for effective Linux administration. I hope this article aids you in understanding this topic, helps your Linux certification path, and adds to your general sysadmin knowledge. |
| Shard | 14 (laksa) |
| Root Hash | 4780968593380432814 |
| Unparsed URL | com,redhat!www,/en/blog/move-copy-files-linux s443 |