1

Is there any command line to see the missing files on Linux. I have a list of files start from 000 to 073 in the terminal folder on MobaXterm. But as you see in the picture below 070 is missing. Thanks

enter image description here

kutlus
  • 345
  • 2
  • 6
  • 19

4 Answers4

1
cd yourfolder
    for file in {001..099}; do
       [ -e "$file.mat" ] && echo $file.mat || echo "Warning: $file.mat is missing"
    done 

Change 99 to the number of files you are expecting....

  • This gives all files are missing; Warning: 001.mat is missing Warning: 002.mat is missing Warning: 003.mat is missing Warning: 004.mat is missing Warning: 005.mat is missing Warning: 006.mat is missing Warning: 007.mat is missing Warning: 008.mat is missing ..... thanks – kutlus Mar 25 '19 at 15:39
  • @kutlus Are you running this in the folder with the files? e.g. cd folderwiththefiles . I tested here and it is working fine. – Luciano Andress Martini Mar 25 '19 at 15:40
  • 1
    Thank you, yes in the folder it worked, but it prints also all the existing files together with the warning for the missing file. For the very large number datasets, I prefer just to print the missing files. But I voted for you, thanks for your help – kutlus Mar 25 '19 at 15:51
1

This commands check if a file exists:

test -f file
[[ -f file ]]

You can echo a message based on the return value of those:

test -f file || echo file does not exist

To check many files, you can use a for loop:

for f in {000..073}.mat ; do
    [[ -f $f ]] || echo $f does not exist
done

Or as oneliner:

for f in {000..073}.mat ; do [[ -f $f ]] || echo $f is missing; done
ctx
  • 2,495
0

If you know the upper limit of files then:

for i in {000..074}
  do
  if [ -f "$i.mat" ]
  then
    echo "$i.mat exists"
  else
    echo "$i.mat doesn't exists"
  fi
done

You can modify the echo commands according to your wish.

Prvt_Yadav
  • 5,882
0

With the zsh shell:

files=(<->.mat)
expected=({000..073}.mat)

missing=(${expected:|files})
printf ' - %s\n' $missing

For files with simple names like that, you could use also use comm (here using the ksh, zsh or bash shell):

comm -13 <(ls) <(seq -f '%03d.mat' 0 73)