Skip to main content
added 294 characters in body
Source Link
TonyH
  • 159
  • 5

Here is a one-liner using xargs, tr and globbing. Might have some value.

echo *.c | tr ' ' '\n' | xargs -n1 -I{} cp "{}" "PREFIX{}" 

This returns all files matching *.c as a space-separated string. Next, tr turns the extra spaces into newlines (N.B. did not test file names with spacesspaces**). Then, xargs gets populated with each file name, and runs cp with the appropriate name and prefix.

*.c can be modified for other, useful globs. Other prefixes in the xargs and cp part can be used as well.

**for those with spaces in their filenames:

(requires find that supports -print0) Similar to above, we can use find to output a null-seperated list of files, and tweak xargs with a flag to separate on null

find . -name '*.c' -print0 | xargs -0 -n1 -I{} cp "{}" "PREFIX{}" 

Here is a one-liner using xargs, tr and globbing. Might have some value.

echo *.c | tr ' ' '\n' | xargs -n1 -I{} cp "{}" "PREFIX{}" 

This returns all files matching *.c as a space-separated string. Next, tr turns the extra spaces into newlines (N.B. did not test file names with spaces). Then, xargs gets populated with each file name, and runs cp with the appropriate name and prefix.

*.c can be modified for other, useful globs. Other prefixes in the xargs and cp part can be used as well.

Here is a one-liner using xargs, tr and globbing. Might have some value.

echo *.c | tr ' ' '\n' | xargs -n1 -I{} cp "{}" "PREFIX{}" 

This returns all files matching *.c as a space-separated string. Next, tr turns the extra spaces into newlines (N.B. did not test file names with spaces**). Then, xargs gets populated with each file name, and runs cp with the appropriate name and prefix.

*.c can be modified for other, useful globs. Other prefixes in the xargs and cp part can be used as well.

**for those with spaces in their filenames:

(requires find that supports -print0) Similar to above, we can use find to output a null-seperated list of files, and tweak xargs with a flag to separate on null

find . -name '*.c' -print0 | xargs -0 -n1 -I{} cp "{}" "PREFIX{}" 
typo fix
Source Link
TonyH
  • 159
  • 5

Here is a one-liner using xargs, tr and globbing. Might have some value.

echo *.c | tr ' ' '\n' | xargs -n1 -I{} cp "{}" "PREFIX{}" 

This returns all files matching *.c*c as a space-separated string. Next, tr turns the extra spaces into newlines (Didn'tN.B. did not test case of spaces in file names with spaces). Then, xargs gets populated with each file name, and runs cp with the appropriate name and prefix.

*.c can be modified for other, useful globs. Other prefixes in the xargs and cp part can be used as well.

Here is a one-liner using xargs, tr and globbing. Might have some value.

echo *.c | tr ' ' '\n' | xargs -n1 -I{} cp "{}" "PREFIX{}" 

This returns all files matching *.c* as a space-separated string. Next, tr turns the extra spaces into newlines (Didn't test case of spaces in file names). Then, xargs gets populated with each file name, and runs cp with the appropriate name and prefix.

*.c can be modified for other, useful globs. Other prefixes in the xargs and cp part can be used as well.

Here is a one-liner using xargs, tr and globbing. Might have some value.

echo *.c | tr ' ' '\n' | xargs -n1 -I{} cp "{}" "PREFIX{}" 

This returns all files matching *.c as a space-separated string. Next, tr turns the extra spaces into newlines (N.B. did not test file names with spaces). Then, xargs gets populated with each file name, and runs cp with the appropriate name and prefix.

*.c can be modified for other, useful globs. Other prefixes in the xargs and cp part can be used as well.

Source Link
TonyH
  • 159
  • 5

Here is a one-liner using xargs, tr and globbing. Might have some value.

echo *.c | tr ' ' '\n' | xargs -n1 -I{} cp "{}" "PREFIX{}" 

This returns all files matching *.c* as a space-separated string. Next, tr turns the extra spaces into newlines (Didn't test case of spaces in file names). Then, xargs gets populated with each file name, and runs cp with the appropriate name and prefix.

*.c can be modified for other, useful globs. Other prefixes in the xargs and cp part can be used as well.