Bash find, exclude parent?
Asked Answered
V

2

14

I have a folder with some dotfiles I would like to make symlinks for. I cannot see an easy way to do this.

ls -a ~/dotfiles will include the dotfiles, but also . and ..

find ~/dotfiles -maxdepth 1 will include the dotfiles, but also ~/dotfiles

Vexillum answered 17/6, 2012 at 12:56 Comment(0)
V
33

Based off MvanGeest’s comment this appears to work.

find ~/dotfiles -maxdepth 1 -mindepth 1

This looks to do the job as well

ls -A ~/dotfiles
Vexillum answered 17/6, 2012 at 13:31 Comment(2)
+1 I was about to post an answer with ls's -A option until I saw this.Inceptive
@StevenPenny I was using BSD find rather than GNU find, you are right, and I'll change my scripts accordingly. Thanks for pointing that out.Postboy
R
1

Looks like you're trying to find dot files, ie. Files that start with a "." and have a second character that is not a ".". This should do the job:

find . -name '.[^.]*'

to link all found files to /path/to/dir:

find $PWD -name '.[^.]*' -exec ln -s '{}' /path/to/dir \;

Note that "$PWD" produces an absolute path, as symlinks to relative paths will most likely point into nirvana...

Romilda answered 17/6, 2012 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.