My motivation to ask this question is the following, one purpose of creating a symbolic link is to save space, but a simple mv command to move a directory elsewhere moves everything to the target location, treating a symbolic link as a complete file. This could eat up a tremendously large but unnecessary space when I back up my files. My question is, is there a way to move only true files but leave symbolic links as is?

  • find . -type f will give you only list of files but not symlinks
    – Rahul
    Jul 26 '16 at 5:37
  • 2
    Are you sure? I tried to mv a link to a directory and it is moved as is, the link is moved instead of the content of the directory.
    – fikr4n
    Jul 26 '16 at 6:44
  • 3
    how are you "moving" the files, and how is that considered to be a "backup"?
    – Jasen
    Jul 26 '16 at 8:31

You could use rsync

rsync -l original_file backup_file

From man rsync

-l, --links copy symlinks as symlinks

I.e. you are copying the link only and not what it points at. Note that this is not moving, but copying, but I assumed that is what you meant for backups.


Instead of making symbolic link you can make hard link so if you move the original file somewhere else or delete it, the hard link still works. But there are some limitations, for example it's limited to files so it cannot be pointed to directories. Second, Links can be created only among files included in the same file system.

Anyway, If you choose to use symbolic links after moving the source file you should again give the complete path to your links since it is only a pointer to another filename.


You can use the shell test operator -L to test if a file is a symbolic link. If you're using something like mv *.txt elsewhere/ to move files, then you can skip symbolic links with a loop:

for x in *.txt; do
  if ! [ -L "$x" ]; then mv -- "$x" elsewhere/; fi

Alternatively, you can call find to act on files based on their type. This is mostly useful when you're traversing directories recursively. Note that when you pass a directory to mv, it moves the directory as a whole, which indirectly affects all files underneath.

I fail to see what this has to do with “tremendously large but unnecessary space” in backups. This thread may not be relevant for your actual problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.