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

625 questions
837
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
  • 12,208
  • 9
  • 32
  • 38
386
votes
20 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
  • 62,960
  • 55
  • 119
  • 146
164
votes
10 answers

Undo git mv (rename)

What is the right way to undo a rename in git, like: git mv file1 file2
jrdioko
  • 32,230
  • 28
  • 81
  • 120
147
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
  • 9,768
  • 24
  • 79
  • 122
136
votes
11 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
  • 110,170
  • 32
  • 120
  • 176
91
votes
6 answers

Getting an error cp: cannot stat when trying to copy files from one folder to another

I have this directory called "mock", which contains 3 directories. I am trying to copy all the items from "mock" directory into the "projweek" directory using the following command: cp /mock/* ~/projweek But I get this error: cp: cannot stat…
user5647516
  • 1,083
  • 1
  • 9
  • 19
86
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,501
  • 2
  • 17
  • 25
77
votes
3 answers

move only if file exists in a shell script

I want to use mv to rename a file: mv src.txt dest.txt If the file doesn't exist, I get an error: mv: cannot stat ‘src.txt’: No such file or directory How do I use mv only if the file already exists? I don't want to redirect stderr to dev/null as…
Arth
  • 12,789
  • 5
  • 37
  • 69
59
votes
12 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
  • 16,374
  • 12
  • 37
  • 38
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
  • 2,078
  • 2
  • 19
  • 21
55
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,776
  • 5
  • 25
  • 46
48
votes
5 answers

linux wildcard usage in cp and mv

I am composing a script to process 20 files. All of them located in different directories. I have partial file name. In log directory, File1_Date_time.err change to File1__Date_time_orig.err cd ../scripts/ sh File.sh File1 directory is…
TJ Wu
  • 659
  • 1
  • 7
  • 9
44
votes
5 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
  • 549
  • 1
  • 4
  • 11
39
votes
5 answers

Linux Bash: Move multiple different files into same directory

As a rather novice Linux user, I can't seem to find how to do this. I am trying to move unique files all in one directory into another directory. Example: $ ls vehicle car.txt bicycle.txt airplane.html train.docx (more files) I want car.txt,…
Conner
  • 723
  • 1
  • 8
  • 17
36
votes
8 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,508
  • 3
  • 26
  • 44
1
2 3
41 42