How to create hidden files in Linux?

2020-04-16 05:19发布

In my program I have to create a hidden file in order to avoid remove or modification of file.

PATH=/etc/
NAME = file

Is there is function in c which allow to do that ?

Thanks.

8条回答
三岁会撩人
2楼-- · 2020-04-16 06:09

In LINUX Hidden file are start with .(DOT)

if you create files with starting .(DOT), those files are hidden.

You can use chmod to set permissions to the file.

if you set only read only then those cannot be modified in program

chmod 444 filename

if you want to use this from C-language use system() function to execute this command

if You use simple ls -alF you can see those files.

the below files are hidden files In LINUX

-rw-------  1 root root   27671 Sep 17 11:40 .bash_history
-rw-r--r--  1 root root    3512 Jul 23 16:30 .bashrc
查看更多
劫难
3楼-- · 2020-04-16 06:10

There are no hidden files on Linux. Some tools don't show files starting with . as others already mentioned.

Anyway, you can experiment with putting control characters like new-line into the filename. See Control characters in filenames are a terrible idea:

Some control characters, particularly the escape (ESC) character, can cause all sorts of display problems, including security problems. Terminals (like xterm, gnome-terminal, the Linux console, etc.) implement control sequences. Most software developers don’t understand that merely displaying filenames can cause security problems if they can contain control characters. The GNU ls program tries to protect users from this effect by default (see the -N option), but many people display filenames without getting filtered by ls — and the problem returns. H. D. Moore’s “Terminal Emulator Security Issues” (2003) summarizes some of the security issues; modern terminal emulators try to disable the most dangerous ones, but they can still cause trouble. A filename with embedded control characters can (when displayed) cause function keys to be renamed, set X atoms, change displays in misleading ways, and so on. To counter this, some programs modify control characters (such as find and ls) — making it even harder to correctly handle files with such names.

查看更多
登录 后发表回答