New answers tagged

0

Consider using rsync instead. Rsync works perfectly well on local copies and can certainly do what you want, once you wade through the fifteen gazillion options it has. rsync -avun DIRECTORYA/ DIRECTORYB will show you everything that would be done, and rsync -avu DIRECTORYA/ DIRECTORYB will do it.


0

You can use diff command. I have a job that copy some backup files everyday. some time I need to check if all files are copied, here is the syntax: diff /file1/ /file2/ and of course if you want to copy them use: cp -u /file1/* /file2


3

The expect command you use: spawn ssh test@192.168.142.15 ls > ls_from_remotes_sys This, effectively calls exec("ssh","test@192.168.142.15","ls",">","ls_from_remotes_sys") That means the three parameters (ls, > and the filename) are sent to the remote system; ie the redirection happens on the remote system. A kludge could be to call it via sh ...


3

You can use shell globbing for this: cp -rp *bat*/ /destination/ Here *bat*/ will expand to directories having bat in their names. Or using find, which will work even if there are so many files that you get an error because the command line is too long: find . -maxdepth 1 -type d -name '*bat*' -exec cp -rpt /destination {} +


0

If you always use this to copy only one file, you can create a shell function, possibly in your ~/.bashrc like cpb () { if [ -r "${2}/${1}~" ] ; then echo "backup of '$1' exists in '$2'" else cp -b "$1" "$2" fi } and use it like this: $ mkdir dir $ cpb x dir $ cpb x dir $ cpb x dir backup of 'x' exists in 'dir' $ ls -l dir ...


3

If you want to avoid clobbering any backup files with GNU cp, you can use numbered backups: cp --backup=t source destination Rather than overwrite a backup, this creates additional backups. Example As an example, let's consider a directory with two files: $ ls file1 file2 Now, let's copy file1 over file2: $ cp --backup=t file1 file2 $ ls file1 ...


0

For those who wants a solution, here you go: the install command doesn't work recursivly. So I wrote a shell script that does the trick. The first argument is the folder you want to copy, and the second is the target directory #!/bin/sh # Program to use the command install recursivly in a folder magic_func() { echo "entering ${1}" echo "target $2"...


0

Source side of the install is files list (according to info). So, use install source/* /destination -d and -D options create missed directories in the destination (with difference), -t option means that destination is the directory. With directory option it copies each source file into destination folder with source's file name


3

One way would be to use xargs xargs -a list.txt cp -t path/to/New_Folder/ -R -- If you wish to use a shell loop, then use while e.g. while IFS= read -r dir; do cp -t path/to/New_Folder -R -- "$dir" done < list.txt


1

Something like: for dir in `cat textfile.txt`; do cp -a "$dir" New_Folder/ echo Copied $dir done perhaps? Note: if any of the directory names in textfile.txt have spaces in them, it just got harder. Also: was there something significant about the lines in your .txt file? Were the directories on each line supposed to be treated differently from ...


1

According to the manual page, -u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing this is a feature which combines two tests, one trivial to implement in a script (missing) and one requiring some work (newer). You could make a script which reports what is needed using comm, diff ...


3

cp should do what you want. The problem is that you are not iterating through a folder. You are only doing one iteration with the "folder" being the contents of the $file variable. Try iterating over the file globbing, like this: for file in folder/* do cp -vf 'image.png' "$file" done I added a -v so you can get more verbose output to see any error, ...


2

Yes, rsync is your best bet. Something like this should work: rsync -vr --size-only --times <source> <dest> --size-only tells rsync not to copy the files again, --times tells it to update timestamps.



Top 50 recent answers are included