1. Download our Official Android App: Forums for Android!

The "Linux questions (and other stuff)" thread

Discussion in 'Computers' started by MoodyBlues, Jan 17, 2013.

  1. EarlyMon

    EarlyMon The PearlyMon
    Rank:
     #1
    Points:
    5,218
    Posts:
    57,632
    Joined:
    Jun 10, 2010

    Jun 10, 2010
    57,632
    70,421
    5,218
    New Mexico, USA
    Hint -

    Code (Text):
    1.  
    2. # Change input field separator from default space, restore when done
    3.  
    4. SAVEIFS=$IFS
    5. IFS=$(echo -en "\n\b")
    6.  
    7. for SUBDIR in `ls -d1 */`
    8. do
    9.   echo "Testing: $SUBDIR"
    10. done
    11.  
    12. # cleanup
    13.  
    14. IFS=$SAVEIFS
    15.  
    Kinda in a hurry, saw this on a drive-by, sorry it's not complete.

    Probably use sed to fix whatever else within the for loop.
     

    Advertisement

    MoodyBlues likes this.
  2. saptech

    saptech Android Expert
    Rank:
    None
    Points:
    343
    Posts:
    3,757
    Joined:
    Dec 9, 2011

    9to5cynic likes this.
  3. Dngrsone

    Dngrsone Android Expert
    Rank:
     #38
    Points:
    653
    Posts:
    3,978
    Joined:
    Jan 24, 2013

    Jan 24, 2013
    3,978
    3,675
    653
    Male
    Avionics Technician
    Centrally located far from everywhere, CA
    I didn't know Mint was at the top.

    Now I wonder if I should be proud that my OS of choice is the most popular or if maybe I should be bucking the trend and using something that isn't quite so mainstream.

    I could go back to Slackware, try Arch, or something.

    I see DSL is finally looking at an update after four years of no movement...

    I always did like the early fluxbox interface of DSL.
     
  4. saptech

    saptech Android Expert
    Rank:
    None
    Points:
    343
    Posts:
    3,757
    Joined:
    Dec 9, 2011

    Yes, Mint has been on top for a good while. It's based on Ubuntu which is based on Debian, so the top three are Debian based. If you want to try something different, give Debian a try. I've always used it instead of its siblings. Slackware & Arch are good choices also, along with Mageia (mga)!
     
    Dngrsone likes this.
  5. Dngrsone

    Dngrsone Android Expert
    Rank:
     #38
    Points:
    653
    Posts:
    3,978
    Joined:
    Jan 24, 2013

    Jan 24, 2013
    3,978
    3,675
    653
    Male
    Avionics Technician
    Centrally located far from everywhere, CA
    What's the default desktop environment for Debian?
     
  6. MoodyBlues

    MoodyBlues - Crazy peacock person -
    Thread Starter
    Rank:
    None
    Points:
    343
    Posts:
    3,353
    Joined:
    Jan 27, 2011

    Jan 27, 2011
    3,353
    1,580
    343
    Formerly UNIX/Linux programmer/sysadmin, now disab
    /home/LosAngeles
    Wow. I did not know this.
     
  7. MoodyBlues

    MoodyBlues - Crazy peacock person -
    Thread Starter
    Rank:
    None
    Points:
    343
    Posts:
    3,353
    Joined:
    Jan 27, 2011

    Jan 27, 2011
    3,353
    1,580
    343
    Formerly UNIX/Linux programmer/sysadmin, now disab
    /home/LosAngeles
    Using EM's snippet, I've got it working, but I wonder if you'd like to take a stab at it before I post. Let me know.
     
  8. Joelgp83

    Joelgp83 Android Enthusiast
    Rank:
     #350
    Points:
    68
    Posts:
    454
    Joined:
    Jul 30, 2012

    Jul 30, 2012
    454
    176
    68
    California
    I'd suspect it was something gnome 2 or 3 based....
     
  9. palmtree5

    palmtree5 Sunny Vacation Supporter!
    Moderator
    Rank:
     #41
    Points:
    633
    Posts:
    4,494
    Joined:
    May 2, 2012

    May 2, 2012
    4,494
    3,159
    633
    Male
    Student
    USA
    Not really unless I push it to the upcoming weekend as I have more important things to do between now and Friday
     
  10. MoodyBlues

    MoodyBlues - Crazy peacock person -
    Thread Starter
    Rank:
    None
    Points:
    343
    Posts:
    3,353
    Joined:
    Jan 27, 2011

    Jan 27, 2011
    3,353
    1,580
    343
    Formerly UNIX/Linux programmer/sysadmin, now disab
    /home/LosAngeles
    Okay, here's my script:

    [high]
    #!/bin/bash
    SUBDIR=$1
    SAVEIFS=$IFS

    IFS=$(echo -en "\n\b")
    cd $SUBDIR

    for SUBDIR2 in `ls -d1 */`
    do ZIPFILE=$(basename "$SUBDIR2")
    zip -r $ZIPFILE/$ZIPFILE.zip $SUBDIR2
    done

    # cleanup
    IFS=$SAVEIFS
    [/high]

    As always, this can be tweaked as needed/desired. Right now, it's taking you to the directory whose name you enter at runtime, then it's doing its thing as far as locating subdirectories and zipping their contents. It's creating the zipped files in each subdirectory; of course that can be changed to wherever you'd prefer.

    And thanks to EM for the $IFS idea. :)
     
    EarlyMon likes this.
  11. EarlyMon

    EarlyMon The PearlyMon
    Rank:
     #1
    Points:
    5,218
    Posts:
    57,632
    Joined:
    Jun 10, 2010

    Jun 10, 2010
    57,632
    70,421
    5,218
    New Mexico, USA
    Don't have to pump those through sed to escape any blanks in the path name?
     
  12. palmtree5

    palmtree5 Sunny Vacation Supporter!
    Moderator
    Rank:
     #41
    Points:
    633
    Posts:
    4,494
    Joined:
    May 2, 2012

    May 2, 2012
    4,494
    3,159
    633
    Male
    Student
    USA
    Apparently not. What Moody posted works :)
     
  13. MoodyBlues

    MoodyBlues - Crazy peacock person -
    Thread Starter
    Rank:
    None
    Points:
    343
    Posts:
    3,353
    Joined:
    Jan 27, 2011

    Jan 27, 2011
    3,353
    1,580
    343
    Formerly UNIX/Linux programmer/sysadmin, now disab
    /home/LosAngeles
    No, the basename line is taking care of that.
     
  14. saptech

    saptech Android Expert
    Rank:
    None
    Points:
    343
    Posts:
    3,757
    Joined:
    Dec 9, 2011

    It used to be Gnome 2, but assume it may be Gnome 3. I haven't installed a default Debian in very long time.

    I'm not running it at the moment but when I did, I would do a minimum install of the basic system and then add other components as I needed them. Such as a WM instead of DE.
     
    Dngrsone likes this.
  15. MoodyBlues

    MoodyBlues - Crazy peacock person -
    Thread Starter
    Rank:
    None
    Points:
    343
    Posts:
    3,353
    Joined:
    Jan 27, 2011

    Jan 27, 2011
    3,353
    1,580
    343
    Formerly UNIX/Linux programmer/sysadmin, now disab
    /home/LosAngeles
    What about Unity? Or is that strictly a *buntu thing? (I stick to my trusty and beloved KDE, so I'm quite out of the loop on those other DEs. :D)
     
  16. palmtree5

    palmtree5 Sunny Vacation Supporter!
    Moderator
    Rank:
     #41
    Points:
    633
    Posts:
    4,494
    Joined:
    May 2, 2012

    May 2, 2012
    4,494
    3,159
    633
    Male
    Student
    USA
    Unity is the default on Ubuntu (I wouldn't say strictly though as it can be installed on non-*buntu distros)
     
  17. Dngrsone

    Dngrsone Android Expert
    Rank:
     #38
    Points:
    653
    Posts:
    3,978
    Joined:
    Jan 24, 2013

    Jan 24, 2013
    3,978
    3,675
    653
    Male
    Avionics Technician
    Centrally located far from everywhere, CA
    Unity is not exclusive to Ubuntu... one should be able to install it on Debian.
     
    palmtree5 likes this.
  18. MoodyBlues

    MoodyBlues - Crazy peacock person -
    Thread Starter
    Rank:
    None
    Points:
    343
    Posts:
    3,353
    Joined:
    Jan 27, 2011

    Jan 27, 2011
    3,353
    1,580
    343
    Formerly UNIX/Linux programmer/sysadmin, now disab
    /home/LosAngeles
    Thanks for the info. Now I guess the question is, WHY would anyone want to install it?! :laugh: (Yes, I'm a KDE person through and through--but I did try Unity (just for the hell of it) a few times, so at least I'm not insulting something I've never tried!)
     
  19. EarlyMon

    EarlyMon The PearlyMon
    Rank:
     #1
    Points:
    5,218
    Posts:
    57,632
    Joined:
    Jun 10, 2010

    Jun 10, 2010
    57,632
    70,421
    5,218
    New Mexico, USA
    The last SUBDIR2 in the zip command isn't affected by the basename.

    Interesting. I'm guessing that the IFS sorted that as well...
     
    MoodyBlues likes this.
  20. jonbanjo

    jonbanjo Well-Known Member
    Rank:
    None
    Points:
    43
    Posts:
    208
    Joined:
    May 26, 2013

    May 26, 2013
    208
    49
    43
    UK
    I don't get on well with bash (I dislike the syntax and there seems to me to be a number of "gotchas"). I guess if I had ambitions of being a system admin I'd have to change my ways but for me at home, I'd probably do something like.

    PHP:
    1. <?php
    2. if (count ($argv) !=2){
    3.   echo "Usage zip.php directory\n";
    4.   exit;
    5. }
    6.  
    7. if (!@chdir($argv[1])){
    8.   echo "Invalid directory\n";
    9.   exit;
    10. }
    11.  
    12. $logfile = "zip.log";
    13. @unlink($logfile);
    14. foreach (glob("*", GLOB_ONLYDIR | GLOB_MARK) as $dir){
    15.   $name = basename($dir);
    16.   exec("zip -r \"$dir$name.zip\" \"$dir\" &>>$logfile");
    17. }
    18. ?>
     
    EarlyMon likes this.
  21. palmtree5

    palmtree5 Sunny Vacation Supporter!
    Moderator
    Rank:
     #41
    Points:
    633
    Posts:
    4,494
    Joined:
    May 2, 2012

    May 2, 2012
    4,494
    3,159
    633
    Male
    Student
    USA
    There are other shells...
     
  22. jonbanjo

    jonbanjo Well-Known Member
    Rank:
    None
    Points:
    43
    Posts:
    208
    Joined:
    May 26, 2013

    May 26, 2013
    208
    49
    43
    UK
    csh looks nicer to me but (at least for my own use). I don't see the point of using a shell for the sake of maybe doing the right thing.
     
  23. EarlyMon

    EarlyMon The PearlyMon
    Rank:
     #1
    Points:
    5,218
    Posts:
    57,632
    Joined:
    Jun 10, 2010

    Jun 10, 2010
    57,632
    70,421
    5,218
    New Mexico, USA
    Shell + sed + awk and you can do nearly anything.

    Lot of scripting languages came later to help those finding that path too difficult.

    I once took weeks and found a way to pass variables by reference in csh, something that is known undoable, just because.

    And bash is a hippie's approach to ksh. :D
     
  24. MoodyBlues

    MoodyBlues - Crazy peacock person -
    Thread Starter
    Rank:
    None
    Points:
    343
    Posts:
    3,353
    Joined:
    Jan 27, 2011

    Jan 27, 2011
    3,353
    1,580
    343
    Formerly UNIX/Linux programmer/sysadmin, now disab
    /home/LosAngeles
    You're right. My quick glance at that line shouldn't have been so quick. :D

    Yes, that's it.
     
  25. MoodyBlues

    MoodyBlues - Crazy peacock person -
    Thread Starter
    Rank:
    None
    Points:
    343
    Posts:
    3,353
    Joined:
    Jan 27, 2011

    Jan 27, 2011
    3,353
    1,580
    343
    Formerly UNIX/Linux programmer/sysadmin, now disab
    /home/LosAngeles
    I'd throw grep in there, too.
     
    EarlyMon likes this.

Share This Page

Loading...