Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

linux commands!

  • 07-07-2011 1:04am
    #1
    Closed Accounts Posts: 3


    how do i write a shellscript which accepts some number of file names as arguments and outputs a single line containing only the name of the largest file not the longest file name.
    for example assuming your script is in a file called my_script .sh an invocation might be:
    $sh my_script.sh /etc/fstab /var/log/messages /etc/passwd
    for which the output might be:
    /var/log/messages
    if that happens to be the largest of these three files.


Comments

  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    #!/bin/bash
    ls -lS $* | head -1|cut -d\  -f10
    
    Note: the -S flag to ls is a GNU ls extension and may not work on other unices


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Lads....you're doing this punters homework!


  • Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭MiCr0


    2 more replies unapproved

    is this homework?


  • Closed Accounts Posts: 427 ✭✭scotty_irish


    google knows all. ask him. and why are you doing university assignments over the summer?


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    google knows all. ask him. and why are you doing university assignments over the summer?

    Coz he failed his exams, and has to do repeats in August/September.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,353 ✭✭✭Galway K9


    As annoyign as it sounds you wont learn anything from us tellign you, however i will provide a tutorial for shell scripting that is a good learnign resources.... http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

    What i can recommend is looking up in google? shell script to find the largest files of 3 file entered, learn how to get bash to read in filenames as parameters, and echo the answer.


  • Registered Users, Registered Users 2 Posts: 1,931 ✭✭✭PrzemoF


    university wrote: »
    how do i write a shellscript which accepts some number of file names as arguments and outputs a single line containing only the name of the largest file not the longest file name.
    for example assuming your script is in a file called my_script .sh an invocation might be:
    $sh my_script.sh /etc/fstab /var/log/messages /etc/passwd
    for which the output might be:
    /var/log/messages
    if that happens to be the largest of these three files.
    post what you already wrote and then we can help


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,567 Mod ✭✭✭✭Capt'n Midnight


    http://uni.xkcd.com - great command line learning tool

    in ubuntu you can use dir , but ls gives prettier colours


  • Registered Users, Registered Users 2 Posts: 14,048 ✭✭✭✭Johnboy1951


    http://uni.xkcd.com - great command line learning tool

    in ubuntu you can use dir , but ls gives prettier colours

    Try
    l
    ls
    d
    (LSD :D)

    as well as dir.
    Don't know if they are aliased on the Bunties ...

    ;)


Advertisement