Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 want to find out which file links exist that point to my /tmp folder on Ubuntu.

I had a problem, that my /tmp folder privileges were changed by some accident to 755. The system wasn't running correctly any more as a user other than root.

Maybe there is a link to /tmp somewhere and the command

chmod 755 . -Rf 

called there in that folder was affecting the main /tmp folder.

I had to repair it with:

chmod 777 /tmp
chmod +t /tmp
sudo chown root:root /tmp

I have only one file system, so there shouldn't be a problem with that.

share|improve this question

migrated from Sep 25 '12 at 12:05

This question came from our site for professional and enthusiast programmers.

Your system might have been rooted. – Basile Starynkevitch Sep 22 '12 at 8:14
up vote 2 down vote accepted

try this:

find / -path /proc -prune -o \( -lname '*/tmp' -o -lname '*/tmp/' \) -exec ls -l {} \;

Sample output:

# find / -path /proc -prune -o -lname '*/tmp' -exec ls -l {} \;
lrwxrwxrwx. 1 sergey sergey 4 Sep 22 11:27 /home/sergey/xxx/tmp -> /tmp
lrwxrwxrwx. 1 root root 10 Jun 20 10:28 /usr/tmp -> ../var/tmp
find: `/run/user/sergey/gvfs': Permission denied
share|improve this answer
that gives lots of errors – rubo77 Sep 22 '12 at 7:27
yes, of course. run it as root. – Serge Sep 22 '12 at 7:28
Yes i did run it as root. /proc seems to be the problem – rubo77 Sep 22 '12 at 7:31
I modified the command - now it skips the /proc tree – Serge Sep 22 '12 at 7:37
that's sometimes! working, but it finds other tmp symlinks like /var/www/someapp/html/tmp -> ../tmp – rubo77 Sep 22 '12 at 7:43

As far as I know, there is no easy way to list all symlinks pointing to an inode. Therefore I would recommend using the standard find utility with the -L and -samefile switches:

  • -samefile will compare based on the inode of your target file,
  • -L will include symbolic links in the search, which is what you are looking for.

Here is an example with /bin/dash in /bin:

$ find -L  /bin -samefile /bin/dash -exec ls -lhi {} \;
786515 lrwxrwxrwx 1 root root 4 Mar 29  2012 /bin/sh -> dash
786436 -rwxr-xr-x 1 root root 108K Mar 29  2012 /bin/dash

From this output, you can see both with the inode number (first column) and the arrow (last one) that /bin/sh in a symlink to the /bin/dash. If they were hardlinks, inode number would be the same for different files and there would be no arrow in the last column.

Finally, If I had the need to look for these links on a whole filesystem, I would exclude some directories such as /dev, /proc and /sys from the search. This would be done with the -path and -prune swicthes (you can add as many as you want with -o switch meaning or), 2>/dev/null is here to mask potential errors:

$ sudo find -L  / \( -path /dev -o -path /proc -o -path /sys \) -prune -samefile /bin/dash -exec ls -lhi {} \; 2>/dev/null

As searching in a entire filesystem can take a lot of time (mainly depending on its size) I will consider this option as a last resort. It is like searching a needle in a haystack: it is not impossible but takes a lot of effort...

share|improve this answer

I found the answer, thanks to this question: Linux: Find all symlinks of a given 'original' file? (reverse 'readlink')

find / -exec ls -ald {} ';' 2>/dev/null | grep '\-> /tmp' |grep -v /proc/
share|improve this answer
This will produce the result you are looking for but it will be much slower than solution proposed by me as it will exec ls command for each any file it find, while my solution executes ls only for sym links that ends up with '/tmp' suffix – Serge Sep 22 '12 at 7:33

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.