1

I have a directory with a bunch of images. Going there with the GUI and pressing CTRL+A (selecting all files) it counts 5058 images. Doing `ls . | wc -l files it counts 5060 files.

I have the suspsect that the "missing files" are images, otherwise a program that I'm using on it would have returned an error message (and it counts 5060 files too).

  • Do you have a file with newline in the name? – heemayl Jan 22 '17 at 14:15
  • The files are from a dataset, I don't really now. But I suppose not. – user6321 Jan 22 '17 at 14:16
  • Whats the output of ls *$'\n'*? – heemayl Jan 22 '17 at 14:17
  • No such file or directory – user6321 Jan 22 '17 at 14:18
  • 1
    Do you have ls aliased to ls -A or ls -a by any chance? what do you get if you use \ls . | wc -l or command ls | wc -l? – steeldriver Jan 22 '17 at 14:38
2

Hidden files can be shown using the GUI or the cli.

Using the GUI way, in Nautilus (file manager) hit ctrl+h to see all files, including the hidden files (filenames that begin with a period).

Hidden files can be metadata files, or image catalog files, or even application preferences... and they're hidden because they don't contribute to the general listing of image files that you have.

In the command line way, it's the difference between the ls command, and the ls -a command. The latter one shows the hidden files too.

  • While this answer certainly addresses how to show hidden files, it doesn't address the why there is a discrepancy between output of ls and GUI. – Sergiy Kolodyazhnyy Jan 22 '17 at 17:26
  • @Serg sure it does... because of hidden files whose filenames begin with a period... like metadata files, or image catalog files, or app pref files, etc. The OP wanted to know if cli was the only way to see these files. And the OP upvoted me 'cause it WAS the answer. – heynnema Jan 22 '17 at 17:28
  • @Serg please restore my up vote. – heynnema Jan 22 '17 at 18:05
  • I cannot, the vote is locked for me. I still think you should improve your post, because it's not exactly what OP wants. The core of the issue is that they have discrepancy between GUI and command-line listings of files – Sergiy Kolodyazhnyy Jan 22 '17 at 18:08
  • See imgur.com/a/3WquM – Sergiy Kolodyazhnyy Jan 22 '17 at 18:08
0

If your ls command is aliased to ls -a or ls -A, its output includes two extra items , . and .. , which refer to directory itself . and its parent (..), as well as other files that start with leading . , so there's your difference from 5058 and 5060 files. They don't show up in GUI file manager simply because it's build that way, however most Unix applications are build to recognize the existence of those two.

Additionally, please never use ls | wc -l to count files. Parsing output of ls has a lot of issues, and it's a practice that is generally best to be avoided. If you need to count files in a directory via command line, please see Why does `ls -l` count more files than me? for proper methods.

In this specific case, I'd recommend you use find -maxdepth 1. find prints all of the files and directories, and does not hide those files or directories that begin with leading .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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