David542 David542 - 4 months ago 25
Bash Question

How to remove X files in unix

How would I do the following command? This is the following pseudocode I have:

ls -U | head -4 < rm *


I want to delete the below four files

ubuntu@ip:/tmp$ ls -U | head -4
c9e5aff2-f4f6-459e-9752-466625165fa0.jpg
815626f8-2650-4596-94b9-796a82780390.jpg
b9259a6b-b421-4b64-ba4d-72fd632703a3.jpg
78c243e7-43df-417d-9dcf-a4578f1c1f20.jpg

Answer

xargs should do the trick:

$ ls -U | head -4 | xargs rm