Find the answer to your Linux question:
Results 1 to 8 of 8
Sorry for this question: How do I move multiple files WITH ONE command (not through GUI) from one dir to another? The following command does not work: mv *.mp3 /var/www/backup/files/ ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2006
    Posts
    5

    How to move multiple files in ONE COMMAND to other dir?


    Sorry for this question:

    How do I move multiple files WITH ONE command (not through GUI) from one dir to another?

    The following command does not work:

    mv *.mp3 /var/www/backup/files/

    Linux terminal tells me:
    mv: call of stat for *.mp3 not possible: file or dir not found

    How else does it work?

    Related question: If I replace "mv" by "cp" in your solution: Does it work as well?

    Thomas

  2. #2
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    883
    That is the correct syntax for the command. The error is telling you that it cannot find anything that ends in .mp3 in the current directory.

  3. #3
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    a better way to achieve your multi-file move command might be to use find and its -exec option instead, e.g.:

    Code:
    find . -mindepth 1 -maxdepth 1 -type f -name '*.mp3' -exec mv -iv {} /var/www/backup/files/ \;
    that command will only move files that it finds in the current dir that end in '.mp3', and will prompt you before overwriting (-i). the {} in the above command is actually an internal variable used by find that represents each '.mp3' file found.

  4. #4
    Linux Newbie
    Join Date
    Aug 2010
    Posts
    229
    you might have to move them as root to put them in to that directory.

  5. #5
    Linux Newbie
    Join Date
    Aug 2010
    Posts
    229
    Are you sure it's not the destination folder that it can't find.

  6. #6
    Just Joined!
    Join Date
    Oct 2013
    Location
    Belleville, New Jersey
    Posts
    11
    I believe you are missing a . from the command you are using... try this...

    Code:
    mv *.mp3 /var/www/backup/files/.

  7. #7
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by kmelillo View Post
    I believe you are missing a . from the command you are using... try this...

    Code:
    mv *.mp3 /var/www/backup/files/.
    the trailing "." after the directory there doesn't do anything different. e.g., it is the same as:

    Code:
    mv *.mp3 /var/www/backup/files/
    using the "." usually comes in handy when you are specifying a relative (versus absolute) directory path.

    to avoid confusion to future readers of this thread, mizzle's explanation of the original problem is accurate.

  8. #8
    Just Joined!
    Join Date
    Jun 2013
    Location
    Orlando
    Posts
    3
    Just tried this on my own machine, I moved two text files to my desktop running this command. Try using my format and tell me if that works
    Code:
    mv test.txt test2.txt ~/Desktop
    Here is quick bash script for future usage if you'd like to use it.


    Code:
    #!/bin/bash
    path=~/var/www/backup/files/
    read -p "Enter file names separated by a space: " files
    mv $files $path

Posting Permissions

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