Find the answer to your Linux question:
Results 1 to 4 of 4

Thread: Alias help

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Alias help


    Hey guys, so I work for companies that often use linux gnome based i believe its CentOS.

    We often use version numbers at the end of our files as we make changes and progress with the work. I am wondering if there is away to have an alias that will some how look in the directory and then automatically select the file with the highest version number.

    Thanks,

    IgoMontoya

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    14,035
    You will need to write a script to determine which file is the latest version. You can use bash or awk/sed, python, perl, etc to do this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    depends on the versioning logic.
    does the highest version always appear first or last with a simple ls?
    have you looked at some commands that can help? e.g. find, or sort?
    show some effort, we can help.
    I am not a "Linux Guru"! Get off me! The Forum software won't let me change it!
    How to ask smart questions | Don't be a Help Vampire | How to Use Code Tags
    You can post a link by removing "http://www." from it.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    818
    Simple is to run "fred":

    In the directory containing "fred.XXX" versions add the following script named fred (same name as the versioned files):
    Code:
    cat <<'@EOF' > /tmp/fred
    #!/bin/bash
    #
    location="/tmp"
    exec $(ls -1vr ${location}/${0##*/}*  | /bin/sed -n '1p') "$@"
    @EOF
    
    chmod 750 /tmp/fred
    Of course the "/tmp" and 'fred" needs to have the correct path and name put there.


    Testing:

    Code:
    cat <<@EOF > /tmp/fred.0
    #!/bin/bash
    
    echo "I am Fred,XXX"
    echo "You passed the arguments of:"
    printf "     '%s'\n" "$@"
    @EOF
    chmod 755 /tmp/fred
    
    cat <<@EOF > /tmp/fred.0
    #!/bin/bash
    
    echo "I am Fred,XXX"
    echo "You passed the arguments of:"
    printf "     '%s'\n" "$@"
    @EOF
    chmod 750 /tmp/fred.0
    
    /tmp/fred
    
    for version on {1..13}; do 
        cp /tmp/fred.0 /tmp/fred.${version}
        sed --in-place "s=XXX=${version}="  /tmp/fred.${version}
       /tmp/fred
    done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •