| | |

LFCA 16 ๐Ÿง Moving and Renaming โ€” mv

mv is the command that moves files and directories from one place to another โ€” and also the command that renames them. In Unix, those are the same operation: renaming a file is moving it to a new name in the same directory. That duality is the key to understanding mv. It’s fast because it often does no copying at all โ€” on the same filesystem, it just changes the directory entry, which is why it’s near-instantaneous even for huge files. This chapter covers the syntax, the destination rules, the flags, the surprising behaviors, and how it differs from cp.

Key point: mv SOURCE DEST moves or renames. If DEST is an existing directory, SOURCE moves into it. If DEST is a name (existing or not), SOURCE is renamed to that name. Unlike cp, mv doesn’t copy data when the source and destination are on the same filesystem โ€” it changes the directory entry, which is why it’s fast for large files. mv deletes the source; that’s the “move” part. Both move and rename use the same command because Unix treats a rename as a move to a new name.


What mv does

mv moves a file or directory from one location to another, or renames it.

$ echo "hello" > original.txt
$ mv original.txt renamed.txt
$ ls
renamed.txt

The file was renamed. The content is unchanged. original.txt no longer exists.

The two operations:

OperationCommand
Renamemv oldname newname
Movemv file.txt /other/dir/

Both use the same command because a rename is a move โ€” to a new name in the same directory.

What mv does under the hood:

  • Same filesystem: Renames the directory entry โ€” near-instant, regardless of size
  • Different filesystems: Copies then deletes the source โ€” takes time proportional to size
  • Across symlinks: Follows the target unless -T or careful flags are used

What mv doesn’t do:

  • Doesn’t preserve the source โ€” it’s gone after the move
  • Doesn’t copy data on the same filesystem
  • Doesn’t ask before overwriting by default
  • Doesn’t create parent directories (that’s mkdir -p)

Why “mv” not “rename”: Because a move and a rename are the same operation in Unix. mv names the general case โ€” moving. The rename case is a move to the same directory with a different name.

Why this matters for performance: Moving a 10 GB file within the same filesystem is instant. Copying it and deleting the original would take minutes. That difference comes from mv being a metadata operation โ€” it changes where the directory points, not the file data.

Why the same command for both: A file’s name is part of its directory entry, not the file itself. Changing the name changes the entry. Changing the directory also changes the entry. Both are edits to the same structure. Unix exposes them as one command because they’re one operation.


Renaming files

Renaming is the simplest case.

$ mv report.txt final-report.txt

report.txt is now final-report.txt. No copy happened โ€” the file’s directory entry changed.

Adding an extension:

$ mv script script.sh

Removing an extension:

$ mv script.sh script

Renaming a directory:

$ mv old-folder new-folder

Directories rename the same way โ€” the entry changes, contents untouched.

Renaming with a different path:

$ mv ~/notes.txt /tmp/notes.txt

That’s a move and a rename โ€” to a new directory with the same name. Or:

$ mv ~/notes.txt /tmp/other-name.txt

Different directory, different name.

Why renaming is cheap: A rename on the same filesystem is a change to a directory entry โ€” a few bytes of metadata. The file’s inode and data are untouched. That’s why renaming a 100 GB directory is instant.

Why the syntax is symmetric: mv old new โ€” the source and destination are both names. The command doesn’t care whether they’re the same directory or different; it just moves the source to the destination name.

Why “inode” matters: On most filesystems, a file has an inode (which holds the metadata and points to the data) and one or more names in directories. Renaming changes the name in the directory โ€” the inode and data stay. That’s why renaming is a metadata operation.


Moving files

Moving a file into a directory is the other common case.

$ mv report.txt /tmp/
$ ls /tmp/report.txt
/tmp/report.txt

The file moved into /tmp, keeping its name.

The destination-is-a-directory rule:

$ mkdir archive
$ mv file1.txt file2.txt file3.txt archive/
$ ls archive/
file1.txt  file2.txt  file3.txt

When the destination is an existing directory, sources move into it.

Moving multiple files:

$ mv *.txt /tmp/

