Last Updated: February 25, 2016
·
921
· janosgyerik

Find the longest path on your OS

Somebody asked me today:

Is there a command to run to find the longest path + filename on your OS?

This should do it in UNIX and similar:

find / | awk '{print length($0), $0}' | sort -n | tail

Or, a faster but less accurate way, if you have the locate command:

locate / | awk '{print length($0), $0}' | sort -n | tail

Of course, you can only find paths that your user has read permission for.

In Windows, using Git Bash, for drive C: and D: and E::

find /c /d /e | awk '{print length($0), $0}' | sort -n | tail

However, this might not work for very long paths (> 260), due to a limitation in the Windows API.

2 Responses
Add your response

Shouldn't locate . be locate /?

over 1 year ago ·

@hobarrera yes, well spotted! Thanks!

over 1 year ago ·