3 ms·
Can anybody explain to me why this command can return instantly but "lsof -i" sometimes takes ages to complete?
by comboy 9y ago
Can anybody explain to me why this command can return instantly but "lsof -i" sometimes takes ages to complete?
- jakeogh 9y agoyou need -n, otherwise it's trying to RDNS the IP's. It's a dumb default... chatting on the network without you asking while at the same time censoring the data the kernal was using... similarly "ls" might take forever (which matters if it's a big folder and you are piping it's output or just want |head) because it wants to sort (use -f to fix). The ls is a sensible default, often it's for human consumption, and the sort is way faster than a bunch of DNS lookups that could take an arb long time. lsof has a good case to join coreutils.
- comboy 9y agothanks!
- ktpsns 9y agoA similar issue as with the "-n" flag for netcat exists for "ls": Frequently "ls" is aliased by default in users home directories: $ type ls ls is aliased to `ls --color=auto' On slow file systems (for instance, think of shared machines with large directories, NFS and heavy load) this can take ages to give output. Instead, if you just call /bin/ls, this call only calls http://man7.org/linux/man-pages/man3/readdir.3.html http://man7.org/linux/man-pages/man3/readdir.3.html and thus gives output promptly.
- kbenson 9y agoI've seen \ls used to get the unaliased system version of ls. Likely useful for those commands where you don't want the aliased version and aren't sure if they live in /bin or /usr/bin.
- ssebastianj 9y agoNice, didn't know about "\ls"! I wonder what's the difference between "\ls" and "command ls". Yes, it's a bit longer to type but the output is the same, I'm asking about what happens behind the scenes.