linux - Exclude certain directories from ls and copy the remaining over to a shared path -


i have folder contains sub-directories a,b,c , d. need copy directories a , d directory called 'copy' while excluding b , c(i.e. b , c doesn't copied over). thinking doing following (in command-line pseudocode):

ls (selective ls on source directory) |     scp -r {returned value ls} {target directory} 

is there linux command-line way accomplish above?

the simple answer copy directories want:

scp -r d anotherhost:/path/to/target/directory 

this you've described in example. more general solution might this:

scp -r $(ls | egrep -v '^(b|c)$') anotherhost:/path/to/target/directory 

this command work long number of files in source directory not large. number of files goes up, you'll run "command long" error.

instead of using scp, use rsync, has variety of mechanisms including/excluding files. example:

rsync --exclude='b/' --exclude='c/' . anotherhost:/path/to/target/directory 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -