Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash find, exclude parent?

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

like image 911
Zombo Avatar asked Jun 17 '12 12:06

Zombo


2 Answers

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
like image 109
Zombo Avatar answered Oct 11 '22 11:10

Zombo


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...

like image 28
siggi Avatar answered Oct 11 '22 10:10

siggi