Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to copy a list of files into a single directory, but make the target directory the first filename in the command, how can I do it with linux command.

share|improve this question

migrated from Sep 29 '11 at 16:10

This question came from our site for professional and enthusiast programmers.

Is creating a new script an option? – Vaughn Cato Sep 29 '11 at 3:44
no just i want do it with 1 command line – Elham abbasi Sep 29 '11 at 3:46
Is this a puzzle? There are some potentially tricky ways to do it like: echo target_dir | mv file1 file2 file3 $(cat) – Vaughn Cato Sep 29 '11 at 3:52
dir=$(basename /usr/abc)
for file in a b c d e f
  mv $file /usr/abc/${dir}${file}
share|improve this answer
can I write this without writing script? in one commands – Elham abbasi Sep 29 '11 at 4:18
well, you just glue all the command using ; – ajreal Sep 29 '11 at 6:17
@ajreal: except between do and mv – Benoit Sep 29 '11 at 15:17

man cp gives you the -t option:

cp -t dir a b c d e f
share|improve this answer

You must log in to answer this question.