Is there any program that can tag folders? I have different files within a folder and there are to many folders, if I could tag each folder (contrary to tag each file) then it would be very easy for me to categorise these folders. Does anyone knows if such thing can be done? Thank you.


Solution 1:

It is a great question, and I was looking for something like that too, but I'm pretty sure there is nothing like that already built into Nautilus,

but if you can turn your hand to some scripting, you could relatively easily adapt Nautilus file Notes to do something similar. It would require some basic(+?) scripting..

With file Notes you can add Notes to a Directory as well as files..

It would be a simple matter of searching the Notes for your specific Tag(s), and then create tempory links (or permanent) to each directory with a matching Tag in the 'Notes`... then put these links into a 'search results' directory... which you would then present in a Nautilus window!...

If I had the spare time, I'd do it myself, but instead, here is a script I wrote to access and write and delete Nautilus Notes.. It doesn't do what I described above, but it does show how to access the Notes data cache. The script is intended for use by nautilus-actions

The script is at pastbin.ubuntu.com


UPDATE: I've now written a working script which uses links as described above.. However, I've now swapped the "nautilus Notes" idea and grafted in user unknown's .tag files instead.. (so, if you like the script, remember that the .tag idea is 'user unknown's)..
I like plain text files (they are simple and versatile and very easy to work with)
I've used locate as the search tool, as it is ultra fast, but it is only as up-to-date as the last running of updatedb(which is typically daily, but you can run it any time).

I've attempted to explain the script's usage in the comments, but I should point out that it's not fully tested, so it may misbehave on some minor points..
The only things it deletes/removes are the temp directory and any soft-links it contains... Note that removing soft-links does not remove the target/data directories.

Here is the script

UPDATE2: (fixed a bug.. It was only processing the first 100 located .tag file)

#!/bin/bash

# Script: dirtags ...(by fred.bear)
#
# Summary: Open the file browser in a temporary directory
#          which contains soft-links to directories whose     
#          '.tag' file contains the search string in $1
#
# .tag files are files you create in any directory which 
#      you wish to *tag*.
#
# .tag files are simple free form text, so you can 
#      put anything you like in them...  
#
# The script uses `locate` to create a list of .tag file
# 'locate' is very fast, but because it depends on 'updatedb'  
# for its list of current files, it can be a bit out of sync 
# with a newly added .tag file... Modifying an existing
# .tag file does not effect `locate`
# To refresh the `locate` database, just run 'sudo updatedb'
#  .. (updatedb typically auto-runs once a day, but you should check)
#
# Note: The search result soft links are put into a temporary directory
#   This directory is removed each time you run the script 
#   TODO: allow saved searches (?) maybe
#
# Note: With nautilus, running the script a second time while 
#   the previoulsy opened wiondow is still open, cause the 
#   second window to open in its parent directory: /tmp/$USER
#   ... but you can then just enter the 'dirtags' dir 
#       you see listed /tmp/$USER/$bname 
#       TODO: this probably happens because currently the
#         directory is being removed each time the script
#         is run...  (related to "allow saved searches")                    
#
# A sample usage of this script:
# 
#   1.  Make a  '.tag' file in each of several test directories.
#   2,  For this first-time test, run 'sudo updatedb' so that the   
#       newly added  .tag files are added to the 'locate's database
#   3.  In each .tag file, put some tags (words or phrases to serch for)
#          eg; action comedy drama good bad sci-fi  documentary 
#   4.  Run this script with a single argument.. (a grep regex) 
#          eg "action|comedy" 
#  


function args_grep_links {
  # $1 -- the grep regex
##echo grep -l '"'$1'"' ${tagged[@]}
  < <(eval grep -l '$1' ${tagged[@]}) \
      sed "s/^\(.*\)\/\.tag/ln -s \"\1\" $tagdbs/" \
    >>"$tagdir"/.tag.slinks
##(gedit "$tagdir"/.tag.slinks &)
  # make the soft links
  source "$tagdir"/.tag.slinks
  rm     "$tagdir"/.tag.slinks
  unset tagged
  aix=
}

# Identity the script
  bname="$(basename "$0")"
# Syntax
 if [[ "$1" == "" ]] ; then
  echo "ERROR: $bname requires one arg; a 'grep' regular expression string"
  echo "   eg: $bname \"music\" ......... Any instance of \"music\" .....(eg: \"musical\")"     
  echo "   eg: $bname \"\<music\>\" ..... Only the word \"music\" ...(but not \"musical\")"    
  echo "   eg: $bname \"muscic\|action\". Any instance of \"music\" or \"action\")"
  exit 1
 fi
# 'locate' the .tag files
# =======================
  tagdir="/tmp/$USER/$bname"
  tagdbs="${tagdir//\//\/}"
  [[   -d "$tagdir" ]] && rm -rf   "$tagdir" # remove all
  [[ ! -d "$tagdir" ]] && mkdir -p "$tagdir" # fresh start
  cp /dev/null "$tagdir"/.tag.slinks
  unset tagged  # array of .tag files 
  aix=0    # arg index
  amax=10  # arg max per call to grep 
  fct=0    # file count

  while IFS= read -r file ; do
    tagged[$aix]="$file"
####echo ${tagged[aix]}
    ((aix++));((fct++))
    (( aix == amax )) && args_grep_links "$1"
  done < <(locate -ber ^\.tag$ |sed "s/.*/\"&\"/")
  (( aix < amax )) && args_grep_links "$1"
  sleep 1 # to allow time for rm  to settle down after rm and adding links 
  xdg-open "$tagdir"

exit
#

Solution 2:

You may add a file like

.tag

into every folder. There you could store information as text. You could later browse them for your information.

Maybe you're better suited with a tool like find.

Feel free to ask about it's usage.

Solution 3:

tracker-utils will work for this.

How to search for files by tags?

The answer hasn't been accepted yet, but the examples I posted should give you an idea of how to work with this program. Tag additions work just fine on directories too, and I've tested it as well.

Directory Example

<sean@mymachine:~> tracker-tag -a projects src/ code/ projects/
<sean@mymachine:~> tracker-tag -s projects
Results: 3
  /home/sean/projects
  /home/sean/src
  /home/sean/code

Note that you'll need to start trackerd manually in order for the tracker-tag/* utils to work:

<sean@mymachine:~> /usr/lib/tracker/trackerd &

You can configure tracker with:

<sean@mymachine:~> tracker-preferences

I still don't have the tracker applet running (listed in ps, but not showing up in nautilus even after nautilus -q), but I don't really care. I don't use GUI tools for the most part; I prefer CLI since it's usually much faster than clicking on things.

I read one of your responses from an earlier post, and it looks like you're trying to add/search for tags in Nautilus, although you didn't list that as a primary criteria in your question. That's what the other person was doing, so perhaps this answer will be useless for you. That said, jumping to CLI occasionally isn't so bad if you get stuff done that you wouldn't normally be able to do in a GUI.