Skip to main content
added 129 characters in body
Source Link
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k

With GNU tools:

find /tmp/ -ctime -1 -name 'x*' -print0 | xargs -r0 mv -t ~/play/ 

The -t (--target) option is GNU specific. -print0, -r, -0, while non-standard and originating in GNU are also found in some other implementations like on some BSDs.

POSIXly:

find /tmp/ -ctime -1 -name 'x*' -exec sh -c ' exec mv "$@" ~/play/' sh {} + 

Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.

Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.

With GNU tools:

find /tmp/ -ctime -1 -name 'x*' -print0 | xargs -r0 mv -t ~/play/ 

The -t (--target) option is GNU specific.

POSIXly:

find /tmp/ -ctime -1 -name 'x*' -exec sh -c ' exec mv "$@" ~/play/' sh {} + 

Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.

Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.

With GNU tools:

find /tmp/ -ctime -1 -name 'x*' -print0 | xargs -r0 mv -t ~/play/ 

The -t (--target) option is GNU specific. -print0, -r, -0, while non-standard and originating in GNU are also found in some other implementations like on some BSDs.

POSIXly:

find /tmp/ -ctime -1 -name 'x*' -exec sh -c ' exec mv "$@" ~/play/' sh {} + 

Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.

Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.

added 418 characters in body
Source Link
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k

With GNU tools:

find /tmp/ -ctime -1 -name 'x*' -print0 | xargs -r0 mv -t ~/play/ 

The -t (--target) option is GNU specific.

POSIXly:

find /tmp/ -ctime -1 -name 'x*' -exec sh -c ' exec mv "$@" ~/play/' sh {} + 

Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.

Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.

With GNU tools:

find /tmp/ -ctime -1 -name 'x*' -print0 | xargs -r0 mv -t ~/play/ 

POSIXly:

find /tmp/ -ctime -1 -name 'x*' -exec sh -c ' exec mv "$@" ~/play/' sh {} + 

With GNU tools:

find /tmp/ -ctime -1 -name 'x*' -print0 | xargs -r0 mv -t ~/play/ 

The -t (--target) option is GNU specific.

POSIXly:

find /tmp/ -ctime -1 -name 'x*' -exec sh -c ' exec mv "$@" ~/play/' sh {} + 

Both run as few mv commands as necessary and work whatever characters the file names may contain. The GNU one may have the advantage that find keeps looking for files while mv starts moving the first batch.

Beware that all the files and directories will end up in one directory, beware of clashes if several files in different directories have the same name.

Source Link
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k

With GNU tools:

find /tmp/ -ctime -1 -name 'x*' -print0 | xargs -r0 mv -t ~/play/ 

POSIXly:

find /tmp/ -ctime -1 -name 'x*' -exec sh -c ' exec mv "$@" ~/play/' sh {} +