When I try to do fun cli stuff to move files around etc, I have issues when the file has a space or strange characters in it. Take the following for exampe:
cp -r `ls -trbQ |tail -15 |grep tmp -v` tmp
I would expect this to move the last 15 files into a directory i just create called tmp.. however i get:
cp: cannot stat `"Violent': No such file or directory
A work around is to ls -trbQ |tail 15 >file
and then run a while loop around to wrap each line in the file with the cp command for example, and then run the file as a script
Is there some flag i'm missing on ls that will return a filename on the cli that has the correct special characters so cp can find it?
I'm only using cp as an example there are several cases where I want to find the last few files/directories and do "stuff" to them. They always seem to have wonky filenames.