• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to rename and move the directory and files in linux

August 17, 2013 by Sharad Chhetri Leave a Comment

To rename and move the directory and files in linux in linux we use single command called mv.
The mv command is used for both purpose means renaming and moving the directory or file,it is system command which ships bydefault when you install any linux. The command is also applicable to all Unix based operating system.

Syntax: mv [options] SOURCE DESTINATION

Move and rename directory or file in linux

Note: mv command is applicable to both directory and files.

Here for we have created a directory called test and the example is same with file also

linux@tuxworld:~/Desktop$ cd /tmp/
linux@tuxworld:/tmp$ mkdir test
linux@tuxworld:/tmp$ ls -ld test/
drwxrwxr-x 2 linux linux 4096 Aug 18 01:41 test/
linux@tuxworld:/tmp$ 

Now we will rename the directory.

Syntax: mv dir-name new-dir-name

mv test newtest

Reference:

linux@tuxworld:/tmp$ mv test/ newtest
linux@tuxworld:/tmp$ ls -ld *test*
drwxrwxr-x 2 linux linux 4096 Aug 18 01:41 newtest
linux@tuxworld:/tmp$

Now we will move the directory

Syntax: mv dir-name /destination/path

linux@tuxworld:/tmp$ mv newtest/ /home/linux/Desktop/
linux@tuxworld:/tmp$ cd ~/Desktop/
linux@tuxworld:~/Desktop$ ls -ld newtest/
drwxrwxr-x 2 linux linux 4096 Aug 18 01:41 newtest/
linux@tuxworld:~/Desktop$

Lets see,one more example of renaming the directory

Syntax: mv dir-name /path/you/want/to/move/new-dir-name

linux@tuxworld:~/Desktop$ mv newtest/ /home/linux/sharadtest
linux@tuxworld:~/Desktop$ ls -ld /home/linux/sharadtest/
drwxrwxr-x 2 linux linux 4096 Aug 18 01:41 /home/linux/sharadtest/
linux@tuxworld:~/Desktop$

How to move multiple directories or file

Note: The below given example is applicable to directory

Syntax example: mv directory1 directory2 directoryn -t /path/of/Destination-Directory

Use -t option

linux@tuxworld:/tmp$ mkdir test1
linux@tuxworld:/tmp$ mkdir test2
linux@tuxworld:/tmp$ mkdir test3
linux@tuxworld:/tmp$ 
linux@tuxworld:/tmp$ mkdir all-test
linux@tuxworld:/tmp$ 
linux@tuxworld:/tmp$ mv test1 test2 test3 -t all-test/
linux@tuxworld:/tmp$ ls -l all-test/
total 12
drwxrwxr-x 2 linux linux 4096 Aug 18 02:12 test1
drwxrwxr-x 2 linux linux 4096 Aug 18 02:12 test2
drwxrwxr-x 2 linux linux 4096 Aug 18 02:12 test3
linux@tuxworld:/tmp$ 

How to move multiple files into destination directory or path

Syntax example: mv filename1 filename2 filenamen -t /path/of/Destination-Directory

linux@tuxworld:/tmp$ mkdir all-files-dir
linux@tuxworld:/tmp$ touch testfile{1,2,3}
linux@tuxworld:/tmp$ ls -l testfile*
-rw-rw-r-- 1 linux linux 0 Aug 18 02:15 testfile1
-rw-rw-r-- 1 linux linux 0 Aug 18 02:15 testfile2
-rw-rw-r-- 1 linux linux 0 Aug 18 02:15 testfile3
linux@tuxworld:/tmp$ 
linux@tuxworld:/tmp$ mv testfile1 testfile2 testfile3 all-files-dir/
linux@tuxworld:/tmp$ 
linux@tuxworld:/tmp$ ls -l all-files-dir/
total 0
-rw-rw-r-- 1 linux linux 0 Aug 18 02:15 testfile1
-rw-rw-r-- 1 linux linux 0 Aug 18 02:15 testfile2
-rw-rw-r-- 1 linux linux 0 Aug 18 02:15 testfile3
linux@tuxworld:/tmp$ 

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. rsync all files,hidden files,symlinks,hardlinks to remotes Linux Server
  2. Your data directory and files are probably accessible from the internet because the .htaccess file does not work owncloud
  3. shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
  4. How to rename table in mysql using command line
  5. Linux command : To create new directory/folder
  6. print working directory ( pwd , PWD , OLDPWD ) in Linux / Unix
  7. find command to search keyword in files recursively in linux
  8. list files and directories by 4 commands in linux
  9. linux command to list the files from rpm package without extracting
  10. Extract single and selected files from RPM package on Linux

Filed Under: Linux, Linux Commands Tagged With: linux command, mv

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to empty Trash through command line in Ubuntu

Non interactive ,without typing password do ssh to Server : By sshpass

safest method to remove softlink in linux

Terminal Recording with script and scriptreplay command

Set GRUB password after installation of CentOS/Red Hat

find command to search keyword in files recursively in linux

Read the file inside compressed .gz files without extract

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy