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

  • missing files, you mean moved to some arbitrary directory or you are talking about deleted files? or maybe you just want a list that warns you, that in this sequential logic, this file is missing? – Luciano Andress Martini Mar 25 '19 at 15:25
  • yes, I just want a list that warns me, that in this sequential logic, this file is missing, thanks – kutlus Mar 25 '19 at 15:28
  • If I suggest a shell script is enough for you? Or you really want a single command? – Luciano Andress Martini Mar 25 '19 at 15:30
  • I don't have experience with the shell script, a single command on the terminal would be great, thanks again – kutlus Mar 25 '19 at 15:34
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
| improve this answer | |
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....

| improve this answer | |
  • 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
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.

| improve this answer | |
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)
| improve this answer | |
  • Can you explain a little bit, everything is bouncing off my head? – Prvt_Yadav Mar 25 '19 at 15:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.