mv command in linux move files and directories with examples | Pro Tech guides

mv command in linux move files and directories with examples

mv command allows you to move files and directories, rename files. And also to overwrite the file and directories.

mv | move command in linux | move directories and files

move files in linux
linux command mv

Hello, guys welcome to the next session on Linux command line tutorial. In this session, we will see how we can use "mv command" in Linux.

Let's get started I will just press "ctrl + alt + T" to open my terminal.

Syntax :

$mv [option] [source] [destination]

So first you use "mv" as a command then you can use options like "-v","-i" or "-f" 

Then comes your source file. It can be one or many files or directories.

And then comes the destination (file or directory)

Rename a file using mv command

rename a file using mv command in linux
Rename the file using mv

$mv [fileName] [newfile Name]

First of all, I have this "file1.txt" and I want to use the "mv" command to change the name of this file.

So I will just use "mv" and then the name of the file and then I will just give some other name to the file. For example "file2.txt" and press ENTER.

And you will see here this file1 becomes file2.

And the content of the file will remain the same.

move a file to the directory using mv command

move a text files inside a folder
moving a file to the directory

$mv [file name] [folder name]

Now for example I want to move this "file2.txt" to "folder1".

I can just use "mv" and then the file name and then my directory name and press ENTER.

So in this way you can transfer the file or move the file to our directory using the move command.

To avoid overwrite use an interactive flag with mv

Intractive mode to avoid overwriting
Interactive mode

$mv -i [file name] [folder name]

I want to create a new file. For example "file2.txt" on the desktop.

And I want to move this "file2.txt" to folder1 which already have "file2".

So if you want to move the file which already exists then it will overwrite the file.

At this time what you are going to do is just use a flag (-i) with this command "mv -i file2.txt folder1".

"i" stands for interactive mode.

So it will ask you if you want to overwrite the file. Which was already present in the folder1 with the same name.

When I press "Y" it's going to overwrite the file or if I have press "N" and it's not going to overwrite the file.

move a directory using mv command

move a directory using mv command in linux
move directory in linux

$mv [directory name] [newDirectory name]

Let's create a directory called folder2

Now for example I want to transfer the "folder1" inside the "folder2".

I can use the Move command. So I can just write "mv folder1 folder2" and press ENTER. And it's going to move folder1 inside folder2.

So if the "folder2" doesn't exist it's going to create a directory and then move the content of the folder1 inside folder2.

Conclusion

I hope you understood this basic concept which I want to convey here.

To learn more about "mv" just write "man mv" and it's going to view the whole description of using the mv command.

So just use this and read these descriptions and you will be good to go.

I hope you have enjoyed this tutorial and bye for now.

HAVE A NICE DAY 💗

Name

Apps,3,Games,1,Linux,38,Linux Commands,37,Network-Devices,1,Networking,1,Terminal Apps,2,Termux,17,Userland,3,Windows,1,
ltr
item
Pro Tech guides: mv command in linux move files and directories with examples
mv command in linux move files and directories with examples
mv command allows you to move files and directories, rename files. And also to overwrite the file and directories.
https://1.bp.blogspot.com/-k6wS59oN-fI/X8Ud5o4mCzI/AAAAAAAACf4/VtaW4MMngTQL7Ff7HiHsgggzAmL31lF8ACNcBGAsYHQ/s16000/mv%2Bcommand%2Bin%2Blinux.png
https://1.bp.blogspot.com/-k6wS59oN-fI/X8Ud5o4mCzI/AAAAAAAACf4/VtaW4MMngTQL7Ff7HiHsgggzAmL31lF8ACNcBGAsYHQ/s72-c/mv%2Bcommand%2Bin%2Blinux.png
Pro Tech guides
http://www.protechguidez.com/2020/11/mv-command-in-linux-move-files-and-directories-with-examples.html
http://www.protechguidez.com/
http://www.protechguidez.com/
http://www.protechguidez.com/2020/11/mv-command-in-linux-move-files-and-directories-with-examples.html
true
7053638852026728047
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content