Rsync --delete option doesn't delete files in target directory
Solution 1
Use this command:
rsync --archive --verbose --compress --ignore-existing --delete /var/www/ [email protected]:/var/www
You do not need a "*" and should not use it too.
To exclude/include files or directories, you should use this parameters:
--exclude 'to_exclude*'
--include 'to_include*'
Solution 2
Your command was not working because when you were using /var/www/*
as the source, your shell is performing globbing on it i.e. shell is expanding *
to all files in that directory and the copying the files one by one, so here individual files have become the sources rather than the parent directory.
So, if you use /var/www/*
, then you don't need --recursive
option as *
will causes the files to be copied (along with any directories with their contents), not the parent directory that contains the files. Because of the same reason --delete
is not working, as --delete
will remove files from destination directory that are not in the source directory, but you are copying files so its not removing files (expectedly).
This will make you more clear:
/foo$ ls -l
-rw-rw-r-- 1 user user 0 Apr 16 17:56 egg
-rw-rw-r-- 1 user user 0 Apr 16 17:56 spam
drwxrwxr-x 2 user user 4096 Apr 16 18:14 test
/bar$ ls -l
-rw-rw-r-- 1 user user 0 Apr 16 17:56 egg
-rw-rw-r-- 1 user user 0 Apr 16 18:13 lion
-rw-rw-r-- 1 user user 0 Apr 16 17:56 spam
$ rsync -avz --ignore-existing --recursive --delete
/foo/* /bar/
+ rsync -avz --ignore-existing --recursive --delete
/foo/egg /foo/spam /foo/test /bar/
sending incremental file list
test/
test/hello
sent 173 bytes received 39 bytes 424.00 bytes/sec
total size is 0 speedup is 0.00
/bar$ ls -l
-rw-rw-r-- 1 user user 0 Apr 16 17:56 egg
-rw-rw-r-- 1 user user 0 Apr 16 18:13 lion
-rw-rw-r-- 1 user user 0 Apr 16 17:56 spam
drwxrwxr-x 2 user user 4096 Apr 16 18:14 test
As you can see, i have used the source as /foo/*
hence the rsync
command being executed is
rsync -avz --ignore-existing --recursive --delete /foo/egg
/foo/spam /foo/test /bar/
with *
making shell to expand it and make all files individually as source arguments, not the parent directory as a whole (and you also don't need --recursive
in this case).
So, if you want to make --delete
work, run it as:
rsync -avz --ignore-existing --recursive --delete
/var/www/ [email protected]:/var/www/
Related videos on Youtube
lecham
Updated on September 18, 2022Comments
-
lecham over 1 year
Let's image I have a long text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
I've entered letter
s
and a lot of letters of these text got highlighted. I want to slice it and show highlighted letters.I use
react-native-highlight-words
to highlight the words. https://www.npmjs.com/package/react-native-highlight-wordsIn docs there's a sanitize method, but I'm not sure how can it be used?
Sanitize - Process each search word and text to highlight before comparing (eg remove accents); signature (text: string): string
Here's the example:
Here's a piece of my code:
<Highlighter highlightStyle={{ backgroundColor: 'yellow'}} searchWords={[searchWords]} textToHighlight={description} />
What's the best approach to achieve it?
-
keikai about 4 yearsAny code you have achieved?
-
lecham about 4 years@keikai Just attached
-
Cameron Little about 4 yearsIt doesn't look like that library supports anything more than the behavior you've described it already doing. Sanitize looks like it does the opposite of what you're looking for - it processes highlighted text, not the other stuff you want to remove.
-
Sparkler about 3 yearsinstead of
/var/www/*
all you need to do is/var/www/.
-
-
user2028856 about 9 yearsOkay let me try this :)
-
user2028856 about 9 yearsSo is the "*" that's causing the the --delete command not working?
-
A.B. about 9 yearsThat's how it looks. :)
-
A.B. about 9 years@user2028856 If you are satisfied with my answer, then click on the gray checkmark on the left side of the answer and give me an upvote. ;)
-
don.joey about 9 yearsAsking for internet points, A.B? Here: have some.
-
Temak almost 8 years
--recursive
is overabundant because option-a
already includes it -
Antonio Bardazzi almost 8 yearsExcellent explanation pointing out the real issue: using '*' to expand the source list.
-
sootsnoot over 7 yearsThe "*" could be important in some cases because it excludes files/directories that begin with ".". For example I use it when using rsync to copy a directory maintained under git from a development machine to a production machine. I don't want to sync the .git repository directory, or files like .gitignore, just the working tree,including files at the top-level as well as subdirectories.
-
sootsnoot over 7 yearsAs noted in my comment on the accepted answer, the * can be useful to exclude things like files and directories beginning with ".". Though as you note, this means files and directories removed from the top level in the source won't be removed from the destination directory. For myself, I don't care whether top-level files get properly deleted from the destination, only files below subdirectories matter. Removing a top-level subdirectory is far less likely than adding one, and I'm willing to do a manual rm -r on the destination in that unlikely case.
-
lecham about 4 yearsWow, looks good! Thanks! Just one question, is it possible to pull out not the words, but phrases? In your example: ...psum dolor sit amet, consectetur adipiscing elit... or smth like this..
-
Pramod about 4 yearsyou will have to write your own regex for it
-
lecham about 4 yearsDo you have any examples of similar RegExp?
-
Pramod about 4 yearsyou will have to write in accordance with your expected result. I can only give a try as i don't know what exactly you want. Give example of words and what u want to pull from it
-
lecham about 4 yearsSo, I want to display a few highlighted words + a few nearby words. ``` Example: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat Output: consectetur adipiscing elit, sed do eiusmod tempor incididunt ``` The input string contains a lot of highlighted letters and I don't want to display them all to a user, I need to output just a sentence, containing some words with letters highlighted. Hope this will help!
-
Pramod about 4 yearsI think you won't require regex. You can use split and find indexOf Working Example: snack.expo.io/@msbot01/bad-watermelon
-
lecham about 4 yearsThanks, but in case there are duplicated words the algorithm isn't working as expected: snack.expo.io/HWIM!8sgO In such case I want to display just 1 sentence with this word: The Rodrigues starling (Necropsar rodericanus) is an extinct species of starling that was endemic to the Mascarene island of Rodrigues
-
Pramod about 4 yearsI have just shown you the approach you can use the regex also.
-
Pramod about 4 yearsIf you want to display only one result then after first result break the loop. Updated the example