The shell expands *.txt; mv moves each into /tmp/.

The last argument must be a directory when moving multiple files:

$ mv a.txt b.txt dest-dir/

If the last argument isn’t a directory and there’s more than one source, mv errors.

Moving with a new name in the destination:

$ mv report.txt /tmp/summary.txt

The file is moved to /tmp and renamed summary.txt.

Why the destination rules matter: The same three cases as cp:

  • Destination is a directory โ†’ source moves into it, keeping its name
  • Destination is a name (not an existing directory) โ†’ source is renamed to that name
  • Multiple sources โ†’ the last argument must be a directory

Why moving is fast on the same filesystem: The file’s data isn’t touched. Only the directory entries change โ€” one in the source directory, one in the destination. It’s a couple of metadata writes.

Why the destination-is-a-directory rule is uniform: It applies to mv, cp, and install. Any command that copies or moves multiple sources needs a directory as the destination. The rule is consistent across tools.


Moving directories

Directories move the same way as files.

$ mv old-folder /tmp/
$ ls /tmp/old-folder/
(contents)

The directory and everything inside it moves.

Renaming a directory:

$ mv old-name new-name

The directory’s name changes; contents untouched.

Moving a directory into another:

$ mv project /opt/apps/
$ ls /opt/apps/project/
(contents of project)

If /opt/apps/project doesn’t exist, project becomes it. If it does exist, project nests inside as /opt/apps/project/project.

The subtle nesting rule: Same as cp. If the destination exists as a directory, the source nests inside.

Moving directories across filesystems: mv copies recursively then deletes. Slower, but works.

Why directories are just entries: A directory is a special kind of file that lists other entries. Moving it changes its parent directory’s entry. The contents don’t need to change.

Why cross-filesystem moves are slower: Different filesystems have separate directory structures. mv can’t just change a pointer โ€” it has to recreate the file at the destination and delete the original.

Why the same nesting rule for directories: A directory is a file with entries. When you move it into an existing directory, the parent’s entry points to the moved directory. The nesting follows from how directory entries reference their targets.


mv -i, -n, -u โ€” handling existing files

Like cp, mv has flags for existing destinations.

-i โ€” interactive:

$ mv -i source.txt dest.txt
mv: overwrite 'dest.txt'? y

Prompts before overwriting.

-n โ€” no clobber:

$ mv -n source.txt dest.txt

Doesn’t overwrite. Silently skips if the destination exists.

-u โ€” update only:

$ mv -u source.txt dest.txt

Moves only if the source is newer than the destination.

When to use which:

FlagUse case
-iInteractive, confirm each overwrite
-nScripting, never overwrite
-uSync-like, move only if newer

The alias trap: Many systems alias mv to mv -i. In interactive shells, mv prompts. In scripts, aliases don’t apply โ€” mv overwrites silently.

$ alias mv
alias mv='mv -i'

To bypass: \mv, command mv, or /bin/mv.

Why -i is often aliased: Accidental overwrites are a real hazard. The alias protects against them interactively but doesn’t affect scripts.

Why -n is safer in scripts: No prompt, deterministic behavior. If the script needs to overwrite, don’t use -n.

Why -u exists: When moving files from one directory to another, sometimes you only want newer ones. -u covers that case.

Why cp and mv share these flags: They answer the same question โ€” “what if the destination exists?” The flags are consistent across the tools. Learn them once, use them everywhere.


mv vs cp

The two commands look similar but differ in one crucial way.

Aspectcpmv
Source afterStill existsGone
Same filesystemCopies dataRenames entry
Cross-filesystemCopies dataCopies then deletes
SpeedProportional to sizeInstant on same FS
Recursive flag-r requiredNot needed
Preserve metadata-p, -aAlways (same FS)

The key difference: cp preserves the source; mv removes it. After mv, the source is gone.

When to use which:

NeedUse
Keep the originalcp
Move or renamemv
Backupcp
Reorganizemv
Change a namemv
Duplicatecp

Why mv doesn’t need -r for directories: Since mv doesn’t copy on the same filesystem, it doesn’t need to recurse. On a different filesystem, it recurses automatically.

