mv
Command Function
This command is used to move files.
Syntax
mv [-fivn] SOURCE... DEST
Parameters
Table 1 Parameter description
Usage
- SOURCE supports wildcard characters * and ?. The asterisk (*) indicates any number of characters, and the question mark (?) represents a single character. DEST does not support wildcard characters. If the specified SOURCE matches multiple files, DEST must be a directory.
- If DEST is a directory, this directory must exist. In this case, the destination file is named after the source file.
- If DEST is a file, the directory for this file must exist.
- If the destination file already exists, it will be overwritten.
Example
Run the following commands:
- mv -i test.txt testpath/
- mv test?.txt testpath/ (Move test3.txt, testA.txt, and test_.txt)
Output
Example 1: moving a file
OHOS:/$ touch test.txt
OHOS:/$ mkdir testpath
OHOS:/$ touch testpath/test.txt
OHOS:/$ mv -i test.txt testpath/
mv: overwrite 'testpath//test.txt' (Y/n):y
OHOS:/$ ls
bin etc proc storage testpath usr
dev lib sdcard system userdata vendor
OHOS:/$ cp testpath/test.txt ./
OHOS:/$ ls
bin etc proc storage test.txt userdata vendor
dev lib sdcard system testpath usr
OHOS:/$ mv -i test.txt testpath/
mv: overwrite 'testpath//test.txt' (Y/n):n
OHOS:/$ ls
bin etc proc storage test.txt userdata vendor
dev lib sdcard system testpath usr
Example 2: moving files using wildcards
OHOS:/$ ls
bin etc proc storage test.txt testA.txt testpath usr
dev lib sdcard system test3.txt test_.txt userdata vendor
OHOS:/$ mv test?.txt testpath/
OHOS:/$ ls
bin etc proc storage test.txt userdata vendor
dev lib sdcard system testpath usr
OHOS:/$ ls testpath/
test.txt test3.txt testA.txt test_.txt