File: lndir.sh

package info (click to toggle)
quotatool 1.4.10-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 616 kB
  • ctags: 367
  • sloc: ansic: 1,790; sh: 1,782; makefile: 123
file content (39 lines) | stat: -rw-r--r-- 884 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh

# very small shellscript that more or less implements the lndir of xutils-dev
# it recursively links all files from the directory specified in the first
# argument to the directory in the second argument;

# it probably won't work for exotic filenames

set -e

# need 2 arguments
test -n "$1" || exit -1
test -n "$2" || exit -1

FROM=$1
TO=$2

# check that both arguments are directories
test -d $FROM  || exit -1
test -d $TO || exit -1

# convert the dirs to absolute pathnames
FROM=$( cd $FROM && pwd )
TO=$( cd $TO && pwd )

# check that the dirs are not the smae
test "$FROM" = "$TO" && exit -1

# make a directory structure
( cd $FROM && find -type d \! -name '.' \! -name '..' -print0 ) | ( cd $TO && xargs -0 mkdir )

# make links to regular files
( cd $FROM && find -type f -print ) | \
while read file; do
	#echo $file
	ln -sf $FROM/$file  $TO/$file
done;

exit 0