Questions tagged [mv]

Tag for questions about the terminal command "mv" to move and rename files.

144
votes
5answers
286k views

mv: Directory not empty

I want to move content of a directory within another directory with the same folders. Here's an example: I have ./backup wich have the directories base and test. Now I want to move these directories ...
137
votes
12answers
424k views

How to move multiple files at once to a specific destination directory?

I got a bunch of files in some directory (along with many other files) that I want to move. Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep ...
32
votes
3answers
12k views

“mv file” and now it's missing

In a terminal window, I typed: mv filename ..\.. [Note the wrong slash.] Now I can't find it. Gone. I ran some searches and looked through recoverable deleted files. Nothing. Poof. Serves me ...
21
votes
4answers
12k views

Why does moving some files in a folder take longer than moving the whole folder?

I have millions of images on my ubuntu cloud server. When I move a complete folder containing 12 million images using mv command, it happens almost instantaneously. However, when I mv only images(not ...
19
votes
1answer
2k views

Moved a directory to an unknown …/ place (three dots)

I came across this weird situation when I accidentally moved one of my directory to an unknown place I am unable to find. What I did was executed this command - /opt/lampp/htdocs/cake$ mv cakephp/ .....
14
votes
3answers
3k views

Revert moving root directory recursively

I have an Ubuntu Desktop used as a Server. This morning I accidentally moved all my root to ../ root@server:/tmp/UPS/up/upsilon# mv /* ../ mv: impossibile spostare "/dev" in "../dev": Dispositivo o ...
13
votes
3answers
4k views

Simulate action of mv command

I'm moving some files around, and I want to make sure that the mv command I've typed is correct before I go ahead and run it. If I was using apt-get, I could use the -s flag to perform a simulation ...
12
votes
3answers
27k views

mv files with | xargs

I'm just trying to move a bunch of files (not symlinks) out of my /etc/apache/sites-enabled folder into the /etc/apache/sites-available folder with the following: /etc/apache2/sites-enabled$ find . -...
12
votes
1answer
3k views

How to move some files to their parent directory?

I want to pull all mp3's that accidentially have been put into a flac folder out of it, to their parent folder. It should not matter how deep the folders are, I just want to move the matching files ...
12
votes
3answers
1k views

Change directory to target of move operation

Occasionally, I have edited some file and want to move it to a different folder. (Typically: to a Dropbox folder, where I did not want to work to avoid giving the other owners of the folder constant ...
10
votes
5answers
3k views

Why doesn’t `mv file /dir` move the file to a subdirectory of the current working directory?

I was in my /etc directory and typed the command me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn I thought that would move the file into the directory openvpn which is a subdirectory of the /etc ...
9
votes
6answers
2k views

How to move Only the files in current folder to a sub folder?

I don't have to move the folders, only the files. I have tried mv * but this command moves the folders also.
8
votes
4answers
25k views

copy/move multiple files using cp/mv without using regular expressions

Suppose I have a folder containing some files and some folders(files can be of any type). And I want to move/copy some of those files and folders using mv/cp command. Is there any way, such that I ...
8
votes
3answers
22k views

mv command - don't overwrite files

I want to mv files and not overwrite duplicates. The -b switch only makes a single backup file, whereas I may have many. According to the mv man page: The backup suffix is '~', unless set with --...
7
votes
4answers
2k views

Replace a word in a directory name and in the filenames in that directory

I have a directory structure like this: Bookname Edition 1 Bookname Edition 1 type1.pdf Bookname Edition 1 type2.pdf Bookname Edition 2 Bookname Edition 2 type1.pdf Bookname Edition 2 type2....
7
votes
2answers
1k views

How to use mv command to move only selected files? [duplicate]

What is the command to move the all files to target directory except *.trg files? Tried the below command but it's not working: mv !(*.trg) tgtdir
7
votes
3answers
2k views

Accidentally moved directories under root

I've accidentally run this command sudo mv /* /applications/minced/ instead of sudo mv ./* /applications/minced/ This is all that's left in the root directory $ / applications/ dev/ ...
7
votes
4answers
2k views

Move only the last 8 files in a directory to another directory

I'm trying to move the last 8 files from the Documents directory to another directory, but I don't want to move them one-by-one to that specific directory. Is it possible to move them with a ...
6
votes
4answers
2k views

Renaming multiple files with complex numbered names

I have 365 files named MOD11A1.A2010001.h24v06.006.2016025150444.hdf MOD11A1.A2010002.h24v06.006.2016025151748.hdf MOD11A1.A2010003.h24v06.006.2016025163706.hdf and I want to rename these files as: ...
6
votes
3answers
2k views

Accidentally moved home folder?

I'm not quite sure what just happened, all I did was running: ~/Desktop$ mv sublime.desktop \~/.local/share/applications/ The \ sign before ~/.local came up as autocomplete, so I thought it was okay ...
6
votes
4answers
1k views

with mv, consider the path/name of the original file when choosing destination [duplicate]

Say I need to move the file /etc/dir1/dir2/dir3/a.out to /etc/dir1/dir2/dir3/b.out Typing the whole path twice is tedious, and going to the directory might not be ideal. Is there a way to do such a ...
6
votes
1answer
564 views

Moved file to typoed-folder

I moved mv ~/...path.../myFile.py ~/a/b/c/typoedFolder I understand now that I should always have a trailing / to prevent these issues, but given that it happened - is there any hope of recovering ...
6
votes
4answers
38k views

How to copy (or move) files from remote machine to local machine?

I SSH tunneled from my local Ubuntu machine to a remote Ubuntu machine and I want to copy/move files from the remote Ubuntu to the local one. I need to do that from within the SSH session (i.e, from ...
6
votes
2answers
3k views

How to move output of find command to another directory?

I want the output of this command find /home -name *.pdf to move the files in the search result to another directory, e.g. with a pipe. How can I do that?
5
votes
3answers
2k views

Script for “extracting” subfolders into parent folder

This gonna be a little bit tricky, I guess :-) When I open a terminal in the folder and run a script, that script should: move all content of all subfolders to a top parent folder (recursively) ...
5
votes
3answers
391 views

Renaming files by adding “cycling” suffix

I have a directory containing subdirectories containing many files named as: file1.tif file2.tif file3.tif file4.tif file5.tif file6.tif file7.tif... I want to add a "cycling" suffix c1, c2 and c3, ...
5
votes
3answers
692 views

Move to directory that was no directory

I did this: mv couchpotato_11-08-2016_09-35.tar.gz ~/AtoMiC-ToolKit/backup mv transmission-daemon_11-08-2016_09-36.tar.gz ~/AtoMiC-ToolKit/backup mv sickrage_11-08-2016_09-35.tar.gz ~/AtoMiC-ToolKit/...
5
votes
2answers
2k views

Move multiple files to a dir if their names contain the same string present in dir name

I have multiple files in one folder: ABA.xy BEB.xy ACA.xy The same files with different extension in another folder ABA.rr BEB.rr ACA.rr Then I have single folder for each file name ABA BEB ACA ...
4
votes
2answers
10k views

How to delete to trash via terminal (with mv command)? [duplicate]

I would like to know how can I delete a file and/or move it to trash with mv command? I know where the trash located is, then I tried with this commands to move it to trash: mv somefile /home/...
4
votes
4answers
1k views

Moving multiple extension file name in another directory

#!/bin/bash # script to find and move files SOURCE=/DRIVE2/folder/ DESTDIR=/DRIVE/new3/ MOVEFILES=(mpg avi m4v mp4 3gp mpeg MOV) # this line above is not working, its only reading the first ...
4
votes
3answers
3k views

How to move multiple files with rsync while showing progress?

I can move files with this command: mv -t /mnt/hdd /home/me/movies/movie1.avi /home/me/movies/movie2.avi The problem is, that it shows no progress at all, so I don't know if the operation is 1% done ...
4
votes
3answers
3k views

How do I find my file which was moved without destination

I am in a trouble. I pressed 'enter' without the destination. I had two files in the same directory with a common IDENTIFIER in their name. I wanted to move them to a folder, so I entered mv /path/...
4
votes
3answers
1k views

Renaming files with last modified time on file name

I am trying to rename a file with the mv command and I would like to add the last modified date of this file (with YYYYMMDD format) on the file name and move it to other folder. I got the current ...
4
votes
3answers
768 views

How do I dissolve all subfolders

Is there a command line one-liner to move all the contents of all the direct subfolders of a folder to the folder itself and deleting the subfolders (which are now empty)? I.e., eliminate a level in ...
4
votes
2answers
8k views

File disappeared on move

I had a directory with a file and another empty directory in it like this: . .. file.ext folder I did: mv file.ext /folder The file disappeared now, not in folder too not where it was before! ...
4
votes
2answers
5k views

mv error in shell script “are the same file”

I'm trying to get a script that will rename and move videos. Here is what I have: #!/bin/bash src="/mnt/Files_Apps/temp/" dest="/mnt/Files_Apps/TFTP root/" for file in "$src"*.*; do newfile="${dest}...
3
votes
2answers
16k views

move files matching a specific pattern

How can I move files in a folder with a specific pattern to the destination folder? I want to move files with names in the range [00-09] in the 4th column when separated by delimiter "-". ls | cut -...
3
votes
3answers
738 views

Renaming date-stamped files to the previous day

I want to rename the files in a directory to sequential numbers, based on this rule : filename-[some date] => filename-[previous day's date] For example, file20170329 file20170328 and file20170327 ...
3
votes
1answer
4k views

Script for moving files that are older than 5 days

I'm currently working on a script that allows me to move any file thats older than 5 days into an archive folder with the same path, except for the root folder which changes. So something like: root/...
3
votes
2answers
185 views

-i option not working for mv

The man for the mv command says there's a -i option to prompt a y/n before the command is executed, but it's not working for me. Each time I use mv -i, the file is automatically renamed without ...
3
votes
2answers
3k views

Using wildcards to do mass renaming? [duplicate]

I realized I had named a bunch of files in an off-by-one fashion so I wanted to rename any file starting with "1" to the same thing except starting with 2. For example mv 1.4.5.txt 2.4.5.txt or mv 1-...
3
votes
1answer
985 views

Can't see my files with “ls” anymore

HELP! I think I broke my DESKTOP :/ I was playing around with the Terminal and trying to practice moving, renaming, and copying files when I think I screwed something up. I was attempting to move ...
3
votes
2answers
561 views

How move the biggest file in each subdirectory to current directory?

I like to loop though subdirectories and move the biggest file to its parent and then delete the folder. I have tried many things but never got it working correctly. It says that mv cant find the ...
3
votes
2answers
4k views

Find and exec in found folder

I'm trying to find files containing *.nef and move them to a subdirectory name NEF of the folder in which the file is found. I've started testing with the following command, but this always copies to ...
3
votes
1answer
193 views

Move files to parent directory, prefixing file name with former subdirectory name [duplicate]

I have a folder parentdir with many directories like this: $ tree parentdir/subdir_1 parentdir/subdir_1 ├── important.txt ├── important_001.txt ├── important_002.log ├── important_007.bmp ├── ...
3
votes
1answer
562 views

mv command deleted a folder

I am new to linux. I had a folder called "Código" where I kept all of my .h's and .cpp's when I programmed. I wanted to move said folder up one directory and into a new folder called "Code", so in the ...
3
votes
1answer
2k views

Nautilus sometimes refuses to rename files or folders - terminal works

I sometimes have the following issue: I'm working with Nautilus (Ubuntu 14.10 with Unity) and for example create new folders. But when I want to rename them, I can select that in the context menu and ...
3
votes
2answers
296 views

Move many folders and files to their many parent folders

I need to find all folders with the name "test" and move all folders along with the files inside up a level to their parent folders: html/folder1/js/test -> html/folder1/test html/folder2/js/test ...
2
votes
2answers
8k views

How to exclude a folder when using the mv command

I have this situation where I want to exclude a directory while using the mv command. I saw this example where the syntax would be !(exclude_dir), but when I set up a scenario to test it I get results ...
2
votes
1answer
175 views

Rename and convert dates in filename without file extension

My set of files are named according to GMT time zone. I successfully renamed and converted all files into the required time zone using the following steps. 1. This code removes all file extensions ...