CLI Magic: Using GNOMEvfs to manipulate files

182

Author: Mayank Sharma

While KDE users get to boss KIO slaves for easier access to system and network resources, humble GNOME users can perform similar feats with its virtual file system, called GnomeVFS, which is an extension of the physical filesystem on a disk. Using GnomeVFS, users can work with non-local data that can come from unusual places, such as within compressed gzip archives.

CLI MagicGnomeVFS is an integral part of GNOME. It comprises several modules that work in the background and give GnomeVFS its functionality. In Ubuntu and Fedora distributions these modules are listed under the /usr/lib/gnome-vfs-2.0/modules/ directory. Some of the commonly included modules are http:, ftp:, file:, tar:, ssh:, fonts:, and burn:. You can add more modules via the distro’s package manager. For instance, in Ubuntu, the libgnomevfs2-extra package adds the bzip2: and smb: modules.

You can use GnomeVFS from within the Nautilus file manager or from the command line. The most commonly used GnomeVFS modules are http:// and https://, which get data stored on a Web server. You can also use ftp:// to get data from a FTP server and smb:// to get data from a Samba share.

An interesting GnomeVFS module is burn://. You can use it within a Nautilus window by dragging and dropping files into the window to burn them onto a CD or DVD, depending on the media burner on your machine.

But the real fun of GnomeVFS comes from using it from the command line. The command eog file:///tmp/stuff.tar#tar:bookmarks.png will open the file bookmarks.png in GNOME’s image viewer, Eye of GNOME. The command uses two GnomeVFS modules. The file:// module specifies the location of the file (/tmp/stuff.tar). The “#tar:bookmarks.png” part of the command tells GNOME that anything before it is a tar archive, and it should do what it needs to display the bookmarks.png file under it. You don’t have to worry about untarring the archive and cleaning up afterward.

Similarly you can read files from a compressed archive without uncompressing it first. If you have a .tar.gz file, you’ll have to combine two GnomeVFS modules to suck files out of it. For example, eog file:///tmp/stuff.tar.gz#gzip:#tar:forum.png will first treat the file (/tmp/stuff.tar.gz) as a compressed file and uncompress it, and then treat the resulting file (stuff.tar) as a tar archive and untar it to display the image (forum.png).

GnomeVFS can also handle bzip2 archives and read files from under directories as well. In gedit file:///tmp/old-docs.tar.bz2#bzip2:#tar:020207/writeup.txt we ask GNOME to display a text file from under a directory after extracting it from a bzip2 compressed archive.

There are also some GnomeVFS tools specifically designed for command-line use, such as gnomevfs-cat, gnomevfs-copy, gnomevfs-ls, gnomevfs-mkdir, and gnomevfs-info. These tools are GnomeVFSed versions of common command-line tools and are similar in function to them, with one advantage — the ability to work on external non-local files.

For example, gnomevfs-cat http://www.example.net.net > /tmp/index.html performs the same copy function a normal cat command would, but on a remotely located file. Similarly, gnomevfs-ls smb://192.168.2.2/D/ displays the contents of a remote Windows directory over your network.

Using GnomeVFS, you can also browse files on Web sites via FTP. The command gnomevfs-ls ftp://username:password@ftp.example.net/public_html lists the contents of a remote directory along with the type, size, and permission of the files, in this format:

. (Directory, x-directory/normal) size 4096 .. (Directory, x-directory/normal) size 4096 .htaccess (Regular, application/octet-stream) size 413 .smileys (Directory, x-directory/normal) size 4096 WysiwygPro (Directory, x-directory/normal) size 4096 _private (Directory, x-directory/normal) size 4096 _vti_bin (Directory, x-directory/normal) size 4096 _vti_cnf (Directory, x-directory/normal) size 4096 _vti_inf.html (Regular, text/html) size 1754 _vti_log (Directory, x-directory/normal) size 4096 _vti_pvt (Directory, x-directory/normal) size 4096 _vti_txt (Directory, x-directory/normal) size 4096 contact.htm (Regular, text/html) size 2390 favicon.ico (Regular, image/x-ico) size 1406 images (Directory, x-directory/normal) size 4096 index.htm (Regular, text/html) size 2977

You can also upload a file to a remote site through FTP using GnomeVFS. The command gnomevfs-copy /tmp/moi.jpg ftp://username:password@ftp.example.net/public_html/images/ uses gnomevfs-copy to upload the source file (/tmp/moi.jpg) to the specified location (/public_html/images) on the site. You can also use ftp://username:password@ftp.example.net from within Nautilus to copy and paste files onto the site.

Once it has been uploaded, you can check on the file by using gnomevfs-info. The command gnomevfs-info ftp://username:password@ftp.example.net/public_html/images/moi.jpg produces the following output:

Name : moi.jpg Type : Regular MIME type : image/jpeg Default app : eog.desktop Size : 4321 Blocks : 9 I/O block size : 32768 Local : NO SUID : NO SGID : NO Sticky : NO Link count : 1 UID : 1000 GID : 1000 Access time : Tue Mar 8 00:00:00 2008 Modification time : Tue Mar 8 00:00:00 2008 Change time : Tue Mar 8 00:00:00 2008

Using GnomeVFS to look at remote files and under compressed folders can be a real time-saver.

Category:

  • Desktop Software