Why mv preserves metadata automatically: On the same filesystem, the file’s inode is unchanged โ€” metadata is preserved by definition. Cross-filesystem mv preserves what the copy preserves; for metadata like timestamps, it may not.

Why this distinction is important: Using mv when you meant cp loses the original. Using cp when you meant mv leaves a duplicate. The intent โ€” keep or remove โ€” is the deciding factor.

Why mv is faster: A rename on the same filesystem doesn’t touch the file data. cp reads and writes the entire file. For large files, that’s the difference between milliseconds and minutes. If you only need to change a name or location, mv is always the right tool.


Cross-filesystem moves

When mv crosses filesystems, it behaves like cp + rm.

$ mv /home/alice/video.mp4 /mnt/external/video.mp4

/home and /mnt/external are on different filesystems. mv copies the file to the destination, then deletes the source.

What this means:

  • The move takes time proportional to the file size
  • The destination is a new file (new inode)
  • Metadata may not be preserved exactly
  • Interrupting the move leaves a partial copy

How to tell: df shows the filesystem for each path.

$ df /home/alice/video.mp4
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda2      500000000 200000000 300000000  40% /

$ df /mnt/external
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sdb1     2000000000 500000000 1500000000  25% /mnt/external

Different Mounted on values mean different filesystems. A move between them copies.

Why this matters: If you mv a 100 GB file across filesystems, it takes minutes and needs free space at the destination. On the same filesystem, it’s instant.

Why no error is raised: mv handles both cases seamlessly. The user doesn’t have to know whether the move is same-filesystem or cross-filesystem โ€” mv figures it out.

Why interrupting is risky: If you cancel a cross-filesystem mv mid-copy, the destination has a partial file and the source still exists. Nothing is atomic. For critical files, use a copy tool with verification or a filesystem with snapshots.

Why the same command works for both: The filesystem layer handles the difference. mv calls rename(2) if the filesystems match, and copies otherwise. To the user, it’s one operation with one syntax.


A full example

Renaming, moving, and organizing files.

# ============================================
# PART 1: RENAME A FILE
# ============================================

cd ~
echo "draft" > report.txt
mv report.txt final-report.txt
ls
# final-report.txt

# ============================================
# PART 2: MOVE A FILE
# ============================================

mkdir archive
mv final-report.txt archive/
ls archive/
# final-report.txt

# ============================================
# PART 3: MOVE WITH RENAME
# ============================================

mv archive/final-report.txt archive/2025-report.txt
ls archive/
# 2025-report.txt

# ============================================
# PART 4: MOVE MULTIPLE FILES
# ============================================

touch a.txt b.txt c.txt
mkdir texts
mv a.txt b.txt c.txt texts/
ls texts/
# a.txt  b.txt  c.txt

# ============================================
# PART 5: RENAME A DIRECTORY
# ============================================

mv texts text-files
ls
# archive  text-files

# ============================================
# PART 6: INTERACTIVE OVERWRITE
# ============================================

echo "old" > dest.txt
echo "new" > source.txt
mv -i source.txt dest.txt
# mv: overwrite 'dest.txt'? y

cat dest.txt
# new

# ============================================
# PART 7: NO-CLOBBER
# ============================================

echo "source" > source2.txt
echo "dest" > dest2.txt
mv -n source2.txt dest2.txt

cat dest2.txt
# dest

ls source2.txt
# source2.txt   โ† still exists

# ============================================
# PART 8: UPDATE ONLY
# ============================================

touch -d "2024-01-01" old.txt
touch new.txt   # today

mv -u old.txt target.txt     # old.txt older, no move if target newer
mv -u new.txt target2.txt    # new.txt newer, moves

# ============================================
# PART 9: MOVE ACROSS FILESYSTEMS
# ============================================

# Find the filesystems
df /tmp
# /dev/sda2  ...
df /mnt/data 2>/dev/null || echo "no /mnt/data"

# If different filesystems, mv copies
mv /tmp/bigfile /mnt/data/ 2>/dev/null

