🖥️mv

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the mv command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

#                ███╗   ███╗██╗   ██╗
#                ████╗ ████║██║   ██║
#                ██╔████╔██║██║   ██║
#                ██║╚██╔╝██║╚██╗ ██╔╝
#                ██║ ╚═╝ ██║ ╚████╔╝ 
#                ╚═╝     ╚═╝  ╚═══╝  
                

                                  
#==============================#
# CMD MV - move
#==============================##==============================#
mv -i 
# moves files, asking for confirmation before overwriting an existing file.

mv foo.{old,new}
# Rename foo.old to http://foo.new

mv ./dir/*/*.pdb ./pdb/ ; rm -r ./dir/

mv {E,e}ecummings.txt
# Change the case (to lowercase) of the first letter E of a filename using brace expansion.

mv foo.{old,new}
# Rename foo.old to http://foo.new

mv Picture{,-of-my-cat}.jpg
# I find brace expansion useful for renaming files. This cmd expands to "mv Picture.jpg Picture-of-my-cat.jpg"

mv image-file-with-query-string.jpg{?query-string=Z29vZCBqb2IK,} 
# Getting rid of query string in filename by surrounding it with {,}

# Adding Prefix to File name
# Good old bracket expansion :-) For large numbers of files, "rename" will spare you the for-loop, or the find/exec...
mv {,prefix_}yourfile.txt

# Adding Prefix to File name: Good old bracket expansion :-) For large numbers of files, "rename" will spare you the for-loop, or the find/exec...
mv {,prefix_}yourfile.txt

# Fix time-stamped filenames of JPEG images according to the EXIF date the photo was taken
# For each *.jpg or *.JPG file in the current directory, extract the date the photo was taken from its EXIF metadata. Then replace the date stamp, which is assumed to exist in the filename, by the date the photo was taken. A trick from https://unix.stackexchange.com/a/9256 is used to split the date into its components.
(IFS=': '; for i in *.(#i)jpg; do set $(exiv2 -K 'Exif.Image.DateTime' -Pv $i 2> /dev/null); mv -v $i "$1-$2-$3${i#[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]}"; done)
    # Sample output
	# '2020-04-12 DSC_0146.JPG' -> '2017-12-26 DSC_0146.JPG'
	# '2020-04-12 DSC_0147.JPG' -> '2017-12-28 DSC_0147.JPG'

# Add timestamp of photos created by the “predictive capture" feature of Sony's Xperia camera app at the beginning of the filename - The "predictive capture" feature of Sony's Xperia camera app hides the date stamp deeply inside the filename. This command adds another date stamp at the beginning of the filename.
(setopt CSH_NULL_GLOB; cd /path/to/Camera\ Uploads; for i in DSCPDC_000*; do mv -v $i "$(echo $i | perl -lpe 's/(DSCPDC_[0-9]{4}_BURST)([0-9]{4})([0-9]{2})([0-9]{2})/$2-$3-$4 $1$2$3$4/')"; done)
    # Sample output
	    # 'DSCPDC_0000_BURST20191215123205830.JPG' -> '2019-12-15 DSCPDC_0000_BURST20191215123205830.JPG'
	    # 'DSCPDC_0000_BURST20200119191047162.JPG' -> '2020-01-19 DSCPDC_0000_BURST20200119191047162.JPG'

# Add date stamp to filenames of photos by Sony Xperia camera app - Sony's Xperia camera app creates files without time-stamped names. Thus, after deleting files on the phone, the same names will be reused. When uploading the photos to a cloud storage, this means that files will be overwritten. Running this command after every sync of uploaded photos with the computer prevents this.
(setopt CSH_NULL_GLOB; cd /path/to/Camera\ Uploads; for i in DSC_* MOV_*; do mv -v $i "$(date +%F -d @$(stat -c '%Y' $i)) $i"; done)
	# Sample output
	    # 'DSC_0075.JPG' -> '2020-04-11 DSC_0075.JPG'
	    # 'DSC_0076.JPG' -> '2020-04-11 DSC_0076.JPG'

#==============================##==============================#
# CMD MV - move
#==============================##==============================#
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░