Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    use mv to move file with same name

    call me lazy... but how do I mv or cp a file to a new folder with the same name without having to manually re-type the file name?

  2. #2
    Administrator jayd512's Avatar
    Join Date
    Feb 2008
    I'm just as lazy... maybe lazier.
    Just use cp.
    That pretty much does the job.
    cp /home/this/folder /whatever/folder/here
    Copies it right over. But you will always have to dictate the destination.

    Or you could go GUI and copy/paste.

    I just had a 'duh' moment... using the <TAB> button to auto-complete filenames cankeep you from having to type them out, as well.
    cp /home/this/folder /wh<TAB>(autofill)/fo<TAB>(autofill)/he<TAB>(autofill)
    Hope that made sense.
    Last edited by jayd512; 10-13-2012 at 01:24 AM. Reason: see EDIT

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to private messages asking for Linux help. Please keep it on the public boards.

  3. #3
    use the tab key :/

  4. $spacer_open
  5. #4
    Thanks for the replies

    I understand how to use tab but that would only work on the source parameter, understandably.

    kevin@kevcoder00:~$ mv dirs<TAB>ource/s<TAB>ample.txt dirdest/sample.txt
    but I have to type the second sample.txt... which makes sense. How could the system "know" what I want.

    I was thinking more along the line of maybe some sort of text expansion or magic parameter

  6. #5
    OK I found what I was looking for... at least one way.

    kevin@kevcoder00:~$ mkdir dirsource; mkdir dirdest; touch dirsource/sample
    kevin@kevcoder00:~$ mysource=dirsource/sample ; mv $mysource dirdest/${mysource#*/}
    kevin@kevcoder00:~$ ls dirdest/
    kevin@kevcoder00:~$ ls dirsource/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts