Friday·10·June·2011
How to find broken symlinks //at 20:31 //by abe
Looking through the man page of find
there is no obvious
way to find broken symbolic links. But there is a simple way involving
only find:
$ find -L . -type l $ find -L . -type l -ls
The option -L
(before the path!) causes find
to follow symbolic links and the expression -type l
causes find to report only symbolic links. But as it follows symlinks,
it only reports those it can’t follow, i.e. broken ones.
The second line also shows where the broken links point to.
To easily show that this really works, just use the color indicator of
GNU ls instead of find
’s builtin -ls
:
$ find -L . -type l -exec ls -lF --color=yes '{}' +
Et voilà, all displayed links show up in red which means they’re broken.
Kudos to CodeSnippets for showing me the right
idea. And thanks to ft of zsh and grml fame for the hint about
find -exec command {} +
instead of find -exec
command {} ;
.
Hint from mika of grml fame: With zsh it is even less code to type:
% ls **/*(-@) % ls -lF **/*(-@)
Thanks, mika!
Tagged as: CLI, coreutils, find, GNU, HTH, ls, POSIX, shell
7 comments // show without comments // write a comment
Related stories
How to move a git submodule //at 20:31 //by abe
If you try to move a git submodule with git mv
, you’ll
get the following error message:
$ git mv old/submodule new/submodule fatal: source directory is empty, source=old/submodule, destination=new/submodule
There’s a patch against git to supoort submodule moving, but it doesn’t seem to be applied yet, at least not in the version which is currently in Debian Sid.
What worked for me to solve this issue was the following (as posted on StackOverflow):
- Edit .gitmodules and change the path of the submodule
appropriately, and put it in the index with
git add .gitmodules
. - If needed, create the parent directory of the new location of the
submodule:
mkdir new
. - Move all content from the old to the new directory:
mv -vi old/submodule new/submodule
. - Remove the old directory with
git rm --cached old/submodule
.
Looked like this for me afterwards:
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: .gitmodules # renamed: var/lib/dokuwiki/tpl -> var/lib/dokuwiki/lib/tpl #
Finally commit the changes. HTH.
Tagged as: Debian, git, HTH, move, Sid, submodule
2 comments // show without comments // write a comment