


By default, storage devices that are plugged into the system mount automatically in the /media directory, open a file browser window for each volume and place an icon on your desktop. If you plug in a usb hard disk with many partitions, all of the partitions will automatically mount. This behaviour may not be what you want so you can configure it as shown below.
If the volumes have labels the icons will be named accordingly, otherwise they will be named "disk" and as more volumes are added, you can get "disk-1" and so on.
To change the volume label see RenameUSBDrive.
To enable or disable automount open a terminal and type gconf-editor followed by the [Enter] key.
Browse to /apps/nautilus/preferences/media_automount.
The media_automount key controls whether to automatically mount media. If set to true, then Nautilus will automatically mount media such as user-visible hard disks and removable media on start-up and media insertion.
There is another key /apps/nautilus/preferences/media_automount_open. This controls whether to automatically open a folder for automounted media. This key can also be set in the Nautilus (file manager) window. From the Edit menu in Nautilus select Preferences and then select the Media tab.
If set to true, then Nautilus will automatically open a folder when media is automounted. This only applies to media where no known x-content/* type was detected; for media where a known x-content type is detected, the user configurable action will be taken instead. This can be configured as shown below.
To control which programs automatically start when you plug in a device, go to System->Preferences->Removable Drives and Media.
In Ubuntu 9.10 (Karmic Koala) Removable Drives and Media is no longer in the Preferences menu but you can still do this as follows.
This user configurable action for specific media types can be configured in the Nautilus (file manager) window. From the Edit menu in Nautilus select Preferences and then select the Media tab. There you can select what happens when media is inserted. For example we need to turnoff audio CD auto play. CD audio "can do nothing" or "ask what to do" or "open folder".
For more complex scenarios, see UsbDriveDoSomethingHowto.
Before you disconnect the device, don't forget to unmount it. This can be done by right clicking the desktop icon and selecting "Unmount" (or in some cases, "Eject"). In Ubuntu 9.10 (Karmic Koala), in the file manager window you can also click on an "eject" button against the name of the mounted volume.
By default, disk drives do not automount in Ubuntu Server Edition. If you are looking for a lightweight solution that does not depend on HAL/DBUS, you can install "usbmount".
Sometimes devices don't automount, in which case you should try to manually mount it. First, you must know what device we are dealing with and what filesystem it is formatted with. Most flash drives are FAT16 or FAT32 and most external hard disks are NTFS.
sudo fdisk -l
Find your device in the list, it is probably something like /dev/sdb1. For more information about filesystems, see LinuxFilesystemsExplained.
Now we need to create a mount point for the device, let's say we want to call it "external". You can call it whatever you want, just please don't use spaces in the name or it gets a little more complicated - use an underscore to separate words (like "my_external"). Create the mount point:
sudo mkdir /media/external
We can now mount the drive. Let's say the device is /dev/sdb1, the filesystem is FAT16 or FAT32 (like it is for most USB flash drives), and we want to mount it at /media/external (having already created the mount point):
sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=100,utf8,dmask=027,fmask=137
The options following the "-o" allow your user to have ownership of the drive, and the masks allow for extra security for file system permissions. If you don't use those extra options you may not be able to read and write the drive with your regular username.
Otherwise if the device is formatted with NTFS, run:
sudo mount -t ntfs-3g /dev/sdb1 /media/external
You must have the ntfs-3g driver installed. See MountingWindowsPartitions for more information.
When you are finished with the device, don't forget to unmount the drive before disconnecting it. Assuming /dev/sdb1 mounted at /media/external, you can either unmount using the device or the mount point:
sudo umount /dev/sdb1
or:
sudo umount /media/external
You cannot unmount from the desktop by right clicking the icon if the drive was manually mounted.
There is a program called pmount available in the repositories which allows unprivileged users to mount drives as if they were using sudo, even without an entry in /etc/fstab. This is perfect for computers that have users without RootSudo access, like public terminals or thin clients.
pmount can be used with the same syntax as mount (but without sudo), or quite simply as follows:
pmount[ label ]
Example:
pmount /dev/sdb1 flash_driveThis will mount the device /dev/sdb1 at /media/flash_drive
If you leave off the label option, it will mount by default at /media/device
To unmount the device, use pumount, like so:
pumount
Example:
pumount /dev/sdb1
For more help, you can see the man pages for pmount and pumount.
Before disconnecting devices, you must unmount them first. This is similar to "Safely Remove" in Windows in that the device won't unmount until data is finished being written to the device, or until other programs are finished using it. This applies to all types of storage devices, including flash drives, flash cards, external hard drives, ipods and other media players, and even remote storage like Samba or NFS shares.
Failure to unmount before disconnecting the device can result in loss of data and/or a corrupted file system. There are no exceptions to this rule. Be safe - unmount your drives before disconnecting them!
To see a list of your USB devices (the vendor and device ID's), run:
lsusb
To see all attached storage devices and their partitions, run:
sudo fdisk -l
To see information about currently mounted systems, simply run:
mount
Here's a simple command that converts an MPG file to AVI format:
mencoder file.mpg -o file.avi -ovc lavc -oac lavc-ovc and -oac represent the options for the video and audio codecs that mencoder will use. To find out what video codecs are installed on your system, use mencoder -ovc help and mencoder -oac help.
Suppose you need a file with no compression on the audio part and decide to use PCM. You can specify the type of audio codec you want by using the acodec option:
mencoder file.mpg -o file.avi -ovc lavc -oac lavc -lavcopts acodec=pcm
When it comes to MP3 compression, you can also choose a bitrate using abitrate:
mencoder file.mpg -o file.avi -ovc lavc -oac lavc -lavcopts acodec=libmp3lame:abitrate=128
You can use lameopts if you have libmp3lame installed and want to add extra options to the encoding process. You can also create files with variable bit rate audio compression:
mencoder file -o file.avi -ovc lavc -oac mp3lame -lameopts vbr=2:q=3
where q can be any number between 0 and 9.
You can do the same thing with the video part of the file:
mencoder file.mpg -o file.avi -ovc lavc -oac lavc -lavcopts acodec=libmp3lame:abitrate=128 vcodec=xvid
If you don't want to use video compression, try vcodec=copy. With that option, the frames will be copied one by one from the source file.
You can use xvid or divx directly, without going through lavc:
mencoder -ovc xvid -oac mp3lame -o destination.avi source.avi
If you need customized quality, you can add a few options to the XviD compression:
mencoder -ovc xvid -oac mp3lame -xvidencopts bitrate=878 -o destination.avi source.avi
The higher the bitrate, the better quality the video file will be. The downside is a larger file size.
Now let's get fancy and make an XviD copy of a DVD using two passes. During the first pass, mencoder analyzes the content of the file; on the second pass mencoder encodes the new file based on the information obtained. By using two passes you can produce a better compressed file, but you'll have to wait a little longer for it, and you'll probably see CPU usage at 90% during the conversion:
mencoder dvd:// -oac mp3lame -ovc xvid -xvidencopts pass=1 -o /dev/null
mencoder dvd:// -oac mp3lame -ovc xvid -xvidencopts pass=2:bitrate=800 -o xvidfile.avi
You can use whatever bitrate option you want. If you need to squeeze a DVD into a 700MB XviD file, you could use the following command, which forces the file size of the resulting AVI to 700MB.:
mencoder dvd:// -ovc xvid -oac mp3lame -xvidencopts bitrate=-700000 -o file.avi
If you don't like the CPU being used to the max and want to leave resources for launching other applications, use the nice option, which will run the program with the lowest priority when it comes to process scheduling:
nice -n 19 mencoder dvd:// -ovc xvid -oac mp3lame -xvidencopts bitrate=-700000 -o file.avi
Suppose you have a folder full of small video files of different types and would like to merge them into one big movie for easy watching. First, rename them so that they're in the order you want them to appear in the final video, then use:
mencoder * -o output.avi
If you want to add a particular audio file to a movie, use:
mencoder source.avi -o destination.avi -ovc copy -oac mp3lame -audiofile file.wav (for uncompressed files)
mencoder source.avi -o destination.avi -ovc copy -oac copy -audiofile file.mp3 (for compressed files)
To convert a video file to run on a device running iPodLinux, use:
mencoder -ovc raw -ofps 15 -oac pcm -vf scale=176:-2,expand=176:132,format=bgr16 input.file -o output.avi
This produces a RAW AVI file with uncompressed audio data and scales it so it fits the Nano's tiny screen perfectly.
I have a Pocket PC that I sometimes bring with me on business trips. I take a couple of movies I haven't seen in a while and convert them to fit on a 512MB SD card:
mencoder -oac mp3lame -lameopts mode=3:preset=24 -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=384:keyint=250 -vop expand="320:240" -o outputfile.avi inputfile.avi
or
mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=200:abitrate=48 -vop scale=320:240 -oac copy -o output.avi
The difference here is that the latter command scales the file and the former fills the PDA's 320x240-pixel screen with the movie.
If you have a webcam and want to record the output, use:
mencoder tv:// -tv driver=v4l:device=/dev/video0:width=640:height=480:forceaudio -ovc lavc -oac lavc -lavcopts vcodec=mpeg4:acodec=mp3 -ffourcc divx -o test.avi
The command records anything output by /dev/video0 in 640x480 resolution, using DivX with MP3 audio as an output result.
As you can see, you can use mencoder to convert almost any type of video file in several ways. It works fast, it works well, and I wouldn't change it for any other application, be it GUI-friendly or not.
example pic made by me
Tools like the GIMP (www.gimp.org) and similar graphical applications are great for modifying and manipulating images. Sometimes, however, they can be overkill for little things that need to be done, such as converting file types or resizing images. As well, a graphical tool can be time consuming and difficult to script, unlike CLI tools.
The ImageMagick suite (www.imagemagick.org) of programs allows you to manipulate images from the command-line, making it much simpler to convert large numbers of pictures or even for that single quick image conversion.
Some of the tools that ImageMagick includes are the convert tool, the composite tool, and the display tool.
The convert tool is used to convert pictures from one format or size to another. The easiest method is to simply convert an image from one format to another using:
$ convert image.jpg image.png
This will convert image.jpg from a JPEG to a PNG and save it as image.png. To convert and resize an image, use:
$ convert -size 50x50 image.jpg image.png
This will convert from JPEG to PNG format and resize the resulting image to 50x50 pixels. Likewise, you can use convert to rotate an image:
$ convert -rotate 90 image.jpg image.png
This will rotate the image 90 degrees and convert it to a PNG file. To manipulate the file and keep it in the same format:
$ convert -rotate 90 image.jpg image-new.jpg
To create a composite image, or layer one image above another, use the composite tool. For instance, to put logo.jpg in the top-left corner of image.jpg, you would use:
$ composite -gravity NorthWest logo.jpg image.jpg composite.jpg
This will layer logo.jpg over image.jpg in the top-right corner (NorthWest), and the resulting file will be named composite.jpg. Each edge of the picture is noted by direction: Top is North, bottom is South, right is East, and left is West. The composite tool respects transparent pixels, so using it is a great way to automatically tag all your photos with your name or Web site address.
These commands merely scratch the surface of what ImageMagick can do. ImageMagick is capable of creating new images, embedding steganography in pictures, and much more.