Questions tagged [mv]

mv is the Unix command to rename or move a file or directory.

mv is the Unix command to rename or move a file or directory.

Syntax:

mv - move (rename) files

Examples:

mv /my/dir /my/other/dir

References:

Related commands

556 questions
723
votes
14 answers

Is it possible to move/rename files in Git and maintain their history?

I would like to rename/move a project subtree in Git moving it from /project/xyz to /components/xyz If I use a plain git mv project components, then all the commit history for the xyz project gets lost. Is there a way to move this such that the…
sgargan
  • 10,798
  • 8
  • 29
  • 37
313
votes
19 answers

Is there a way to make mv create the directory to be moved to if it doesn't exist?

So, if I'm in my home directory and I want to move foo.c to ~/bar/baz/foo.c , but those directories don't exist, is there some way to have those directories automatically created, so that you would only have to type mv foo.c ~/bar/baz/ and…
Paul Wicks
  • 55,730
  • 52
  • 115
  • 144
145
votes
9 answers

Undo git mv (rename)

What is the right way to undo a rename in git, like: git mv file1 file2
jrdioko
  • 28,317
  • 26
  • 75
  • 116
132
votes
6 answers

How to do a git diff on moved/renamed file?

I moved a file using git mv. Now I would like to do a diff on the new file to compare it with the old file (with the old, now non-existent name). How do I do this?
dr jerry
  • 8,982
  • 21
  • 70
  • 112
106
votes
10 answers

How to rename with prefix/suffix?

How do I do mv original.filename new.original.filename without retyping the original filename? I would imagine being able to do something like mv -p=new. original.filename or perhaps mv original.filename new.~ or whatever - but I can't see anything…
Peter Boughton
  • 102,341
  • 30
  • 116
  • 172
72
votes
6 answers

Angular design pattern: MVC, MVVM or MV*?

Angular 1.x (AngularJS) was following more or less the MV* design principle because of its two-way data binding functionality. Angular2 is adopting a component-based UI, a concept that might be familiar to React developers. In a sense, the Angular…
AnonDCX
  • 2,121
  • 2
  • 13
  • 23
59
votes
3 answers

How can I rewrite history so that all files, except the ones I already moved, are in a subdirectory?

I have a project under git. One day I moved all project files from current directory to foo/bar/ under the project. I did it using git mv. Then I added some more files and did some changes to already existing files. As a result, now when I look at…
Alexander Sandler
  • 1,978
  • 2
  • 18
  • 21
48
votes
9 answers

How to use 'mv' command to move files except those in a specific directory?

I am wondering - how can I move all the files in a directory except those files in a specific directory (as 'mv' does not have a '--exclude' option)?
David Liu
  • 12,404
  • 8
  • 33
  • 37
47
votes
5 answers

How to move or copy files listed by 'find' command in unix?

I have a list of certain files that I see using the command below, but how can I copy those files listed into another folder, say ~/test? find . -mtime 1 -exec du -hc {} +
L P
  • 1,444
  • 5
  • 23
  • 43
42
votes
3 answers

move only if file exists in a shell script

As part of a backup script I want to call mv on a file to rename it: mv example.txt example2.txt If the file doesn't exist, I am receiving the error: mv: cannot stat ‘example.txt’: No such file or directory How do I call the mv only if the file…
Arth
  • 11,500
  • 5
  • 32
  • 62
39
votes
4 answers

What is cp: cannot stat error in Unix, I get this error when trying to copy thing from one folder to another

Hi I wanted to know why I am getting this error. I have this directory called mock, which inside has another 3 directories. I am trying to copy all the items from mock directory into the projweek directory using the below code. cp /mock/*…
user5647516
  • 547
  • 1
  • 5
  • 15
39
votes
4 answers

Spring mvc Ambiguous mapping found. Cannot map controller bean method

I am trying to build an app which can list some values from the database and modify, add, delete if necessary using Spring 4 and i receive the following error(only if the "@Controller" annotation is present in both of my controller files, if i…
Serban Gorcea
  • 402
  • 1
  • 4
  • 10
33
votes
5 answers

Use xargs to mv a directory from find results into another directory

I have the following command: find . -type d -mtime 0 -exec mv {} /path/to/target-dir \; This will move the directory founded to another directory. How can I use xargs instead of exec to do the same thing.
zjhui
  • 739
  • 1
  • 8
  • 20
28
votes
7 answers

How to move a given number of random files on Unix/Linux OS

I'm facing this simple task but, I'm also wondering about what's the easiest and short way to do it. My proposal is move a given numer of random files from a directory to another. This task is part of the creation of two datasets I need for machine…
Max
  • 2,288
  • 2
  • 23
  • 41
25
votes
5 answers

Linux command to move a directory

My old and new directory have same folders and files inside. I try: mv -if old/* new/* and get error mv: cannot move `./xxxxxx' to a subdirectory of itself How can I move it?
Qooe
  • 663
  • 2
  • 7
  • 13
1
2 3
37 38