# ============================================
# PART 10: MOVE A DIRECTORY INTO AN EXISTING DIRECTORY
# ============================================

mkdir project
mkdir parent
mv project parent/
find parent
# parent
# parent/project

Each part exercises a mv use case. The move-and-rename duality shows up in parts 1, 2, 3, and 5.

Why this session: It covers the practical range โ€” rename, move, move with rename, multiple sources, directory rename, the three flags, cross-filesystem, and the nesting rule. Once these are habits, mv is second nature.


Complete Example Session

# ============================================
# PART 1: BASIC RENAME
# ============================================

echo "content" > oldname.txt
ls
# [ oldname.txt ]

mv oldname.txt newname.txt
ls
# [ newname.txt ]

# ============================================
# PART 2: MOVE TO DIRECTORY
# ============================================

mkdir archive
mv newname.txt archive/
ls archive/
# [ newname.txt ]

ls
# [ archive ]

# ============================================
# PART 3: MOVE AND RENAME
# ============================================

mv archive/newname.txt archive/final.txt
ls archive/
# [ final.txt ]

# ============================================
# PART 4: MULTIPLE SOURCES
# ============================================

touch one.txt two.txt three.txt
mkdir all
mv one.txt two.txt three.txt all/
ls all/
# [ one.txt  three.txt  two.txt ]

# ============================================
# PART 5: WILDCARD
# ============================================

touch more1.txt more2.txt
mv more*.txt all/
ls all/
# [ more1.txt  more2.txt  one.txt  three.txt  two.txt ]

# ============================================
# PART 6: RENAME DIRECTORY
# ============================================

mv all archive-all
ls
# [ archive  archive-all ]

# ============================================
# PART 7: NESTING
# ============================================

mkdir existing
mv archive-all existing/
find existing -type d
# [ existing ]
# [ existing/archive-all ]

# ============================================
# PART 8: -i INTERACTIVE
# ============================================

echo "target" > target.txt
echo "src" > src.txt

mv -i src.txt target.txt
# [ mv: overwrite 'target.txt'? ]
# Type y
# Moved

cat target.txt
# [ src ]

# ============================================
# PART 9: -n NO CLOBBER
# ============================================

echo "keep" > keep.txt
echo "ignored" > ignored.txt
mv -n ignored.txt keep.txt

cat keep.txt
# [ keep ]

ls ignored.txt
# [ ignored.txt ]   โ† still exists

# ============================================
# PART 10: -u UPDATE
# ============================================

touch -d "2020-01-01" older.txt
touch target2.txt

mv -u older.txt target2.txt
# older.txt stays โ€” target2.txt is newer

# If older.txt were newer, it would move and overwrite

# ============================================
# PART 11: SAME FILESYSTEM โ€” INSTANT
# ============================================

# Create a large file
dd if=/dev/zero of=big.bin bs=1M count=100 2>/dev/null

time mv big.bin big-renamed.bin
# real 0m0.001s   โ† near-instant

# ============================================
# PART 12: CROSS-FILESYSTEM
# ============================================

# /tmp and /home may be on different filesystems
df /tmp | tail -1
# /dev/sda2  ... /

df /home | tail -1
# /dev/sda2  ... /  โ† same filesystem, mv is instant

# If different:
time mv big-renamed.bin /tmp/
# real 0m0.5s   โ† takes time to copy

# ============================================
# PART 13: RECAP
# ============================================

ls
# [ archive  existing  keep.txt  src.txt  target.txt  target2.txt  ... ]

# mv is used for both rename and move
# Same filesystem โ†’ instant (metadata)
# Different filesystem โ†’ copy + delete

Every part exercises a mv feature. The same-filesystem speed is visible in the time outputs.


Quick Reference

mv Syntax

FormMeaning
mv SRC DESTRename or move
mv SRC DIR/Move into directory
mv SRC1 SRC2 DIR/Multiple sources
mv -i SRC DESTInteractive
mv -n SRC DESTNo overwrite
mv -u SRC DESTOnly if newer

Common Flags

