December 2, 2026 - 21:51
Linux Lesson 10 — mv: Moving a File and Changing Its Name Image
Linux Tutorials

Linux Lesson 10 — mv: Moving a File and Changing Its Name

0 Comments

Renaming and moving look like different desktop gestures, but mv can perform both. A destination in the same directory changes the name; a destination in another directory changes the location.

The old source path will disappear

Mv can overwrite an existing destination. Stay inside the practice area and use -i so a collision requests confirmation. We move the copy from lesson nine, keeping the original notlar.txt in place.

The archive tree from lesson six and notlar-kopya.txt from lesson nine must exist. Complete those steps if needed rather than ignoring a missing-source error.

BASH
cd "$HOME/netopsiyon-dersleri"
mv -i notlar-kopya.txt taslak.txt
ls -l taslak.txt
mv -i taslak.txt arsiv/2026/aralik/
ls -l arsiv/2026/aralik/taslak.txt

First rename, then move

The first mv changes notlar-kopya.txt to taslak.txt in the same directory. The new name appears and the previous name disappears. The content is not rewritten as a new document.

The second mv places it inside the existing archive directory. Its path becomes arsiv/2026/aralik/taslak.txt. The name stayed the same while the location changed. Supplying a new filename at the destination can combine both operations.

Verify the difference from copying

BASH
ls -l notlar.txt
ls -l notlar-kopya.txt
ls -l arsiv/2026/aralik/taslak.txt

After a successful exercise, the second ls is expected to report that the old copy name is absent. The original notes remain and the renamed copy appears at the archive path. We verify intended locations rather than relying only on the absence of an error.

Inspect what the destination name represents

The destination rule from cp matters here too. A nonexistent destination name can rename the file. An existing directory receives it inside. An existing regular file can be overwritten. An -i question gives you a decision point; it does not establish that replacing the target is appropriate.

A graphical file manager makes folder boundaries visible. In a terminal, the path and the listing provide that context. Inspect the target before and after a move instead of inferring it from a short name.

Supply the final filename as well

Run this extra experiment inside the supplied depth/move-targets fixture, which includes son-not.txt, bir.txt, iki.txt and the destination directories. Check pwd before starting so the main lesson's files remain separate. If the source is missing, do not choose another file arbitrarily.

BASH
mv -iv -- son-not.txt arsiv/2026/aralik/bitmis-not.txt

The command changes both location and name. The verbose option reports the action and -- ends options.

Declining an overwrite should leave the source where it was. Accepting can replace the old destination. This concrete consequence is why the exercise uses disposable lesson files.

Move more than one source

BASH
mv -iv -- bir.txt iki.txt belgeler/
ls -l belgeler/bir.txt belgeler/iki.txt

The final target must be an existing directory. Multiple moves can be processed one by one: a later failure does not automatically undo earlier successful moves. Inspect both locations after an error instead of treating the command as an all-or-nothing database transaction.

A renamed extension does not convert content

Renaming notlar.txt to notlar.jpg does not turn text into a photograph. Mv changes names and locations, not the encoded data format. An operating system may try a different application, but the stored bytes have not magically become another format.

Similarly, adding a leading dot changes default listing behavior, not encryption or access permissions. Names, contents and permissions are separate concepts.

Finish with a small record of the former path, new path and name that no longer exists. Confirm the starting point with pwd and the result with ls. That evidence is more useful than simply remembering that the command printed no error.

Not every move uses the same mechanism

Within one filesystem, mv can generally rename an entry. Across filesystems, copying and removing the source may be necessary. Do not assume every large move is instantaneous or automatically undone if interrupted.

Also consider references to the old path: an HTML image URL, a script or another application's configuration. Moving the file does not automatically repair those references.

Choose the final move

Move the archived file back into the practice directory under the name son-not.txt. Inspect both the new destination and the former archive path. If the new name exists and the previous path is gone, you have combined relocation and renaming in one operation.

Previous lesson

References: GNU / Linux

Related Articles

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment