I want to hide some files such that not even ls -a can find it. I'm not talking about adding '.' in front of the filename. I was thinking if I could create separate system calls for accessing those files The actual need is to hide some log files from the user. I'm storing the MAC data of some files and don't want the user to see those log files. At present I know only one way to hide data i.e by adding '.' in front of filename. But the file can be seen by the user by the simple call ls -a. So I want to know if there is any other way to hide those log data?

  • 5
    This sounds a lot like a XY problem. If you need to protect files for legitimate reasons, you should be looking into access control (discretionary or mandatory, depending on the particular use case), not hiding them in some obscure way. – Thomas Nyman May 13 '14 at 7:07
  • 1
    The '.' in front of a filename doesn't hide it. It is just a convention for some commands not to display such files without special options. How do you want the normal system calls not to overwrite the information on disc if they (by your definition) don't know about them. Blocks still need to be allocated and kept track of. – Anthon May 13 '14 at 7:07
  • 2
    You could just delete it, you know ;-) – daniel kullmann May 13 '14 at 7:21
  • @danielkullmann that's not what I asked for – deathholes May 13 '14 at 7:23
  • You should make something clear: whether you want the files to be persistent or be gone after closing them. O_TMPFILE approach is fancy but only works for second case. – ArekBulski Oct 27 '15 at 17:41

As others have noted, if the purpose of this is to hinder access to a persistent file, hiding it is probably the wrong approach. In this case the use of appropriate access control measures or even cryptography, if the application warrants it, might be a solution. On the other hand, creating "hidden" temporary files is a perfectly legitimate use case.

In Linux, since kernel version 3.11 the open() system call supports the O_TMPFILE flag, which can be used to create unnamed temporary files. When this flag is used, the pathname argument to open() is used to specify a directory, under which an unnamed inode is created. However, as the principal use case for O_TMPFILE is, as the name implies, the creation of temporary files, this is not suitable for persistent storage as the file will be lost when the last file descriptor to the file is closed, unless the file is given a name. The file may be given a name with the linkat() system call, unless the O_EXCL flag was specified in addition to the O_TMPFILE, in which case linking the file to the file system is prevented.

The recently added O_TMPFILE functionality is significant because it can be used to provide the following properties to temporary files:

  1. Race-condition free creation.
  2. Automatic deletion when closed.
  3. Unreachable via any pathname.
  4. Not subject to symlink attacks.
  5. No need for the caller to devise unique names.

In addition, the functionality can be used create files that are initially invisible, at which time appropriate file system attributes may be adjusted on the file, before linking it to the file system in one atomic operation. This can be used to avoid certain TOCTOU race conditions.

A drawback with the O_TMPFILE flag is that only a subset of file systems provide support for it. Initially support was provided in the ext2, ext3, ext4, UDF, Minix, and shmem filesystems. XFS support was added in Linux 3.15.

  • Wow, O_TMPFILE, that's beautiful. I'd hadn't seen that one yet (typically do the create, open, unlink, use, close method). Thanks :-) – Patrick May 13 '14 at 13:56

No matter what separation you will do, root will still be able to access it, so you will only have security through obscurity which isn't really safe. If you want to hide access from other users, you can use permission for that. Denying read permissions to file or directory will accomplish what you want.


If you want to prevent other users (including root) from reading your files, you could encrypt them. If you also want to hide the names of the files, you either give them bogus names, or you use an encrypted file container like TrueCrypt. In that case, the files will still be accessible by root when the file system is mounted.

  • 1
    There's also encfs. It's fuse, meaning it can be mounted without root, and without requiring an entry in fstab. It also obscures filenames. And since it's fuse, it can be made inaccessible to root (though root can just su to the user to get access). – Patrick May 13 '14 at 14:00

Security reseacher The Grugq has discovered a technique he calls "FISTing", "Filesystem Insertion and Subversion Technique". His presentations read like he's put filesystems in odd places, like EXT3 journal filees, directory files, and "bad blocks" files. This seems like reccommending security through obscurity, but can you do something like that?

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.