user3475244
user3475244

Reputation: 11

Find the original file for a series of soft-linked files

How would I write a bash shell script that finds the original file for a series of soft-linked files? For example, if I had 5 files in a directory and named file1 through file5. File2 is linked to file1, file3 is linked to file2, file4 is linked to file3, and file5 is liked to file4. In this case, the original file is file1.

I want the script to search for the file in the current directory, not providing the path.

If there is no symlink then display message saying so

if there is a symlink then should display the original file, and names of the symlinked files: eg file is file1. Symlinked files are: file2, file3, file4. file5.

Upvotes: 1

Views: 143

Answers (1)

Bruce K
Bruce K

Reputation: 769

for f in *
  do test -L $f || echo $f ;
done

Upvotes: -1

Related Questions