How to handle those "smart" device names at the CLI?

Johnny Rosenberg gurus.knugum at gmail.com
Sat May 14 16:43:36 UTC 2011


2011/5/14 Dotan Cohen <dotancohen at gmail.com>:
> On Sat, May 14, 2011 at 19:07, Johnny Rosenberg <gurus.knugum at gmail.com> wrote:
>> Anyway, since there are different tools for different file systems I
>> wrote a very simple function.
>>
>> function label () {
>> case $# in
>> 1 | 2)
>>        Device=$1
>>        Label=$2
>>        FileSystem=$(cat /proc/mounts | grep $Device | awk '{print $3}')
>>        case ${FileSystem} in
>>        "ext2" | "ext3" | "ext4")
>>                sudo e2label $Device $Label;;
>>        "vfat")
>>                sudo dosfslabel $Device $Label;;
>>        "ntfs")
>>                sudo ntfslabel $Device $Label;;
>>        *)
>>                echo "Sorry, no support currently for ${FileSystem}.";;
>>        esac;;
>> *)
>>        echo "Syntax: label device [name]";;
>> esac
>> }
>>
>> I added the function to ”~/.bash-functions”, which is a file that will
>> run whenever I login. On my system that is, because I have the
>> following lines added to my ”~/.bashrc” file:
>>
>> if [ -f ~/.bash-functions ]; then
>>    . ~/.bash-functions
>> fi
>>
>> So now it works like an alias, kind of. Right now I have two devices
>> connected: sdb1 and sdc1. The first one is a vfat device and the other
>> one a ext3 device. The label function works for both of them:
>> $ label /dev/sdb1
>> [sudo] password for guraknugen:
>> Backup
>> $ label /dev/sdc1
>> Transcend
>> $
>>
>> Of course it's easy to add support for other file systems as well, I
>> just made it simple for my own use…
>> And of course I take no responsibility what so ever for any damages
>> caused by that function.
>>
>> Kind regards
>>
>> Johnny Rosenberg
>> ジョニー・ローゼンバーグ
>>
>
> Nice! I have a collection of code snippets and this one is going in
> there. If as intended I ever get around to publishing them should I
> attribute this to you?
>
> --
> Dotan Cohen
>
> http://gibberish.co.il
> http://what-is-what.com

Well, you can if you want to, it's not very important to me, unless
someone who runs into the code wants to tell me how it could have been
done better…




More information about the ubuntu-users mailing list