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 all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Do's and Don'ts of Linux

  • 27-09-2014 9:37pm
    #1
    Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    So I thought it might be an idea to start a thread for the provision of some useful tips and tricks. If this has been done to death or it's better to just start a thread and ask, then no worries.

    Tonight though, I learned the hard way to not run the following as root or a user regardless

    chmod -f -R 777 / | chown -f -R 777 /


Comments

  • Closed Accounts Posts: 824 ✭✭✭Kinet1c


    Itzy wrote: »
    So I thought it might be an idea to start a thread for the provision of some useful tips and tricks. If this has been done to death or it's better to just start a thread and ask, then no worries.

    Tonight though, I learned the hard way to not run the following as root or a user regardless

    chmod -f -R 777 / | chown -f -R 777 /

    I did this very early on too, it was a good lesson to learn :)

    Turning it off and on again tends not to apply with *nix (very rarely imo anyway) as it does with Windows.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    I know :P It's a good lesson is shít you don't do, that's why I believe that if you want to try things out, try it out in a VM first.


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


    Less of an issue nowadays but dont login to your desktop environment as root.

    If you've not updated bash since last weekend, do it now.

    The -y option on yum and I believe Apt-get also, answers yes for all questions. Don't get into the habit of using it by default. There will be a day when removing one library removes your entire desktop.

    Use SSH keys. Dont use password-less keys unless its a very low priority system. I use a password-less key on my media centre so I can push stuff to it easily. Thats it. Every other system requires a pass phrase.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    syklops wrote: »
    The -y option on yum and I believe Apt-get also, answers yes for all questions. Don't get into the habit of using it by default. There will be a day when removing one library removes your entire desktop...

    apt-get upgrade -y


  • Registered Users Posts: 104 ✭✭justjustin


    syklops wrote: »
    If you've not updated bash since last weekend, do it now.
    Why do you say this? Is this meant as a general "Make sure your bash is up to date" remark, or is it in relation to some issue of late?

    I've always used manual upgrading on my linux boxes, apart from when I or someone else may be using a GUI on that box, e.g. HTPC and one laptop.


  • Advertisement
  • Closed Accounts Posts: 2,267 ✭✭✭ Eddie Crooked Muffler


    Old one, but don't run this in bash/bash-like shell:
    :(){ :|: & };:
    


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    Old one, but don't run this in bash/bash-like shell:
    :(){ :|: & };:
    

    Dear I ask what hazardous behaviour this will inflict?


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


    justjustin wrote: »
    Why do you say this? Is this meant as a general "Make sure your bash is up to date" remark, or is it in relation to some issue of late?

    The shellshock vulnerability was reported on Wednesday just gone, its a remote code injection vulnerability(pretty much the worst kind).


  • Registered Users Posts: 104 ✭✭justjustin


    Old one, but don't run this in bash/bash-like shell:
    :(){ :|: & };:
    

    Fork off!!


  • Closed Accounts Posts: 2,267 ✭✭✭ Eddie Crooked Muffler


    Itzy wrote: »
    Dear I ask what hazardous behaviour this will inflict?

    http://en.wikipedia.org/wiki/Fork_bomb


  • Advertisement
  • Registered Users Posts: 104 ✭✭justjustin


    Itzy wrote: »
    Dear I ask what hazardous behaviour this will inflict?

    Can't post links.

    Google "Linux fork bomb"


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    Sounds like fun :P


  • Registered Users Posts: 1,193 ✭✭✭liamo


    You could do worse than get into the habit of using screen when you log in over ssh.

    I have a script called startScreen.sh in my home directory
    #!/bin/bash
    if [[ -n $STY ]] ; then
     echo "Already attached to a screen session"
    else
     screen -R
    fi
    

    I've also added alias r="~/startScreen.sh" to my .bashrc giving me a quick and easy one-key shortcut to creating a new session or re-attaching to an available detached session.
    (Yes, "alias s" would be more intuitive but that's already in use)

    If you kick off a remote apt-get upgrade or a long compile or other operation it's comforting to know that a dropped connection won't kill your ongoing work or damage your system.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    Depending on how this thread goes, we could nearly put together a mini manual for noobs and novices.


  • Closed Accounts Posts: 2,267 ✭✭✭ Eddie Crooked Muffler


    liamo wrote: »
    You could do worse than get into the habit of using screen when you log in over ssh.

    I have a script called startScreen.sh in my home directory
    #!/bin/bash
    if [[ -n $STY ]] ; then
     echo "Already attached to a screen session"
    else
     screen -R
    fi
    

    I've also added alias r="~/startScreen.sh" to my .bashrc giving me a quick and easy one-key shortcut to creating a new session or re-attaching to an available detached session.
    (Yes, "alias s" would be more intuitive but that's already in use)

    If you kick off a remote apt-get upgrade or a long compile or other operation it's comforting to know that a dropped connection won't kill your ongoing work or damage your system.

    Just an addition to this.

    tmux is an alternative to screen.

    You can keep commands alive without the use of screen/tmux also if your terminal dies, by launching the command with nohup.


  • Registered Users Posts: 1,477 ✭✭✭azzeretti


    Itzy wrote: »
    Depending on how this thread goes, we could nearly put together a mini manual for noobs and novices.

    I think that's a great idea, the format might have to change a little though.

    Quick DO:
    Add aliases for potentially dangerous commands especically if coming from Windows, where there are plenty of "Are you sure?" questions afer a command. A simple example is `rm`. By default `rm` will blindy obey however if you add this: alias rm='rm -i' to your .bashrc it will add a bit of security by prompting to confirm your deletion.

    You can change to upper case 'I' for prompting to remove many files or recursive command.


  • Registered Users Posts: 1,193 ✭✭✭liamo


    tmux is an alternative to screen.
    A short Google later .... looks very interesting. New toy to play with this evening.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    Handy little command to get the number of files in a dir:
    ls -l . | grep -c '^-'

    And if you can't be arsed typing all of that out:
    alias numFiles='ls -l . | grep -c '^-''

    Then use numFiles instead.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    The joy of alias'. They seem to disappear when you close a session. How do you make them stick or save them? Go /home/YourACName/Desktop

    ls -a and you'll find .bashrc is in the directory as a hidden file. If you're brave, vi .bashrc and add your alias name='command' to the end of the file. esc :wq to save and exit the file. The alias will remain to use at your convenience.


  • Moderators, Computer Games Moderators Posts: 4,281 Mod ✭✭✭✭deconduo


    Itzy wrote: »
    The joy of alias'. They seem to disappear when you close a session. How do you make them stick or save them? Go /home/YourACName/Desktop

    ls -a and you'll find .bashrc is in the directory as a hidden file. If you're brave, vi .bashrc and add your alias name='command' to the end of the file. esc :wq to save and exit the file. The alias will remain to use at your convenience.

    I thought .bashrc is usually just in the /home/username dir? I've never seen it in /home/username/Desktop before, though that might be the case for some distros.

    Sidenote: ~ is short for the current user's home directory. So /home/username/.bashrc could also be written as ~/.bashrc


  • Advertisement
  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    You would be right actually, my bad.


Advertisement