# Exclude files when copying

**URL:** <https://community.learnlinux.tv/t/exclude-files-when-copying/3781>\
**Category:** Uncategorized\
**Created:** [April 8, 2024, 3:35pm UTC](https://community.learnlinux.tv/t/exclude-files-when-copying/3781 "2024-04-08T15:35:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Williamj48](https://community.learnlinux.tv/letter_avatar_proxy/v4/letter/w/e480ec/32.png) [@Williamj48](https://community.learnlinux.tv/u/Williamj48)\
**Post date:** [April 8, 2024, 3:35pm UTC](https://community.learnlinux.tv/t/exclude-files-when-copying/3781/1 "2024-04-08T15:35:13Z")

</div>

Is there a flag that I could set on a file so that it will not be copied? I have a lot of Virtual environments on my computer and it would be immensely helpful to flag a directory so that itself and its contents will not be copied due to the amount of files contained in the virtual environment. I regularly try to backup my computer through aliases in my .bashrc. I know that I could try exclude directories in the command line when using file copying utilities but that could become a little too arduous with the amount of virtual environments that I have.

---

<div class="post-metadata">

**Author:** ![ThatGuyB](https://community.learnlinux.tv/user_avatar/community.learnlinux.tv/thatguyb/32/784_2.png) [@ThatGuyB](https://community.learnlinux.tv/u/ThatGuyB)\
**Post date:** [April 8, 2024, 9:47pm UTC](https://community.learnlinux.tv/t/exclude-files-when-copying/3781/2 "2024-04-08T21:47:48Z")

</div>

Not with copy, but rsync has `--exclude` option.

```auto
rsync -varoglAX --exclude "/this/folder" --exclude "/that/folder" /back/this/up /target/location

```

---

<div class="post-metadata">

**Author:** ![marcoperson](https://community.learnlinux.tv/user_avatar/community.learnlinux.tv/marcoperson/32/1375_2.png) [@marcoperson](https://community.learnlinux.tv/u/marcoperson)\
**Post date:** [May 16, 2024, 2:09pm UTC](https://community.learnlinux.tv/t/exclude-files-when-copying/3781/3 "2024-05-16T14:09:58Z")

</div>

Hello @Williamj48

To prevent a file from being copied; you can set the no copy flag. One frequent approach is to use the chattr command on Linux systems;, which adds the i attribute to a file; making it unchanging,; means it cannot be edited;, deleted; or renamed.
