File could be listed using ls but when trying to move using mv the system says no such file. I typed
~$ sudo mv "$(ls -lt /media/cache | grep ^- | head -1 | awk '{ print $9 }')" /media/cache/2
I got
mv: cannot stat 'ea9a1f08ddcf32c6e3cfea3b055d45e1e3690ca75c7bedf1ce938a2fc8bf507e.tmp': No such file or directory
Which could only means that ls could list out this ea9a1f08ddcf32c6e3cfea3b055d45e1e3690ca75c7bedf1ce938a2fc8bf507e.tmp file but mv can't move it. Where did I go wrong?
Your solution doesn't work because the
lspipeline outputs the filename, not the whole file path, somvtries to find that file in the current directory (instead of/media/cache) and fails. Looking at the pipeline, you're trying to select the first file from/media/cachedirectory, and move it to/media/cache/2. This can be achieved using a for loop with a break: