mv

Move files and/or folders.

Syntax
      mv [options] source target

Options
     -n     Do not overwrite any existing file.

     -i     Prompt before moving a file that would overwrite an existing file.
            A response `y' or `Y', will allow the move to proceed
            (writes to standard error)

     -f     Always Overwrite destination files
            (Do not prompt for confirmation)

     -v     Verbose, show filenames.

The -n and -v options are non-standard and their use in scripts is not recommended.

The key combination Ctrl+w (cut last word followed by Ctrl-y, Ctrl-y (Paste twice) can be useful when writing mv commands, to quickly create two copies of the path, you can then just edit the destination to generate the new name.

Examples

Move all files with names ending in ".jpg" from the current folder to the Documents directory
$ mv *.jpg ~/Documents

Move the "Documents" folder to "Documents backup", quotes are needed because of the space in the folder name.
$ mv Documents "Documents backup"

Move the file Hunter.txt to the Trash. The tilde ~ indicates that the .Trash folder is located in the users home.

$ mv Hunter.txt ~/.Trash

Move all .jpg files to the CA folder, and for those with "New York" in the filename, replace with "California_"
the "${f/New York/California_}" is an application of bash parameter expansion.

$ mkdir CA
$ for f in *.jpg; do mv "$f" "CA/${f/New York/California_}"; done

Rename .txt files to .html
$ for f in *.txt; do mv ./"$f" "${f%txt}htm"; done

“Any intelligent fool can make things bigger and more complex, and more violent. It takes a touch of genius - and a lot of courage to move in the opposite direction” - Albert Einstein

Related macOS commands:

cp - Copy files.
CpMac - Copy a file while preserving metadata and forks (Developer Tools).
dd - Data Duplicator - convert and copy a file.
install - Copy files and set attributes.
MvMac - Copy a filewhile preserving metadata and forks (Developer Tools).
tar - store or extract files to an archive (allows symbolic links to be copied as links).


 
Copyright © 1999-2020 SS64.com
Some rights reserved