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
34
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
  • 779
  • 1
  • 8
  • 21
32
votes
9 answers

Split a folder into multiple subfolders in terminal/bash script

I have several folders, each with between 15,000 and 40,000 photos. I want each of these to be split into sub folders - each with 2,000 files in them. What is a quick way to do this that will create each folder I need on the go and move all the…
Brian C
  • 1,333
  • 3
  • 19
  • 36
29
votes
2 answers

bash error renaming files with spaces - mv target is not a directory

I'm trying to rename a bunch of files which contain spaces in them, getting rid of the spaces. I thought I found the correct bash command: for f in *.txt; do mv \"$f\" ${f/ /}; done However, this gives the error, "mv: target is not a directory"…
Jim Hines
  • 291
  • 1
  • 3
  • 3
26
votes
1 answer

mv equivalent rsync command

i'm trying to move folders to another folders using command line, with overwrite if already exists, but i got error "Is a directory" when using mv.. example: mv src/test/ dest/ there are many files and folders on src/test/, there are also some…
Kokizzu
  • 24,974
  • 37
  • 137
  • 233
26
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
  • 673
  • 2
  • 7
  • 13
21
votes
1 answer

Permissions required to move file to different directory in Unix/Linux

I would like clarification on the permissions required, in order to move a file A from directory B to directory C (the command would be "mv B/A C/A", I think), with name unchanged. Am I correct to think that the following are required? The…
Andy
  • 2,770
  • 9
  • 35
  • 42
19
votes
4 answers

move or copy a file if that file exists?

I am trying to run a command mv /var/www/my_folder/reports.html /tmp/ it is running properly. But I want to put a condition like if that file exists then only run the command. Is there anything like that? I can put a shell file instead. for shell…
Maharjun M
  • 853
  • 4
  • 11
  • 24
18
votes
3 answers

mv: "Directory not Empty" - how do you merge directories with `mv`?

I tried to deploy my personal blog website to my remote server recently. When I tried to move a few files and directories to another place by executing mv, some unexpected errors happened. The command line echoed "Directory not Empty". After doing…
SilentKnight
  • 13,761
  • 19
  • 49
  • 78
15
votes
4 answers

How to use the mv command in Python with subprocess

I have a lot of files in /home/somedir/subdir/ and I'm trying to move them all up to /home/somedir programmatically. right now I have this: subprocess.call(["mv", "/home/somedir/subdir/*", "somedir/"]) but it's giving me this error: mv: cannot stat…
CSStudent
  • 425
  • 1
  • 6
  • 14
15
votes
5 answers

bash removing part of a file name

I have the following files in the following format: $ ls…
HattrickNZ
  • 4,373
  • 15
  • 54
  • 98
14
votes
2 answers

How do the UNIX commands mv and rm work with open files?

If I am reading a file stored on an NTFS filesystem, and I try to move/rename that file while it is still being read, I am prevented from doing so. If I try this on a UNIX filesystem such as EXT3, it succeeds, and the process doing the reading is…
jl6
  • 6,110
  • 7
  • 35
  • 65
14
votes
3 answers

How can I move many files without having Argument list too long?

I am trying to move about 700,000 .jpg files from one directory to another in my Ubuntu server. I tried the following: xargs mv * -t /var/www/html/ and echo (*.jpg|*.png|*.bmp) | xargs mv -t /var/www/html/ and echo (*.jpg) | xargs mv -t…
Awah Hammad
  • 165
  • 1
  • 1
  • 9
13
votes
7 answers

Rename files using sed and mv

I want to rename files in the format: img_MM-DD-YY_XX.jpg img_MM-DD-YY_XXX.jpg to: newyears_YYYY-MM-DD_XXX.jpg Where: YYYY = year MM = month DD = day XXX or XX = photo number I came up with this script but it isn't working: for filename in…
tiagob
  • 1,088
  • 1
  • 11
  • 14
12
votes
3 answers

Move all files in directory to parent with node.js

Question Is there a simple way to move all the files in a directory up to its parent directory then delete the directory? Use Case I'm doing a zip extraction and the source zip contains a root folder called archive, so when I extract I get…
Ralph Callaway
  • 1,768
  • 1
  • 15
  • 34
11
votes
5 answers

Is there any shortcut to reference the path of the first argument in a MV command?

I often find myself using mv to rename a file. E.g. mv app/models/keywords_builder.rb app/models/keywords_generator.rb Doing so I need to write (ok, tab complete) the path for the second parameter. In this example it isn't too bad but sometimes the…
Jack Kinsella
  • 4,491
  • 3
  • 38
  • 56
1
2
3
41 42