首页 > Sysadmin > 正文

Import a Folder into Linux and Find Its Location

2026-11-03 Sysadmin

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 -r or rsync -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 -r recursively copies the entire directory tree — good for one-off imports[1][2].
  • rsync -av preserves permissions and timestamps, prints per-file transfer status — good for large directories or repeated syncs[4].
  • Trailing slash matters: source/ copies directory contents; source copies 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
  • pwd shows 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/null suppresses 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: mv the folder back to its original location.
  • Search took too long because scope was too broad: narrow the find starting directory, or give updatedb a 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 -r copying directory trees, rsync -av incremental sync, mv moving directories, pwd/realpath printing absolute paths, find by-name search, updatedb generating a database, locate -d reading from that database.
  • Limitations: cross-filesystem moves on NFS/SMB mounts not tested; SELinux environments not tested; default system database update policy for locate not 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

Key commands in this article were tested on WSL Ubuntu (24.04) and cross-checked against Debian-family and general-distribution documentation.