FlagEffect
-iInteractive โ€” prompt before overwrite
-nNo clobber โ€” never overwrite
-uUpdate โ€” only if source newer
-vVerbose
-fForce โ€” no prompt
-t DIRTarget directory first
-TTreat DEST as a normal file, not a directory

Destination Rules

DestinationResult
Doesn’t existRename to that name
Existing fileOverwrite (unless -i, -n)
Existing directoryMove into it
Multiple sourcesLast must be a directory

mv vs cp

Aspectcpmv
Source afterExistsGone
Same-FS speedCopy timeInstant
Cross-FS speedCopy timeCopy time
Needs -r for dirsโœ…โŒ
Preserves metadataWith -p/-aAlways (same FS)

Same-FS vs Cross-FS

CaseBehavior
Same filesystemRename โ€” instant
Different filesystemsCopy then delete
Detect withdf PATH
Interrupted cross-FS movePartial destination

Common Patterns

TaskCommand
Rename filemv old.txt new.txt
Move filemv file.txt /tmp/
Move and renamemv file.txt /tmp/new.txt
Move multiplemv *.txt /tmp/
Rename directorymv old-dir new-dir
Move directorymv project /opt/
Interactivemv -i src dest
No overwritemv -n src dest
Update onlymv -u src dest

Error Cases

MessageCause
No such file or directorySource doesn’t exist
Permission deniedNo write on target dir
cannot move X to Y: Directory not emptyTrying to replace a non-empty dir
cannot overwrite directoryType mismatch
same fileSource and destination are the same

When to Use mv

SituationUse
Renamemv
Reorganize filesmv
Move to another diskmv
Backup (keep original)cp
Duplicatecp
Atomic change of namemv

Safety Flags

FlagWhen
-iInteractive use
-nScripts (never overwrite)
-uSync-like moves
-fForce in scripts that must overwrite

The Alias Trap

ContextBehavior
Interactive shell with alias mv='mv -i'Prompts
Script (aliases not loaded)Overwrites silently
Bypass alias\mv, command mv, /bin/mv

Metadata on Move

CasePreserved
Same filesystemAll metadata (inode unchanged)
Cross filesystemDepends on copy; may lose timestamps
PermissionsPreserved
OwnershipPreserved

Interaction with Symlinks

OperationBehavior
Move symlinkThe symlink moves
Move targetThe symlink points to the new location (if path stays)
mv -TTreat destination as file, not dir

Performance

CaseTime
Small file same FSInstant
Large file same FSInstant
Large file cross FSProportional to size

Verification

CommandShows
lsFiles after move
df PATHFilesystem of a path
find . -name XWhere a file ended up
statMetadata of moved file
cmp SRC DSTCompare after a cross-FS move

Best Practices

โœ… Do This:

# Use mv for rename and move
mv old-name.txt new-name.txt                             # โœ…

# Move into a directory
mv file.txt /tmp/                                        # โœ…

# Use -i interactively
mv -i source.txt dest.txt                                # โœ…

# Use -n in scripts
mv -n source.txt dest.txt                                # โœ…

