I have quite an extensive collection of videos and pictures that I've gathered over the last few years.

These files of mine are located in "~/stuff/". Within the "stuff" folder, there's many subfolders, and these subfolders also contain subfolders of their own.

My videos and pictures are arranged into subfolders because I have categorised them. For instance, I might have a folder tree something like:

Code:
stuff
|
|
|
|--------camera_photos
         |
         |
         |
         |--------norway_2003
                  |
                  |
                  |
                  |
                  --------xmas_party
                  |
                  |
                  |
                  |
                  --------last_day
This categorisation of files is handy when I'm searching for a particular picture, but it's a pain in the ass when I just want to browse around all my photos in a file manager such as Nautilus.

I'm currently running Ubuntu Linux Lucid Lynx as my main operating system, so I have GNome as my desktop manager.

With GNome, I can click on the "Ubuntu Menu", go to "Places", then "Search for Files...". From there, I can specify "~/stuff" as the folder to search in, and then I just leave the filename blank. I hit return and it shows me a list of all the files found under the "stuff" folder. But I'm restricted in what I can do with this list. For instance, I can't change the view from List to Thumbnail.

I wanted to find a way of creating a "Virtual Folder" for my search results which would contain symbolic links to all of the files I had under my "stuff" folder. I could use this virtual folder just like any other folder; I could open it up in Nautilus file manager and see thumbnails for all my pictures and videos.

So I played around for an hour or two at the command line trying to perfect the command I needed to create this "Virtual Folder".

OK, I'll go through it step by step.

Open up a terminal.

First you want to create the "Virtual Folder" and navigate into it:

Code:
cd
mkdir all_my_stuff
cd all_my_stuff
You want to get a full list of all regular files that exist in a folder of your choice:

Code:
find ~/stuff -type f
This should give you an output something like:

Code:
/home/virchanza/stuff/1.jpg
/home/virchanza/stuff/2.jpg
/home/virchanza/stuff/3.jpg
/home/virchanza/stuff/camera_photos/norway_2003/xmas_party/All of us.jpg
/home/virchanza/stuff/camera_photos/norway_2003/last_day/billy in the kitchen.jpg
Normally, to create a symbolic link, I would use the command "ln" as follows:

Code:
ln -s ~/all_of_us.jpg all_of_us.jpg
Some of my files contain spaces in their names, so I would need to make sure to put the filename in quotes, e.g.:

Code:
ln -s "~/all of us.jpg" "all of us.jpg"
The "find" program has a handy built-in printf feature that works just like the printf function in the C programming language. I'm going to use printf with four special codes:

Code:
%p = The full path and name of the file
%f = Just the name of the file on its own
\n = New line
\" = This is an actual quote symbol
So I start with:

Code:
find ~/stuff -type f -printf "ln -s %p %f\n"
Next I want to make sure that the filenames are surrounded in quotes just in cases there's a space in the name:

Code:
find ~/stuff -type f -printf "ln -s \"%p\" \"%f\"\n"
There's another tinly little problem though. It's possible to have two files with the same name, e.g.:

Code:
/home/virchanza/photos/norway/me.jpg
/home/virchanza/photos/iceland/me.jpg
You can't create two symbolic links with the same name within your "Virtual Folder". To remedy this, I prefix the file's inode number to the name of the symbolic link:

Code:
find ~/stuff -type f -printf "ln -s \"%p\" \"%i__%f\"\n"
Next, to actually create all these symbolic links, you need to pipe the output of the above command into "sh", as follows:

Code:
find ~/stuff -type f -printf "ln -s \"%p\" \"%i___%f\"\n" | sh
Instead of using the inode number, you can prefix the folder path, but it's a little more complicated:

Code:
find ~/stuff -type f -printf "\"%p\"\0\"%P\"\n" | awk -F "\0" '{gsub("/","___",$2);print "ln -s " $1 " " $2}' | sh
OK so now you should have a folder full of symbolic links. You can open this folder in your favourite file manager and do whatever you want with it

When you're finished with your virtual folder, you can delete its contents:

Code:
rm *
cd ..
rmdir all_my_stuff
or if you like, you can delete the entire folder all at once like so:

Code:
cd ..
rm -r all_my_stuff
NOTE: When you delete a symbolic link, it does NOT delete the actual file to which the link points; all it does is delete the link. However, if you open up a symbolic link in an editor program such as "nano" or "gedit", the changes you make to it will be saved to the actual file.

I keep a small collection of command line stuff like this on my website: Virjacode