Copying all directories while ignoring certain filetypes

I want to write a script that copys over a complete folder including the dirs to another
location.
However in the process I want to ignore several filetypse that SHOULD NOT get copied over.
I know Global Ignore is capable of make the copy command ignore one file type, however
I don't know how to get multiple file types ignored.

Thanks in advance for replys,

I appreciate it

Do you have specific extension to those file types?

--ahamed

yes, like for example .mp3, .mp4, .sav. etc....

they are fixed. just not sure how many I need yet. (might be 20+ file extensions needed to ignore)

May be you can give the extensions you need to consider for copy if that list is less

--ahamed

---------- Post updated at 09:42 AM ---------- Previous update was at 09:40 AM ----------

and how many level of sub directories do you have?

--ahamed

well, I have .smc, .psx .nes .gb .gbc .gba (rom homebrew files).
sublevels... I think 3 or 4 Max.

well, the extensions that have to be ignored are about less: 6 currently: smc gba gb gbc psx gen

Max sublevels: 3

You could use rsync

Just put list of exclude patterns in a file eg /tmp/nosync.txt

*.mp3
*.mp4
*.sav

Now run

rsync -axv --exclude-from=/tmp/nosync.txt --dry-run /source/top/dir /dest

If this looks like what you want to do remove the --dry-run option to actually do the copy.

To do a move instead of copy you can use --del and --prune-empty-dirs . There are heaps of other options that control how rsync works so check the manual for other options you man want to consider.

1 Like

assuming ignore list is created with ignore extensions on each line .. like suggested by Chubler_XL.. here is my take.. i directly writing here so there can be syntactical error.

$ cat CpCertailnFiles.sh 
#! /bin/bash
find . -type f | grep -v -f $HOME/Ignore.lst | xargs -iSourceFile cp SourceFile $1

$ CpCertailnFiles.sh <DESTINATION_DIR>

I am not sure if "grep -v" supports "-f" switch but it should .. if destination is fixed then you could hardcode the destination

Try :

  • Create ignore list in some other location than /tmp
  • Add some validation
  • run in debug mode if it doesnt work
1 Like

Awesome suggestions ! Especially, because if a new to be ignored extension is needed I just need to change the txt file. THANKS both of you :slight_smile:
Will try this ASAP.