[Solved] why command mv remove all the file? [closed]


Command mv moves files. When file in destination exists, it will be replaced. The right command to copy file is cp. It’s used same way as mv.

Command mv git.sh /root/* will substitute wildcard char * with all names the directory contains. Then there are a few cases:

  1. /root contains multiple files or directories: command will fail
  2. /root contains one file: git.sh will be moved and replace the file in directory /root
  3. /root is empty: git.sh will be moved as git.sh to /root

mv will remove source but cp keeps it.

It’s better to have destination path with filename, for example mv git.sh /root/git.sh. When moving multiple files use destination path just to directory without filename or wildcard chars, for example mv dir/* /root/. When you want to move directory with subdirectories add -R argument.

Use man mv or man cp for more information.

solved why command mv remove all the file? [closed]