How To Rename Directories and Folders In Linux? – POFTUT

How To Rename Directories and Folders In Linux?

Renaming or moving directories and folder can be tricky if those directories and folders have some subfolders. Or the destination may have all ready same name folder which will create some error. In this tutorial we will look how to rename and move directories and folders in Linux.

Rename Using Mv Command

The defacto command for rename directories and folders is mv . mv is the short form for the move . We can simply rename by providing the current directory and folder name and destination directory or folder name. Syntax is like below. If the source or current directory folder have content we need to rename by using recursive move. This will only change given directory or folder name but move all sub files and folder.


In this example we will rename directory named backup  into old_backup .

$ mv backup old_backup


While renaming or moving files and folders we may need to get verbose information. Verbose mode will print every move or rename. This will be helpful for recursive option. We will provide -v to enable verbose.

$ mv -v backup old_backup

Overwrite Forcibly If Exists

In some cases there may be existing folder or directory with the new name. We need to confirm the overwrite. But this can be daunting task if there is a lot of them. We can overwrite existing files and folder with -f option automatically. -f means forcibly.

$ mv -f backup old_backup

Prompt For Confirmation Before Overwriting

If we do not want to write existing file forcibly we can confirm for each file rename. In this case we have to use -i like below.

$ mv -i backup old_backup

LEARN MORE  Windows Ren Command Tutorial with Examples To Rename Files and Folders

Leave a Comment