The mv command moves files or directories from one location to another. It can also rename files or directories by moving them to the same location with a new name.
Click to reveal answer
beginner
How do you rename a file using mv?
To rename a file, use mv oldname newname. This moves the file oldname to the same directory but with the new name newname.
Click to reveal answer
intermediate
What happens if you use mv to move a file to a directory that already has a file with the same name?
The existing file in the destination directory will be overwritten without warning, replacing it with the moved file.
Click to reveal answer
beginner
How can you move multiple files to a directory using mv?
You list all the files you want to move followed by the destination directory. For example: mv file1.txt file2.txt /path/to/destination/.
Click to reveal answer
intermediate
What option can you use with mv to ask before overwriting files?
Use the -i option (interactive). It prompts you to confirm before overwriting any existing files.
Click to reveal answer
What does the command mv file1.txt file2.txt do if both files are in the same directory?
ACopies file1.txt to file2.txt
BRenames file1.txt to file2.txt
CDeletes file2.txt
DMoves file2.txt to file1.txt
✗ Incorrect
The mv command renames file1.txt to file2.txt by moving it to the same directory with a new name.
Which option with mv asks for confirmation before overwriting a file?
A-v
B-f
C-i
D-r
✗ Incorrect
The -i option makes mv interactive, asking before overwriting files.
What happens if you move a file to a directory where a file with the same name exists and you do not use any options?
AThe move fails
BThe file is renamed automatically
CThe command asks for confirmation
DThe existing file is overwritten without warning
✗ Incorrect
By default, mv overwrites existing files without asking.
How do you move multiple files to a directory?
Amv file1 file2 /directory
Bmv /directory/file1 /directory/file2
Cmv file1 /directory file2
Dmv /directory file1 file2
✗ Incorrect
You list the files first, then the destination directory.
Which command renames a directory named 'oldfolder' to 'newfolder'?
Amv oldfolder newfolder
Bmv newfolder oldfolder
Crename oldfolder newfolder
Dcp oldfolder newfolder
✗ Incorrect
Using mv with the old and new directory names renames the directory.
Explain how to rename a file and move a file to a different directory using the mv command.
Think about moving a file within the same folder vs moving it to another folder.
You got /3 concepts.
Describe what happens when you move a file to a directory where a file with the same name already exists. How can you avoid accidental overwrites?
Consider safety options in commands.
You got /3 concepts.
Practice
(1/5)
1. What does the mv command do in Linux?
easy
A. Copies files and folders
B. Lists files and folders
C. Deletes files and folders
D. Moves or renames files and folders
Solution
Step 1: Understand the purpose of mv
The mv command is used to move files or folders from one location to another or to rename them.
Step 2: Compare with other commands
Unlike cp which copies, or rm which deletes, mv changes the location or name without duplicating.
Final Answer:
Moves or renames files and folders -> Option D
Quick Check:
mv = move or rename [OK]
Hint: Remember: mv = move or rename files [OK]
Common Mistakes:
Confusing mv with cp (copy)
Thinking mv deletes files
Assuming mv lists files
2. Which of the following is the correct syntax to rename a file old.txt to new.txt using mv?
easy
A. mv old.txt new.txt
B. mv new.txt old.txt
C. mv -r old.txt new.txt
D. mv old.txt -n new.txt
Solution
Step 1: Understand basic mv syntax
The syntax is mv source destination. To rename, source is old name, destination is new name.
Step 2: Check each option
mv old.txt new.txt correctly uses mv old.txt new.txt. mv new.txt old.txt reverses source and destination. Options A and D use invalid options.
Final Answer:
mv old.txt new.txt -> Option A
Quick Check:
mv source destination = rename [OK]
Hint: Syntax: mv oldname newname to rename [OK]
Common Mistakes:
Swapping source and destination
Using invalid options like -r or -n
Confusing mv with cp syntax
3. Given the commands: mkdir testdir touch file1.txt mv file1.txt testdir/ What will be the result?
medium
A. Error: testdir does not exist
B. file1.txt is moved inside testdir folder
C. A new file named testdir is created
D. file1.txt is renamed to testdir
Solution
Step 1: Create directory and file
mkdir testdir creates a folder named testdir. touch file1.txt creates an empty file named file1.txt.
Step 2: Move file into directory
mv file1.txt testdir/ moves file1.txt into the folder testdir, keeping the same name.
Final Answer:
file1.txt is moved inside testdir folder -> Option B