Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make a debian package from upstream source code which is not mine. The configure script provided by author makes a lot of symlinks in source directory. They're symlinks to all headers in src subdir to include subdir (So that makefile can easily copy the include directory in the case of installing development package). I'm using debhelper scripts to make package.

I'm using debhelper scripts to make package. The problem is using new debian package format (quilt 3.0 native), debuild refuses add changes of source directory consisting symlinks to final diff file. I'm getting errors like this:

dpkg-source: error: cannot represent change to foo.h:
dpkg-source: error:   new version is symlink to /ba/foo/foo.h
dpkg-source: error:   old version is nonexistent

I'm aware of the good solution: Change configure script not to symlink any header at all. It should add a target to makefile to install devel package. Though configure script has copyright issues. I can't touch upstream source.

I'm looking for a bash script to replace all symlinks in a directory with actual files they point to. For example if in the directory d there are three files a and b and c, which they ate symlinks to ../../foo/bar/x, ../../foo/bar/z ../../foo/bar/y, running desired script (say giving the ./d as first argument, should

cp ../../foo/bar/x ./d/a
cp ../../foo/bar/y ./d/b
cp ../../foo/bar/z ./d/c

I can't find a way to know which file is a symlink pointing to.

share|improve this question
up vote 4 down vote accepted

Use readlink.

$ readlink /etc/alternatives/editor

and wrap it in a shell script walking over the symbolic links in the directory.

You can find symbolic links using find:

$ find . -type l

A more complete example:


find . -maxdepth 1 -type l | while read LINE; do 
echo link: $LINE resolved: `readlink $LINE`


link: ./.remmina resolved: sparkleshare-homedir/remmina
link: ./project resolved: Documents/2011-2 Project/
link: ./.ssh resolved: sparkleshare-homedir/ssh
share|improve this answer I hope this work for me... – sorush-r Sep 18 '12 at 18:11
Works fine... thanks :) – sorush-r Sep 18 '12 at 18:15
Be sure to do proper escaping though when doing operations. A symlink resolving to bla / bla may expand to this: rm -rf bla / bla. Not sure if your example prevents this, mine doesn't. – gertvdijk Sep 18 '12 at 18:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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