6 ms·
|For example, what combination of shell commands can I use to output the number of files in a directory? Hint: it probably isn't what you think it is, if it's e
by memetomancer 3y ago
|For example, what combination of shell commands can I use to output the number of files in a directory? Hint: it probably isn't what you think it is, if it's even possible.
`find . -type f | wc -l`
- jcynix 3y agoGood first attempt. But: counts two links to the same file twice. That is: touch foo; ln foo bar Is this one file or two "links" to the same file? ;-0
- bandrami 3y agoYou said files, not inodes. Those are two files sharing one inode. If you want to count inodes, specify that in the question.
- deleted 3y ago[deleted]
- jcynix 3y agoI'm not the one who posed the question. And: file, filename, inode, ...? What's what and what's exactly to be counted?
- memetomancer 3y agothe inode is the important thing when all is said and done. It is flexible in that it can contain all the metadata needed to present a file to a process. Sometimes that metadata is a list of blocks in the filesystem. sometimes it points to another inode. I think of it like an old-timey 'card catalog'. You have a bunch of tiny drawers filled with cards. Some of the cards are big and blank spacers with a prominent tab sticking above the normal top edges (Directory). Sometimes you have a card that points to another card elsewhere in the catalog (link). Sometimes you find the details of a specific book on a specific shelf (block data). Point is, they are all cards. The comment essentially asked for a command to say 'how many cards between these two spacers'. It's a "trick" question as old as usenet to spring the distinction between link inodes and list of blocks inodes and say "Ah-HAH!! gotcha", but in reality it's a silly game of jumping levels, misdirecting semantics and prey upon the distribution of understanding in a forum for personal glory. The inode is the item, it is the card that is being counted, no matter what is printed on it. imho.
- preseinger 3y agoabsent further qualifications it is two files
- chias 3y agoThis doesn't work. Try setting up a test directory as follows: touch first$'\n'file touch .hidden$'\n'file mkdir folder$'\n'. touch folder$'\n'./another$'\n'file There are two files in the folder, or three if you want to count files in subdirectories too. Your solution incorrectly outputs 7.