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?
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 done
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.