Search code examples
linuxunixrm

Removing oldest file in directory with spaces in name


Hi everyone I'm trying to remove a file in a directory that has spaces in the name I'm currently trying to do this

rm `ls -t1 | tail -1`

only problem I have is that I can't remove the oldest file if it has spaces in the name

Is there a work around this?

Thanks!


Solution

  • rm "$(ls -t|tail -1)"
    

    (The 1 argument to ls isn't needed.)