mv with exclusion of FULL PATH ?
This is a simple structure of dirs and files where I want to present my problem:
Code:
/testing/backup/1.txt 1. move (mv) all content of /testing to /testing/tmp 2. exclude /testing/1.txt but /testing/backup/1.txt must be included. I was trying some tricks with FIND and exclusion like this -type f ! \( -name 1.txt\) but then it excluded both /testing/1.txt but /testing/backup/1.txt. It is also not possible to add to this exclusion full path. Does anyone have some smart idea how to do that move with full path exclusion ? Temporary my solution for this issue is rsync: Code:
rsync /testing/* -a --exclude /test/1.txt /testing/tmp |
Won't that get you /testing/tmp/tmp/tmp/tmp ...?
|
The switches to specify full path are -path and -wholename (less portable). I assume that you want to move the whole directory structure into tmp (except tmp itself) otherwise you will end up with some files overwritten by others with the same name (e.g. 2.txt). In this case you may use the option -maxdepth to limit the search to the first level of the directory tree.
Here is an example: Code:
$ find /testing -maxdepth 1 ! -path /testing/1.txt Code:
$ find /testing -mindepth 1 -maxdepth 1 ! -path /testing/1.txt ! -path /testing/tmp |
Hi, thank you for your answer. That worked perfectly and solved my problem, thanks :)
That is full command that I used. Code:
find /testing -mindepth 1 -maxdepth 1 ! -path /testing/1.txt ! -path /testing/tmp -exec mv {} /testing/tmp \ Eg. to skip file: /testing/backup/1.txt So, I modified command like this: Code:
find /testing -mindepth 1 -maxdepth 1 ! -path /testing/backup/1.txt ! -path /testing/tmp -exec mv {} /testing/tmp \; dir /testing/tmp has not been moved (thats good) but /testing/backup/1.txt has been moved. Why is that ?. UPDATE: and it is odd because by issuing this I have a good output: Code:
find /testing -mindepth 1 -maxdepth 2 ! -path /testing/backup/1.txt ! -path /testing/tmp UPDATE #2 I think I know why. Its probably because of this: Code:
find /testing -mindepth 1 -maxdepth 2 ! -path /testing/backup/1.txt ! -path /testing/tmp |
This is because from your output
Code:
/testing/2.txt Code:
rsync -av --dry-run --remove-source-files --exclude tmp --exclude backup/1.txt /testing/ /testing/tmp
|
Professor Colucix, your help is priceless. As always :)
Now I also better understand your explanation for -maxdepth Thank you. ps. I think it should be --remove-sent-files instead of --remove-source-files |
All times are GMT -5. The time now is 06:08 AM. |