2

I just came across this weirdness: I want to do the equivalent of dragging a directory inside another (moving it). Trival day-to-day task for a GUI.

here is my tree:

.
├── assemble.py
├── Basic Information Retrieval.ipynb
├── Basic Information Retrieval.tex
├── Book
│   ├── book.aux
│   ├── book.log
│   ├── Book_master.tex
│   ├── book.out
│   ├── book.pdf
│   ├── book.tex
│   ├── book.toc
│   ├── build.sh
│   ├── chapter_0.tex
│   ├── chapter_1.tex
│   ├── chapter_2.tex
│   ├── chapter_3.tex
│   ├── chapter_4.tex
│   ├── chapter_5.tex
│   ├── Cosine Similarity_files
│   │   ├── Cosine Similarity_17_0.png
│   │   └── Cosine Similarity_22_0.png
│   ├── Language Models_files
│   │   └── Language Models_5_0.png
│   └── nb_preamble.tex
├── convert_to_latex.sh
├── convert_to_pdf.sh
├── corpus_zika
├── Cosine Similarity_files
│   ├── Cosine Similarity_17_0.png
│   └── Cosine Similarity_22_0.png
├── Cosine Similarity.ipynb
├── Cosine Similarity.tex
├── Dicionario_zika.dict
├── Language Models_files
│   └── Language Models_5_0.png
├── Language Models.ipynb
├── Language Models.tex
├── Probabilistic Text Models.ipynb
├── Probabilistic Text Models.tex
├── README.md
├── Topic Modeling.ipynb
└── Topic Modeling.tex

I want to move Cosine Similarity_files into Book/, eventualy overwriting it if it is already there. I issue the natural command:

mv Cosine\ Similarity_files Book/

and I get the message Directory not empty WTF!? But it gets better if I ask it to move one level deeper:

mv Cosine\ Similarity_files Book/Cosine\ Similarity_files

It dutifully does what it wouldn't do before! it writes the source directory into the target directory!! WTF²!?!

Why is that? Does it make any sense?

1
  • 2
    It doesn't do what you think... It moves it into the destination directory, it doesn't overwrite the destination; that is, you end up with Book/Cosine\ Similarity_files/Cosine\ Similarity_files Jun 6, 2016 at 19:55

1 Answer 1

4

When you execute mv Cosine\ Similarity_files Book/ nothing happens because a directory with the same name that is not empty exists in the Book directory.

As don_crissti stated in the comments above, when you executed mv Cosine\ Similarity_files Book/Cosine\ Similarity_files, it moved Cosine\ Similarity_files to Book/Cosine\ Similarity_files/Cosine\ Similarity_files

If you want to overwrite any existing files within the directory you are moving, you will have to use the -f or -i option.

-f
--force
     Remove existing destination files and never prompt the user.

-i
--interactive
     Prompt whether to overwrite each existing destination file,
     regardless of its permissions.  If the response does not begin
     with `y' or `Y', the file is skipped.

Example: mv -f Cosine\ Similarity_files Book/

Note: -f will not overwrite or merge directories within the directory you are trying to move. It will only overwrite files.

If you want to merge or overwrite directories, you can use rsync with the --remove-source-files option. For more information look at this answer.

5
  • mv -f Cosine\ Similarity_files Book/ will not work. -f overwrites regular files but not directories. It will not perform a recursive overwrite.
    – grochmal
    Jun 6, 2016 at 20:19
  • @grochmal That is true. This will work for the OP's particular problem though. I will update my answer.
    – Peschke
    Jun 6, 2016 at 20:28
  • @ElixirofLove - Thanks. I'd add a small reference to rsync, just for people that might come here looking for and answer and not bother reading comments.
    – grochmal
    Jun 6, 2016 at 20:36
  • @grochmal Just updated. Thank you for your help and suggestions.
    – Peschke
    Jun 6, 2016 at 20:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .