1

I have a dir contains several sub-dirs:

./abc/
./cde/
./link_to_abc -> ./abc

abc and cde is normal directories, but link_to_abc is a soft link whose target is abc.

now I want to use linux's find command to find normal dirs without soft links, in my case, it is cde. how to do it?

because I need to delete some dirs, but I should check nobody use my files anymore(no other symbol link point to my dirs)

user2848932
  • 776
  • 1
  • 14
  • 28
  • 1
    `find` in isolation cannot know whether a symbolic link somewhere else in the file system points to a file. You cannot avoid the brute force approach -- find all directories, find all symlinks, remove symlink targets from list of directories, print the rest. – tripleee Jan 18 '16 at 12:25
  • really .... @tripleee – user2848932 Jan 18 '16 at 12:26
  • Is that a serious question? Yes, that is really the case. – tripleee Jan 18 '16 at 12:40

2 Answers2

3

The following solution uses more than a single find but should work:

# step1: list all directories:
$ find /absolute/path -type d | sort > real_dirs.txt
# step2: list all files "pointed" by a symlink:
$ find /absolute/path -type l -exec readlink -f {} \; | sort > sym_dirs.txt
# step3: get directories not "pointed" by symlinks:
$ comm -23 real_dirs.txt sym_dirs.txt 
mklement0
  • 382,024
  • 64
  • 607
  • 775
mauro
  • 5,730
  • 2
  • 26
  • 25
1

use find ! -type l or find -type d

Check this answer https://stackoverflow.com/a/16303559/3343045

Community
  • 1
  • 1
averello
  • 114
  • 1
  • 5
  • because I need to delete some dirs, but I should check nobody use my files anymore(no other symbol link point to my dirs) – user2848932 Jan 18 '16 at 12:30
  • 1
    This finds directories which are not symlinks; not directories which do not have a symlink anywhere to them. – tripleee Jan 18 '16 at 12:39