# Use -u for update-only moves
mv -u /src/* /dest/                                      # โœ…

# Rename directories with mv
mv old-folder new-folder                                 # โœ…

# Verify the destination after
ls /tmp/file.txt                                         # โœ…

# Check the filesystem for large moves
df /tmp                                                  # โœ…

# Move a large file quickly within the same FS
mv bigfile.bin backup/                                   # โœ…

# Move multiple files into a directory
mv *.log logs/                                           # โœ…

โŒ Don’t Do This:

# Don't mv when you meant cp
mv file.txt backup/  # โš ๏ธ  original gone                        // โš ๏ธ

# Don't overwrite silently in scripts
mv source.txt dest.txt  # โš ๏ธ  overwrites without warning       // โš ๏ธ

# Don't assume cross-FS moves are instant
mv huge.bin /mnt/external/  # โš ๏ธ  takes minutes                 // โš ๏ธ

# Don't move into a name that's a file
mv file.txt existing-file.txt  # โš ๏ธ  overwrites existing-file   // โš ๏ธ

# Don't interrupt a cross-FS move
# Ctrl+C mid-copy leaves a partial file                        // โš ๏ธ

# Don't try to replace a non-empty directory with mv
mv file.txt non-empty-dir/  # โš ๏ธ  moves file into the dir       // โš ๏ธ

# Don't forget the -r confusion
mv dir1 dir2  # โœ… mv handles dirs without -r                   // โœ…
# (this is fine โ€” just noting that cp needs -r, mv doesn't)

# Don't rely on alias in scripts
mv old new  # โš ๏ธ  alias doesn't apply                          // โš ๏ธ

# Don't move files across filesystems casually
# Check df first                                                // โš ๏ธ

Common Pitfalls

PitfallProblemSolution
Confusing mv with cpOriginal goneConfirm intent
Overwriting silentlyLost fileUse -i or -n
Cross-FS slowUnexpected delayCheck df first
Interrupted cross-FSPartial fileUse robust copy tools
Alias not in scriptOverwritesUse full path
Same filesame file errorDifferent name
Multiple sources to non-dirErrorMake last a directory
Moving to a nonexistent parentErrormkdir -p first
Moving into itselfNested directoryUse mv dir/* dest/
No permissionPermission deniedCheck target dir

Real-World Examples

1. Rename a file

mv report.txt final-report.txt

2. Move to a directory

mv notes.txt ~/Documents/

3. Move and rename

mv report.txt /tmp/summary.txt

4. Move multiple files

mv *.log /var/log/archive/

5. Rename a directory

mv old-project new-project

6. Move a directory

mv project /opt/apps/

7. Interactive

mv -i source.txt dest.txt

8. No overwrite

mv -n source.txt dest.txt

9. Update-only

mv -u /newer/* /older/

10. Verbose

mv -v *.txt /tmp/

11. Same-filesystem rename

mv /home/alice/bigfile.bin /home/alice/backup.bin

Instant, no copy.

12. Cross-filesystem move

mv /home/alice/video.mp4 /mnt/external/video.mp4

Copies then deletes.

13. Move into an existing directory

mv project/ /opt/apps/

/opt/apps/project results.

14. Move directory contents

mv source-dir/* dest-dir/

Moves each item, not the dir itself.

15. Rename with extension change

mv script script.sh

16. Move with wildcard

mv *.txt docs/

17. Safe move in script

mv -n source.txt dest.txt || echo "not moved"

18. Move to a specific name with target directory

mv -t /tmp/ file.txt

Same as mv file.txt /tmp/.

19. Force overwrite in a script

mv -f source.txt dest.txt

20. Move across filesystems safely

rsync -av /home/alice/data /mnt/external/ && rm -rf /home/alice/data

More robust than mv for critical data.


Visual: What mv Does

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Before:                                     โ”‚
โ”‚  /home/alice/                                โ”‚
โ”‚  โ”œโ”€โ”€ report.txt                              โ”‚
โ”‚  โ””โ”€โ”€ backup/                                 โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ”‚  mv report.txt backup/
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  After:                                      โ”‚
โ”‚  /home/alice/                                โ”‚
โ”‚  โ””โ”€โ”€ backup/                                 โ”‚
โ”‚      โ””โ”€โ”€ report.txt                          โ”‚
โ”‚                                              โ”‚
โ”‚  Same filesystem โ†’ instant                   โ”‚
โ”‚  report.txt's inode unchanged                โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Rename = Move

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Rename:                                     โ”‚
โ”‚                                              โ”‚
โ”‚  /home/alice/old.txt                         โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ”‚  mv old.txt new.txt                  โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚  /home/alice/new.txt                         โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Move to a new name in a new directory:      โ”‚
โ”‚                                              โ”‚
โ”‚  /home/alice/old.txt                         โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ”‚  mv old.txt /tmp/new.txt             โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚  /tmp/new.txt                                โ”‚
โ”‚                                              โ”‚
โ”‚  Same operation โ€” the destination differs    โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Same FS vs Cross FS

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Same filesystem                             โ”‚
โ”‚                                              โ”‚
โ”‚  /home/alice/file.bin                        โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ”‚  mv /home/alice/file.bin /home/alice/backup/โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚  /home/alice/backup/file.bin                 โ”‚
โ”‚                                              โ”‚
โ”‚  โ€ข Rename only                               โ”‚
โ”‚  โ€ข Instant                                   โ”‚
โ”‚  โ€ข No copy                                   โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Different filesystems                       โ”‚
โ”‚                                              โ”‚
โ”‚  /home/alice/file.bin  (sda)                 โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ”‚  mv /home/alice/file.bin /mnt/external/โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚  /mnt/external/file.bin  (sdb)               โ”‚
โ”‚                                              โ”‚
โ”‚  โ€ข Copy then delete                          โ”‚
โ”‚  โ€ข Proportional to size                      โ”‚
โ”‚  โ€ข New inode at destination                  โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Destination Semantics

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  mv file.txt newname.txt                     โ”‚
โ”‚                                              โ”‚
โ”‚  โ†’ file.txt renamed to ./newname.txt         โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  mv file.txt /tmp/                           โ”‚
โ”‚                                              โ”‚
โ”‚  โ†’ file.txt moves to /tmp/file.txt           โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  mv file.txt existing-file.txt               โ”‚
โ”‚                                              โ”‚
โ”‚  โ†’ existing-file.txt overwritten             โ”‚
โ”‚  โ†’ unless -i or -n                           โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Directory Nesting Rule

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Case 1: Destination doesn't exist           โ”‚
โ”‚                                              โ”‚
โ”‚  $ mv project /opt/apps                      โ”‚
โ”‚                                              โ”‚
โ”‚  /opt/apps/                                  โ”‚
โ”‚  โ””โ”€โ”€ (project's contents)                    โ”‚
โ”‚                                              โ”‚
โ”‚  apps becomes the project                    โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Case 2: Destination exists as a directory   โ”‚
โ”‚                                              โ”‚
โ”‚  $ mv project /opt/apps/                     โ”‚
โ”‚                                              โ”‚
โ”‚  /opt/apps/                                  โ”‚
โ”‚  โ””โ”€โ”€ project/                                โ”‚
โ”‚      โ””โ”€โ”€ (project's contents)                โ”‚
โ”‚                                              โ”‚
โ”‚  project nested inside apps                  โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: -i vs -n vs -u

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Default: silent overwrite                   โ”‚
โ”‚                                              โ”‚
โ”‚  $ mv src dst                                โ”‚
โ”‚  (dst replaced)                              โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  -i: interactive                             โ”‚
โ”‚                                              โ”‚
โ”‚  $ mv -i src dst                             โ”‚
โ”‚  mv: overwrite 'dst'? _                      โ”‚
โ”‚                                              โ”‚
โ”‚  y โ†’ overwrite                               โ”‚
โ”‚  n โ†’ skip (source stays)                     โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  -n: no clobber                              โ”‚
โ”‚                                              โ”‚
โ”‚  $ mv -n src dst                             โ”‚
โ”‚  (dst not overwritten, source stays)         โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  -u: update only                             โ”‚
โ”‚                                              โ”‚
โ”‚  $ mv -u src dst                             โ”‚
โ”‚  If src newer than dst โ†’ move                โ”‚
โ”‚  Otherwise โ†’ skip                            โ”‚
โ”‚  If dst missing โ†’ move                       โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: mv vs cp โ€” Source Survival

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  mv source dest                              โ”‚
โ”‚                                              โ”‚
โ”‚  Before:                                     โ”‚
โ”‚  source   dest                               โ”‚
โ”‚                                              โ”‚
โ”‚  After:                                      โ”‚
โ”‚  (gone)   dest'                              โ”‚
โ”‚                                              โ”‚
โ”‚  Source is gone                              โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  cp source dest                              โ”‚
โ”‚                                              โ”‚
โ”‚  Before:                                     โ”‚
โ”‚  source   dest                               โ”‚
โ”‚                                              โ”‚
โ”‚  After:                                      โ”‚
โ”‚  source   dest'                              โ”‚
โ”‚                                              โ”‚
โ”‚  Source still exists                         โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Cross-Filesystem Detection

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ df /home/alice                            โ”‚
โ”‚  Filesystem  Mounted on                      โ”‚
โ”‚  /dev/sda2   /                               โ”‚
โ”‚                                              โ”‚
โ”‚  $ df /mnt/external                          โ”‚
โ”‚  Filesystem  Mounted on                      โ”‚
โ”‚  /dev/sdb1   /mnt/external                   โ”‚
โ”‚                                              โ”‚
โ”‚  Different "Mounted on" โ†’ different FS       โ”‚
โ”‚  mv will copy                                โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Directory Move

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  mv old-dir /new-parent/                     โ”‚
โ”‚                                              โ”‚
โ”‚  Before:                                     โ”‚
โ”‚  old-dir/                                    โ”‚
โ”‚  โ”œโ”€โ”€ a.txt                                   โ”‚
โ”‚  โ””โ”€โ”€ b.txt                                   โ”‚
โ”‚                                              โ”‚
โ”‚  /new-parent/                                โ”‚
โ”‚  (empty)                                     โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  After:                                      โ”‚
โ”‚  /new-parent/                                โ”‚
โ”‚  โ””โ”€โ”€ old-dir/                                โ”‚
โ”‚      โ”œโ”€โ”€ a.txt                               โ”‚
โ”‚      โ””โ”€โ”€ b.txt                               โ”‚
โ”‚                                              โ”‚
โ”‚  The whole tree moved                        โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Decision Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Rename or move a file?                      โ”‚
โ”‚       โ””โ”€โ”€ mv                                 โ”‚
โ”‚                                              โ”‚
โ”‚  Keep the original?                          โ”‚
โ”‚       โ””โ”€โ”€ cp, not mv                         โ”‚
โ”‚                                              โ”‚
โ”‚  Destination exists as a file?               โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ”œโ”€โ”€ Overwrite safely โ”€โ”€โ–บ mv -i         โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ””โ”€โ”€ Never overwrite โ”€โ”€โ–บ mv -n          โ”‚
โ”‚                                              โ”‚
โ”‚  Only if newer?                              โ”‚
โ”‚       โ””โ”€โ”€ mv -u                              โ”‚
โ”‚                                              โ”‚
โ”‚  Large file?                                 โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ”œโ”€โ”€ Same FS โ”€โ”€โ–บ instant                โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ””โ”€โ”€ Cross FS โ”€โ”€โ–บ copy + delete         โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ConceptMeaning
mvMove or rename
Same-FS moveRenames โ€” instant
Cross-FS moveCopies then deletes
Renamemv old new
Movemv file /dir/
-iInteractive
-nNo overwrite
-uUpdate only
Source afterGone

Key takeaways:

  • mv moves or renames โ€” the same operation
  • Renaming is a move to a new name in the same directory
  • Destination is a directory โ†’ source moves into it, keeping its name
  • Destination is a name โ†’ source is renamed to that name; existing files are overwritten
  • Same-filesystem moves are instant โ€” only the directory entry changes
  • Cross-filesystem moves copy then delete โ€” proportional to size
  • No -r needed for directories โ€” mv handles them by default
  • -i prompts before overwrite; -n never overwrites; -u moves only if newer
  • mv removes the source โ€” use cp if you need to keep it
  • Aliases only affect interactive shells โ€” scripts see plain mv
  • Interrupted cross-FS moves leave partial copies
  • mv preserves metadata on the same filesystem (inode unchanged)
  • Check df before large moves to know if they’ll be instant

Remember: mv is the move-and-rename command. Same filesystem? Instant, because only the directory entry changes. Cross filesystem? A copy then delete. Use -i interactively, -n in scripts. Remember the destination rules โ€” directory means “into,” a name means “rename.” And remember that mv deletes the source โ€” if you want to keep the original, use cp. That’s the whole command: one operation, two names, one move.


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!