≡ Menu

Unix Command To Rename A Folder

How do I rename a folder under UNIX operating systems using a command line tools?

You need to use the mv command to rename a folder under UNIX operating systems. You must have write permission for all folders.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Estimated completion time1m

Syntax to rename a directory on Unix

The syntax is as follows:
mv old-folder-name new-folder-name


mv /path/to/old /path/to/new

Example: Unix rename a directory command

In this example, a folder called drivers is renamed as olddrivers. Open a terminal (shell prompt) and type the following commands:

mv drivers oldrivers

OR pass the -v option to get verbose output:

mv -v drivers oldrivers

Do not prompt for confirmation before overwriting

mv -f dir1 dir2

Prompt for confirmation before overwriting

mv -i dir1 dir2

Pass the -n option to mv command to do not overwrite an existing file/dirname. The -n option overrides any previous -f or -i options:

mv -n dir1 dir2
Recommend readings
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 4 comments… add one }

  • Rogelio September 25, 2011, 11:27 pm

    I how do I move a file or folder into another directory? I have tried mv file.rtf ~/Documents mv ~/file.rtf ~/Documents and mv ~/file.rtf ~/Documents/ none of these work.

    • Ikem April 4, 2012, 5:03 pm

      I would try:

      mv “file.rtf” “Documents”
      mv “$HOME/file.rtf” “$HOME/Documents”

  • Aditya July 15, 2013, 7:04 pm

    ~ (tilt) means that you are working in the root directory and in root directory you can not do any changes if you have not only linux as your single o.s.
    so (move, rename )changes can be done in home directory only in that case.

  • Thomas August 31, 2015, 7:02 pm

    I would like to rename all “OK-” directory to “KESZ-” For example from: OK-Brooklyn.Nine.Nine.S02E10.WEB-DL.x264.HUN-SFY I wold like to this: KESZ-Brooklyn.Nine.Nine.S02E10.WEB-DL.x264.HUN-SFY
    I need some help :D

Leave a Comment