Tag Info

New answers tagged

1

find -mtime -2 \ -maxdepth 1 \ \! -type d \ \( -name 'simon*' \ -o -name 'tom*' \ -o -name 'john*' \ \) | tar -T - \ --xform='s/[0-9]*$//' \ -cf - | tar -C ./path/to/destination --keep-newer-files -xf - I think that will do it - it appears to work for me. So long as the simon, tom, and john files are intended to be ...


0

The following is hopefully self explainatory find -maxdepth 1 -mtime -2 -type f -exec bash -c 'name=${1##*/}; cp "$name" /some/other/dir/${name%%[0-9]*}' _ {} \;


27

The linefeed character (also known as newline or \n) is the one that when sent to a terminal tells the terminal to move its cursor down. Yet, when you run seq 3 in a terminal, that is where seq writes 1\n2\n3\n to something like /dev/pts/0, you don't see: 1 2 3 but 1 2 3 Why is that? Actually, when seq 3 (or ssh host seq 3 for that matter) writes ...


3

When using that method to copy the file the files appear to be different. Remote server ls -l | grep vim_cfg -rw-rw-r--. 1 slm slm 9783257 Aug 5 16:51 vim_cfg.tgz Local server Running your ssh ... cat command: $ ssh dufresne -t 'cat ~/vim_cfg.tgz' > vim_cfg.tgz Results in this file on the local server: $ ls -l | grep vim_cfg.tgz -rw-rw-r--. 1 ...


3

To avoid running one cp per file (as with -exec cp {} /dest \;): find . -name '*.txt" -type f -exec sh -c ' exec cp "$@" /path/to/destination' sh {} + Or with GNU cp: find . -name '*.txt" -type f -exec cp -t /path/to/destination {} + With zsh: cp ./**/*.txt(.) /path/to/destination Or cp ./**/*.txt(D.) /path/to/destination If you want to include ...


3

use command : find . -name "*.txt" -exec cp {} /path/to/destination \;


7

use rsync: rsync -a --ignore-existing cosmo_sim_9 /dest/disk/cosmo_sim_9 --ignore-existing will cause it to skip existing files on the destination, -a will make it recursive, preserving if possible permission/ownership/group/timestamp/links/special devices. you can do it for all directories by using a bash for loop: for dir in cosmo_sim_* ; do rsync -a ...


10

Using rsync can accomplish this. Based on the type of system you have, you will need to donwload it: sudo yum install rsync (RPM Based) sudo apt-get install rsync (Debian Based) Then using this, here is the command you will need to use: rsync -a source destination Or rsync -r source destination Where -r stands for copying data recursively (but don’t ...


1

This is a job for rsync. There's no benefit to doing this manually with a shell loop unless you want to move the file rather than copy them. rsync -a /images/ /images2/ If images with the same name exist in both directories, the command above will overwrite /images2/SOMEPATH/SOMEFILE with /images/SOMEPATH/SOMEFILE. If you want to replace only older files, ...


0

for dir in images2/*; do mv "$dir"/* "images/$(basename "$dir")"; done Loop over all the contents of images2 using an expanded glob (to avoid the problems with parsing ls) then mv the contents of those items to the matching entry in images. Uses basename to strip the leading images2 from the globbed path.


1

@inulinux12 , you can use the following one line for loop from command line: $ for dir in images2/*; do mv "$dir"/* "${dir/2/}"; done This will move all of the files from images2 to images in their respective directories. Note: this assumes no files have the same name. For example: Before execution: $ ls -R images* images: ad adfoo fe images/ad: ...


0

There's no traditional Unix system call for "copy the full contents of one fd to another". Loops of "read a chunk; stop if EOF; write the chunk" were always written in userspace. There are some recent additions like sendfile(2) and splice(2) which allow you to do the equivalent of a read-write loop in a single syscall. Using these can improve performance at ...


1

Look at the manual for cp (also mv): cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... If you do cp a b then if b does not exist you get cp -T a b, but if b exists and is a directory you get cp -t b a, else error. Example mkdir empty cd empty mkdir a touch a/a-file cp -r a b #this creates ...


1

Just do as you did: cp -r dir1 dir2 and you will have dir1 (with its content as well) inside dir2. Try if you don't believe ;-). The command that would copy content of dir1 into dir2 is: cp -r dir1/* dir2


1

You use Ubuntu, so you will have GNU find, try: find . -maxdepth 1 ! -iregex ".*\.\(jpg\|png\|gif\|xcf\)$" -exec mv -- -t /path/to/newdir "{}" + -iregex use regex to find filename, but case insensitive, ! negates the regex. -exec command + run command for files matching. It's like using find -print0 with xargs -0. Using this we can move multiple files ...


6

You can use find to find all files in a directory tree that match (or don't match) some particular tests, and then to do something with them. For this particular problem, you could use: find -type f ! \( -iname '*.png' -o -iname '*.gif' -o -iname '*.jpg' -o -iname '*.xcf' \) -exec echo mv {} /new/path \; This limits the search to regular files (-type f), ...


1

OK, I have found the solution in my case. I am indeed using the suggested while loop. It now looks like this: while ! \ rsync -aiizP --append --stats . -e ssh user@host.com:./path/rfiles ; \ do now=$(date +"%T") ; echo · Error at $now · ; sleep 5 ; done Without the while loop, I would have to manually start the rsync again. Now, it works just like a ...


2

If you try to solve this problem at the level of the file copy tool, rsync is as good as it gets. Be sure to use the options -au, so that rsync won't try to synchronize the same file multiple times. Rsync will make progress as long as it's able to at least exchange the file list and transfer one file fully before being interrupted; if you can't ensure that, ...


2

The main problem with rsync that it can't continue induvidual files. If you are copying a complex directory structure, it is okay, but if you want to copy for example a single dvd image, it won't be robust. For such cases I use wget. More precisely, wget -c -t 0 -T 10 http://.... Especially interesting is the 20 sec timeout, which resolves the common ...


3

I would definitely suggest rsync. I use rsync to copy files anytime I think that the connection has any possibility of being interrupted. If the copy fails, I know I can simply start it again. It's easy to put it in a while loop if you need it to automatically restart until it succeeds.


0

I would suggest using an NFS mount to copy your files. To install Services for NFS components: Click Start, point to Administrative Tools, and then click Server Manager. In the left pane, click Manage Roles. Click Add Roles. The Add Roles Wizard appears. Click Next. The Select Server Roles options appear. Select the File Services check box, and then click ...



Top 50 recent answers are included