Do Linux commands need to be memorized?Daily Linux Command: manThe mv (move) command primarily serves two purposes: one is to rename files, executing this command does not copy the file. The other purpose is to move files or folders from one directory to another, similar to the “cut” command in Windows.In essence, there is no significant difference between renaming and moving files.
This command, like the file-related commands we introduced earlier, carries certain risks; when overwriting files, there is no confirmation message, and the overwritten files are difficult to recover, so caution is advised when using it.
✦•———-Basic Usage———-•✦
The interesting aspect of Linux commands is that many commands with similar functionalities also have similar parameters, so learning these commands can help you understand others.
Previously, when we introduced commands like cp(1) and rm(1), we mentioned some parameters that are also applicable to the mv(1) command:
1. Interactive overwrite confirmation (-i):This prevents accidentally overwriting important files! When a file with the same name already exists at the target location, it will pause and ask you mv: overwrite ‘destination’? You need to input y or n to confirm.
2. Force overwrite without asking (-f):This is the opposite of -i. Even if the target file exists and does not have write permission (as long as you have permission), it will forcefully overwrite without any prompts. Use with caution! This can easily lead to data loss.
3. Verbose mode (-v):This will inform you exactly what it did. For example: ‘source’ -> ‘destination’. This is very useful when moving multiple files or writing scripts, as it clearly shows the results of the operations.
4. No overwrite (-n):If a file with the same name already exists at the target location, mv will skip moving this source file and will not overwrite the target file. There are no prompts (unless used with -v).
The mv(1) command can also be used with wildcards, such as ?, *, [], {} etc. For specific usage of wildcards, please refer to previous articles.
Congratulations, you have gained more useful knowledge✨