Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

linux commands!

  • 07-07-2011 01: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,929 ✭✭✭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: 96,269 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: 13,950 ✭✭✭✭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