Find the answer to your Linux question:
Results 1 to 5 of 5
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?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2012
    Posts
    20

    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
    Location
    Kentucky
    Posts
    5,025
    I'm just as lazy... maybe lazier.
    Just use cp.
    That pretty much does the job.
    Code:
    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.

    *EDIT*
    I just had a 'duh' moment... using the <TAB> button to auto-complete filenames cankeep you from having to type them out, as well.
    Code:
    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 02:24 AM. Reason: see EDIT
    Jay

    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
    Just Joined!
    Join Date
    Oct 2012
    Posts
    11
    use the tab key :/

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jan 2012
    Posts
    20
    Thanks for the replies

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

    Code:
    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
    Just Joined!
    Join Date
    Jan 2012
    Posts
    20
    OK I found what I was looking for... at least one way.

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

Posting Permissions

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