Search code examples
unixterminalmv

Moving a file in terminal using mv


I have a simple python file simple_events.py that was mistakenly saved outside of my python_practice directory. I am trying to move it back into this directory but I get an error when try.

command:

mv simple_events.py/python_practice 

second command:

mv simple_events.py/Users/One-Life.Grind./python_practice

error:

usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory

If someone could tell me why this isn't working and how to correct it, it would me much appreciated.


Solution

  • mv -u simple_events.py/python_practice 
    

    The usage of "-u" means that an existing file will be overwritten if the source file is newer than the file already in place. I would just cp the file

    cp -rp /source.file /destination.file
    

    then remove the source by

    sudo rm source.file
    

    EDIT:: The "-rp" will recursively copy all folders within a folder, and their respective permissions to the new location.