Why I can not give the 'ln -s' command an operand through out the command sub $(ls ../*.txt)?

51 Views Asked by At
ln -s $(ls ../*.txt)

When I do the command above it replay with an error message saying : "ln: target '../foo.txt' is not a directory".

foo.txt is the first file that ls command has found in the parent dir.

I am trying to make symbolic links for all the files in the parent directory which ends with ".txt".

Can you please explain why my command did not work ?

1

There are 1 best solutions below

0
Barmar On BEST ANSWER

You forgot the directory name to put all the links into. If you want them put into the current directory, use ..

There's also no need to use ls, and you'll get the wrong results if any of the filenames contain whitespace or wildcard characters, because those will be processed in the $(...) output. Just use the wildcard directly.

ln -s ../*.txt .