Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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
add comment

2 Answers

dir=$(basename /usr/abc)
for file in a b c d e f
do
  mv $file /usr/abc/${dir}${file}
done
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
add comment

man cp gives you the -t option:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.