After copying or moving an external folder into a Linux system, use find, realpath, and similar commands to confirm its actual location.
Importing a Folder: Copy or Move?
- Need to keep the original folder: use
cp -rorrsync -av. - Original folder no longer needed: use
mv— faster and avoids doubling disk usage. - Cross-machine or resumable transfer: prefer
rsync; rerunning after a failure skips already-synced files[4].
Note: Before importing, confirm the target directory exists and is writable; double-check the path before running recursive operations on system directories (/, /etc, /usr).
Copying a Folder: cp vs rsync
cp -r source_folder target_dir/
rsync -av source_folder/ target_dir/new_name/
cp -rrecursively copies the entire directory tree — good for one-off imports[1][2].rsync -avpreserves permissions and timestamps, prints per-file transfer status — good for large directories or repeated syncs[4].- Trailing slash matters:
source/copies directory contents;sourcecopies the directory itself.
Moving a Folder: mv
mv source_folder target_dir/
mv only updates directory entries within the same filesystem — nearly instant; across filesystems it degrades to copy-then-delete[3].
Finding a Folder’s Location
Confirm your current location first, then search by name or content.
pwd
realpath .
find / -type d -name "folder_name" 2>/dev/null
pwdshows the current working directory;realpath .prints its absolute path[7].find / -type d -name "folder_name"recursively searches from root for a directory name;2>/dev/nullsuppresses permission errors[5][6].- When you know the rough scope, replace
/with/home,/opt, etc. to narrow the search.
locate can find by name faster, but it depends on a pre-built database:
updatedb --localpaths='/dir/to/search' --output=/tmp/locate.db
locate -d /tmp/locate.db folder_name
updatedb scans the specified directory and builds the database; locate -d reads results from it[9][8].
Rollback
- Copied to the wrong place: delete the imported result with
rm -rf target_dir/imported_folder; the original is untouched. - Moved to the wrong place:
mvthe folder back to its original location. - Search took too long because scope was too broad: narrow the
findstarting directory, or giveupdatedba smaller--localpaths.
Troubleshooting Quick Reference
| Symptom | Cause | Fix |
|---|---|---|
cp: cannot create directory |
Target directory missing or not writable | mkdir -p target_dir and check permissions |
mv: cannot move ... across devices |
Cross-filesystem move | Use cp -r, then delete the source |
find hangs with no output |
Full-disk search from / |
Narrow the starting directory or add -maxdepth |
locate: database not found |
Database not built yet | Run updatedb first |
| Search results don’t match reality | Stale database | Rerun updatedb |
Verified on
- Tested environment: WSL2 Ubuntu 24.04.4, GNU coreutils 9.4, findutils 4.9.0.
- Verified:
cp -rcopying directory trees,rsync -avincremental sync,mvmoving directories,pwd/realpathprinting absolute paths,findby-name search,updatedbgenerating a database,locate -dreading from that database. - Limitations: cross-filesystem moves on NFS/SMB mounts not tested; SELinux environments not tested; default system database update policy for
locatenot tested — only custom databases verified.
FAQ
Q: Imported a folder but can’t find it — where might it be? Run pwd to confirm your current directory, then search with find /home -type d -name "folder_name" to limit scope.
Q: cp -r or rsync -av? Use cp -r for one-off imports; use rsync -av for large directories, network transfers, or resumable syncs.
Q: find too slow? Limit depth with -maxdepth, or change the starting directory from / to /home, /opt, or another known scope.
Q: Why can’t locate find a freshly imported folder? locate reads a database snapshot; rerun updatedb after importing to make it searchable.
References
- [1] cp(1) – Linux manual page (man7.org) (man7-cp)
- [2] cp(1) – Ubuntu 24.04 manual page (ubuntu-cp)
- [3] mv(1) – Linux manual page (man7.org) (man7-mv)
- [4] rsync(1) – Linux manual page (man7.org) (man7-rsync)
- [5] find(1) – Linux manual page (man7.org) (man7-find)
- [6] find(1) – Ubuntu 24.04 manual page (ubuntu-find)
- [7] realpath(1) – Linux manual page (man7.org) (man7-realpath)
- [8] locate(1) – Linux manual page (man7.org) (man7-locate)
- [9] updatedb(1) – Linux manual page (man7.org) (man7-updatedb)
Key commands in this article were tested on WSL Ubuntu (24.04) and cross-checked against Debian-family and general-distribution documentation.