Moving multiple items in Linux requires just a single command with the right syntax. If you’ve ever wondered how to move multiple files in linux, you’re in the right place. This guide will show you the fastest, safest ways to relocate several files at once using the terminal.
Whether you’re a beginner or a seasoned user, moving files in bulk saves time and reduces errors. Let’s get straight to the practical steps.
Understanding The Basic Move Command
The mv command is your main tool for moving files and directories in Linux. It’s simple, powerful, and works instantly.
Here’s the basic syntax for moving a single file:
mv source_file destination_folder/
For multiple files, you list them all before the destination:
mv file1.txt file2.txt file3.txt destination_folder/
This moves all three files into the target directory. The command doesn’t ask for confirmation, so double-check your paths.
Common Mistakes With The Mv Command
One frequent error is forgetting the destination. If you type mv file1.txt file2.txt without a folder, it renames file1.txt to file2.txt instead of moving it.
Another mistake is using a trailing slash incorrectly. Always include the slash after the destination folder name, like dest/, to avoid confusion.
How To Move Multiple Files In Linux Using Wildcards
Wildcards make moving groups of files incredibly efficient. Instead of typing each filename, you use patterns to match multiple files at once.
The asterisk * matches any sequence of characters. For example, to move all .txt files:
mv *.txt destination_folder/
The question mark ? matches a single character. To move files like file1.txt, file2.txt, but not file10.txt:
mv file?.txt destination_folder/
Square brackets [] match any character inside. To move files starting with a or b:
mv [ab]* destination_folder/
Using Brace Expansion For Specific Files
Brace expansion lets you list multiple patterns in one command. It’s perfect for non-sequential filenames.
Example: move report.pdf, summary.docx, and data.csv at once:
mv {report.pdf,summary.docx,data.csv} destination_folder/
This is faster than typing each file separately and reduces typos.
Moving Files With The Find Command
When you need to move files based on criteria like date, size, or permissions, find combined with mv is your best bet.
To move all files modified in the last 7 days:
find . -type f -mtime -7 -exec mv {} destination_folder/ \;
This finds files in the current directory and moves them one by one. The {} placeholder represents each found file.
Using Find With Exec For Bulk Moves
For large numbers of files, -exec can be slow. A faster alternative is piping to xargs:
find . -type f -name "*.log" -print0 | xargs -0 mv -t destination_folder/
The -print0 and -0 flags handle filenames with spaces correctly. The -t option for mv specifies the target directory first.
Moving Files With Specific Extensions
Often you need to move only files of a certain type. Wildcards make this easy.
To move all .jpg images:
mv *.jpg images/
To move multiple extensions at once, use brace expansion:
mv *.{jpg,png,gif} images/
This moves all JPEG, PNG, and GIF files into the images folder.
Excluding Certain Files While Moving
Sometimes you want to move most files but keep a few. You can use the extglob shell option for advanced pattern matching.
First enable it:
shopt -s extglob
Then move all files except important.txt:
mv !(important.txt) destination_folder/
To exclude multiple files:
mv !(file1.txt|file2.txt) destination_folder/
Remember to disable extglob after if you don’t need it:
shopt -u extglob
Moving Files Between Directories Recursively
When you need to move entire folder structures, use the -r (recursive) flag. This moves directories and all their contents.
mv -r source_folder/ destination_folder/
If the destination folder doesn’t exist, it will be created. Be careful: moving a directory overwrites existing files with the same name.
Moving Only Files, Not Subdirectories
To move only files inside a directory without moving subdirectories, use find with -type f:
find source_folder/ -type f -exec mv {} destination_folder/ \;
This leaves subdirectories intact while moving all files to the target.
Using The Mv Command With Verbose Output
To see what’s happening during a move, add the -v (verbose) flag. This prints each file as it’s moved.
mv -v *.txt destination_folder/
Output example:
renamed 'file1.txt' -> 'destination_folder/file1.txt'
renamed 'file2.txt' -> 'destination_folder/file2.txt'
This is especially useful for debugging or when moving many files.
Interactive Mode To Avoid Overwrites
If you want to be prompted before overwriting existing files, use the -i (interactive) flag:
mv -i *.txt destination_folder/
You’ll be asked to confirm each overwrite. Type y to proceed or n to skip.
Moving Files With Spaces In Names
Filenames with spaces can break commands. Always quote them or use escape characters.
Using quotes:
mv "my file.txt" destination_folder/
Using backslash escape:
mv my\ file.txt destination_folder/
For multiple files with spaces, wildcards still work as long as you don’t have spaces in the pattern itself.
Handling Special Characters In Filenames
Filenames with parentheses, brackets, or ampersands need careful handling. Use single quotes to protect them:
mv 'report (final).pdf' destination_folder/
Tab completion (pressing Tab) automatically escapes special characters for you.
Moving Files Based On Size Or Date
The find command shines when you need to move files by attributes like size or modification time.
To move files larger than 100MB:
find . -type f -size +100M -exec mv {} large_files/ \;
To move files older than 30 days:
find . -type f -mtime +30 -exec mv {} old_files/ \;
You can combine conditions with -a (and) or -o (or):
find . -type f -size +10M -a -mtime -7 -exec mv {} recent_large/ \;
Using Find With Regex For Complex Patterns
For advanced pattern matching, use -regex with find:
find . -type f -regex '.*\.\(txt\|log\|csv\)' -exec mv {} text_files/ \;
This moves files ending in .txt, .log, or .csv. Regex is more flexible than wildcards for complex rules.
Moving Files To Multiple Destinations
You can’t move one file to multiple places with a single mv command. But you can copy then delete, or use a loop.
Using a bash loop to move a file to two folders:
for dest in folder1 folder2; do cp file.txt "$dest/"; done; rm file.txt
This copies the file to both destinations, then removes the original.
Moving Files With A Script For Bulk Operations
For repetitive tasks, write a simple bash script. Save this as move_logs.sh:
#!/bin/bash
for file in *.log; do
mv "$file" archive/
done
Make it executable with chmod +x move_logs.sh, then run it. Scripts save time for daily or weekly moves.
Using The Rename Command For Moving
The rename command can move files while renaming them. This is useful for batch operations.
To move and rename all .txt files to .bak:
rename 's/\.txt$/.bak/' *.txt
This changes the extension but keeps files in the same directory. For moving to a different folder, combine with mv.
Moving Files With Timestamps In Names
To add a date stamp when moving, use a loop:
for file in *.txt; do
mv "$file" "archive/$(date +%Y%m%d)_$file"
done
This prepends the current date to each filename during the move.
How To Move Multiple Files In Linux Using Graphical Tools
If you prefer a GUI, file managers like Nautilus (GNOME), Dolphin (KDE), or Thunar (XFCE) support bulk moves.
Simply select multiple files with Ctrl+click or Shift+click, then drag them to the target folder. Or use Ctrl+X to cut and Ctrl+V to paste.
For remote servers, use SFTP clients like FileZilla or WinSCP to move files graphically.
When To Use GUI Vs Command Line
Use the command line for automation, remote servers, or large numbers of files. Use the GUI for occasional moves or when you need visual confirmation.
Both methods work well; choose what feels comfortable for your workflow.
Common Errors And Troubleshooting
Here are frequent issues and how to fix them:
- “No such file or directory”: Check the source path. Use
lsto verify files exist. - “Permission denied”: Use
sudoor change file permissions withchmod. - “Argument list too long”: For thousands of files, use
findwithxargsinstead of wildcards. - Files overwritten accidentally: Use
-ifor interactive mode or-nto never overwrite.
Using The -N Flag To Prevent Overwrites
The -n (no-clobber) flag prevents overwriting existing files:
mv -n *.txt destination_folder/
This skips any file that already exists in the destination, keeping both safe.
Moving Files With Rsync For Advanced Control
While rsync is primarily for syncing, it can move files with more options:
rsync -av --remove-source-files source/ destination/
The --remove-source-files flag deletes the originals after copying, effectively moving them. Use -n for a dry run first.
Benefits Of Rsync Over Mv
Rsync can resume interrupted transfers, preserve permissions, and show progress. It’s ideal for large file sets or network moves.
For simple local moves, mv is faster and simpler.
Moving Files With A Progress Bar
To see progress during a move, use pv (pipe viewer) with tar:
tar cf - *.txt | pv | tar xf - -C destination_folder/
This shows a progress bar and estimated time. Install pv with sudo apt install pv if needed.
Using Mc (Midnight Commander) For Visual Moves
Midnight Commander is a text-based file manager that runs in the terminal. Install it with sudo apt install mc, then navigate and press F6 to move files.
It’s a good middle ground between CLI and GUI.
How To Move Multiple Files In Linux Safely
Always double-check your command before pressing Enter. Use echo to preview what will happen:
echo mv *.txt destination_folder/
This prints the command without executing it. If it looks right, remove the echo and run again.
Creating A Backup Before Moving
For critical files, make a backup first:
cp -r source_folder/ backup_folder/
mv source_folder/* destination_folder/
This gives you a safety net in case something goes wrong.
Moving Files With Symbolic Links
To move a file and leave a symbolic link behind, use mv with ln:
mv file.txt destination_folder/
ln -s destination_folder/file.txt file.txt
This keeps a reference to the file’s new location. Useful for maintaining compatibility with scripts.
Moving Files While Preserving Hard Links
The mv command preserves hard links by default. If you need to break them, copy first then delete:
cp file.txt destination_folder/
rm file.txt
This creates a new inode, breaking the link.
How To Move Multiple Files In Linux With Different Ownership
Moving files doesn’t change ownership. If you need to change owner after moving, use chown:
sudo chown newuser:newgroup destination_folder/*
This is common when moving files between user directories.
Using Sudo With Mv For System Files
For system directories like /etc or /var, prepend sudo:
sudo mv *.conf /etc/backup/
Be extra careful with system files; a wrong move can break your system.
Moving Files Across Different Filesystems
When moving between partitions or drives, mv actually copies then deletes. This takes longer but works seamlessly.
For large transfers, use rsync to see progress and resume if interrupted.
Checking Disk Space Before Moving
Use df -h to check available space on the