linuxbashcommand-lineln

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


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 ?


Solution

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