How do I create an alias dir command for ls?

Discussion in 'Android Hacks and Help' started by kevdog, Dec 20, 2009.

  1. kevdog

    kevdog Member

    Joined:
    Nov 14, 2009
    Messages:
    722
    Likes Received:
    0
    Trophy Points:
    16
    Ratings:
    +0
    Ive tried creating a symbolic link for dir, as well as just copying the ls command to dir as well. No method works. Is there an equivalent alias command?
     
  2. phone

    phone Member

    Joined:
    Dec 12, 2009
    Messages:
    189
    Likes Received:
    0
    Trophy Points:
    16
    Ratings:
    +0
    Someone can jump in if I'm wrong here but this is what I've found out playing around.

    There is no user environment with Android, like you'd have with a normal Linux box. In other words, setting up .profile in /root and placing your aliases won't work.

    Environment variables, like PATH, are set in init.rc. In order to add aliases there you'd need to flash it to ROM.

    You can set your alias on the command line, each time you log in.

    alias dir='ls'

    I have not tested this but you might be able to use a function. Create a file called "dir" and put the following in it.

    Code:
    #!/bin/sh
    function dir
    {
       ls
    }
    dir
    
    Then "chmod 750 dir"

    If it works put the file in /system/xbin/ so it's in your PATH and you can run it as "dir" from the command line. Or you'll need to use a full PATH to the command or use ./dir

    If the function actually works, let me know. I de-rooted my phone for the time being.
    hth,
     
  3. kevdog

    kevdog Member

    Joined:
    Nov 14, 2009
    Messages:
    722
    Likes Received:
    0
    Trophy Points:
    16
    Ratings:
    +0
    Its really wierd.

    I can execute this script in linux and on cygwin. I put this script in the /system/xbin directory.

    Here it is:
    # ls -la | grep dir
    ls -la | grep dir
    -rwxr-xr-x 1 2000 2000 47 Dec 20 23:01 dir
    -rwxr-xr-x 192 0 0 690260 Dec 13 05:47 dirname
    -rwxr-xr-x 192 0 0 690260 Dec 13 05:47 mkdir
    -rwxr-xr-x 192 0 0 690260 Dec 13 05:47 rmdir

    But when I go to run it:
    # ./dir
    ./dir
    ./dir: not found

    I even did a
    chown root.root dir

    But that produced the same output!

    Is the 192 designation important?
     
  4. phone

    phone Member

    Joined:
    Dec 12, 2009
    Messages:
    189
    Likes Received:
    0
    Trophy Points:
    16
    Ratings:
    +0
    If it's in /system/xbin/ you shouldn't need "./"

    You should be able to run it like:

    # cd /system/xbin/
    # ./dir

    or

    # /system/xbin/dir

    or

    # dir
     
  5. kevdog

    kevdog Member

    Joined:
    Nov 14, 2009
    Messages:
    722
    Likes Received:
    0
    Trophy Points:
    16
    Ratings:
    +0
    Have you tried this because it still says not found for me

    Home there is no /bin/sh as there is in a normal Linux system
     
    Last edited: Dec 20, 2009
  6. phone

    phone Member

    Joined:
    Dec 12, 2009
    Messages:
    189
    Likes Received:
    0
    Trophy Points:
    16
    Ratings:
    +0
    No I haven't, that's what I said in my original email. ;) My phone isn't rooted ATM, so I can't test.

    Anyway try taking out "#!/bin/sh" and see if that works for you. I ran a script successfully without a shebang. I didn't try a function though.
     
  7. kevdog

    kevdog Member

    Joined:
    Nov 14, 2009
    Messages:
    722
    Likes Received:
    0
    Trophy Points:
    16
    Ratings:
    +0
    Ok after a bit of googling here is what I have:

    I placed this script known as dir within /system/xbin

    #!/system/xbin/sh

    dir(){
    ls $@
    }
    dir $@

    I then did a
    cd /system/xbin
    chown root.root dir
    chmod 755 dir

    The only thing that would have to be modified for anyone is the location of the busybox sh. When I originally installed busybox I did a busybox --install /system/xbin.

    Thanks for pointing to me on the right track.
     
  8. jrummy16

    jrummy16 Premium Member Theme Developer Premium Member Developer

    Joined:
    Jan 25, 2010
    Messages:
    1,211
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    Orange County, CA
    Ratings:
    +0
    you are just trying to create a symbolic link?

    Code:
    #!/system/bin/sh
     
    busybox mount -o remount,rw /system
    busybox ln -s $1 $2
    echo created a symbolic link for $1 at $2
    
    then do:

    script_name /what/I/want/to/symlink /where/the/symlic/should/go

    not really understanding what the whole ls is for.
     
  9. DigiK

    DigiK Member

    Joined:
    Jan 17, 2010
    Messages:
    213
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Pittsburgh, PA
    Ratings:
    +0
    J thanks for getting back on this.

    Tried the script but it's throwing an operation not permitted error when trying to create a symlink from the SD card. I read that ln is not permitted on FAT file systems, i.e.: the SD card.

    I'm trying to find a way to utilize the onboard 8Gb DX memory for media and make it visible as a searchable folder for music players. Creating an ext3 partition on the SD card would theoretically make the symlink possible, right?

    I also contacted the Mixzing dev to see if they'd be willing to come at it from the app side and enable root level search directories... We'll see if they can provide any love for DX owners.
     
  10. FranklinWalker

    FranklinWalker Member

    Joined:
    Sep 7, 2010
    Messages:
    427
    Likes Received:
    0
    Trophy Points:
    16
    Ratings:
    +0
    thanks for your feedback
     
Search tags for this page

android alias

,

android alias command

,
android alias folder
,
android create alias
,
android create alias folder
,
android root alias
,

android symlink command

,
create alias android
,
init.rc alias
,
root aliases android