January 12, 2017

Adding a text property to a file

Hi, I'm absolutely a beginner in Linux and my question might be odd. Is there any way to add a piece of text as a hint to a file's properties? I'm looking for a way to add a short description to my files to make me able to recognize their content when using ls command or in a window. ( not looking for a piped grep) thank you



Answer to the question

Thank you, I think this getter/setter system can be really helpful :)

Like  (0 likes)

Answer to the question

I wouldn't say "absolutely a beginner" since you know about piping the grep command. Good for you.


The short answer (in my opinion) is no, you can't add a text property that will display with the ls command. However, you can use Extended File Attributes on a file to include a "user comment". This is cumbersome, and you have to use "setfattr" (set file attribute) to set the text and then use "getfattr" (get file attribute) to read it. You can also set "root comment" if you are root, but you have to also be root to read them. Here is a nice article that gives some examples: http://www.linux-mag.com/id/8741/


In my own simple world, I just use the filename to accomplish what you are asking. When I use ls in my home directory and see savings_account.ods -- I know that is my bank savings spreadsheet. Or This_is_the_current_novel_I_am_writing.rtf -- you get the idea.




Like  (1 like)
Click Here!