Important Update: Cohesity Products Knowledge Base Articles


All Cohesity Knowledge Base Articles are now managed via the Cohesity Support Portal: https://support.cohesity.com/. The Knowledge Base articles available here will not reflect the latest information or may no longer be accessible.

ls command taking very long time to list the files.

Article: 100049222
Last Published: 2020-12-23
Ratings: 1 0
Product(s): InfoScale & Storage Foundation

Problem

ls command taking very long time to list the files.  This is observed particularly with huge number of files in a folder.

Error Message

- In the problem folder.

# time ls
real 15m38.233s
user 0m1.135s
sys 0m10.685s

 

Cause

- strace on this process showing the below system calls. 

# strace -c -p 30856
strace: Process 30856 attached
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
99.32 9.130288 215 42497 lstat      <<<<<<<<<<<<
0.54 0.049749 2 23144 write
0.13 0.012314 118 104 getdents
0.00 0.000292 7 40 brk
0.00 0.000156 52 3 mremap
0.00 0.000009 3 3 close
0.00 0.000009 5 2 mmap
0.00 0.000000 0 1 fstat
0.00 0.000000 0 1 munmap
0.00 0.000000 0 36 rt_sigaction
0.00 0.000000 0 1 ioctl
------ ----------- ----------- --------- --------- ----------------
100.00 9.192817 65832 total


The color command causes a stat() of every file to discover its type. Reducing the amount of calls to the filesystem reduces the time taken to list the files. This is particularly seen with high number of files in a folder. 


# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'     <<<<<
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' 


Solution:

Tried the ls command without color option and seen a drastic change in the results. It completed in seconds. 

# /bin/ls 
or 
# unalias ls 

Was this content helpful?