Running Ubuntu, I open a terminal and dosudo bashcd /ls | head -n 1000And predictably about 20 directories are returned. However, if I do an ls, and don't pipe it into anything, the ls just hangs there until I kill it from another terminal. What could be happening? EDIT:> type lsls is aliased to `ls --color=auto`EDIT:> /bin/ls /<normal response>> /bin/ls --color=auto<hangs indefinitely>Why is coloring the output of ls causing this command to hang?
ls taking long time in small directory
shell;command line;files;ls
If you run ls normally, it will just show the list of files without needing to run stat(2) on any of them.  In other words, it doesn't access the FILES themselves, but only the directory that contains the files.If you add in the --color option, or use other ls options that need to examine the files themselves, then ls will need to stat(2) those files.Most likely at least one of the files in your directory are actually being mounted from a remote system, via NFS or similar.  And the server that you've mounted that partition from is not up or not responding.  So, when ls tries to get the information about that directory it will hang in the kernel waiting for the server to respond.As others have mentioned, if you use strace you'll find out which directory ls is trying to access when it hangs.  Then you can umount that mounted partition or whatever.