Question
The closest and only answer I saw is: ipfs add -r {folder-name}
But it adds the whole folder to IPFS (but you don’t want to really add, but simply to get its CID) and displays all CIDs from all files.
A better command I came with is ipfs add -qr --only-hash {folder-name}
, because it only gets the CID instead of adding all the files; but, still, it outputs all CIDs instead of only the folder’s CID you want.
Working answer
How to display the CID of a folder:
ipfs add -qr --only-hash {folder-name} | tail -n 1
Display base32/CID v2 of a folder:
ipfs add -qr --only-hash {folder-name} | tail -n 1 | ipfs cid base32
Updated answer by @Jorropo
How to display the CID of a folder:
ipfs add -Qr --only-hash {folder-name}
Display base32/CID v2 of a folder:
ipfs add -Qr --only-hash {folder-name} | ipfs cid base32
Bonus
Display the CID of a single file:
ipfs add -q --only-hash {file-name}
Display the base32/CID v2 of a single file:
ipfs add -q --only-hash {file-name} | ipfs cid base32