Moving and Renaming Files and Directories

Learn how to move and rename files and directories using the mv command.

We'll cover the following

The mv command

File names need to change, and things need occasional reorganization. We use the mv file to perform both of these operations. It works almost exactly like the cp command, except that the syntax is identical for moving files and directories. To move a file, we specify the source path and the destination path. Let’s try it out.

First, we rename the files/documents/markdown directory. We name it employee_handbook instead:

mkdir -p files/{movies,music,photos,docs/{diagrams,markdown},code/{go,js,elm}}
touch files/docs/markdown/chapter{1..3}.md
mkdir files/backups
clear
mv files/docs/markdown files/docs/employee_handbook
ls files/docs/markdown
ls files/docs/employee_handbook

Run the complete code on the terminal below for practice.

Get hands-on with 1400+ tech skills courses.