Announcement

Collapse
No announcement yet.

Bash Tricks and Tips requests

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bash Tricks and Tips requests

    Hey all, I am currently writing up a blog/article on some tips and tricks I have learnt during my use of bash. Is there anything in particuler that anyone would like me to add to it. My current plan was to talk about the following:

    History
    Jobs
    Sourcing files
    Short Cuts

    Is there any thing else I should cover or would be useful?

    I am also planning on writing one about zsh and its improvements over bash if there is anything you would like to know about that (although this one might have to wait until I have more free time).

    #2
    Originally posted by james147 View Post
    Is there anything in particuler that anyone would like me to add to it.
    Code:
    echo particuler | aspell -a
    hehehehehe...

    Comment


      #3
      Good one Steve...

      Personally, I would add using aliases as an important part of any article on bash. I do a lot of command line stuff (old DOS and Apple peeks and pokes geek) and I us the heck out of aliases.

      A couple of examples from my ~/.bash_aliases file:

      alias cp="cp -i" # confirm before overwriting something
      alias df='df -h' # human-readable sizes
      alias free='free -m' # show sizes in MB
      alias cd..='cd ..'
      alias ..='cd ..'
      alias suka='kdesudo kate'
      alias cate='kate'
      alias ssh='ssh -p 2222'
      alias ping='ping -c 5'
      alias blkid='sudo blkid -c /dev/null -o list'

      You can use these to prevent your personally common typos like 'cd..' instead of 'cd ..' and shortcuts like 'suka' for superuser editing, automatically setting ssh ports or ping limits, etc.

      Please Read Me

      Comment


        #4
        Well, thinking about this a bit more...
        • Differences between single and double quotes
        • Why $() is better than backquotes
        • The immense utility of xargs
        • Techniques for avoiding unnecessary subshells
        • Combine commands appropriately--
          • foo && bar when you want bar to run only if foo succeeds
          • foo || bar when you want bar to run only if foo fails

        Comment


          #5
          Originally posted by oshunluvr View Post
          alias cate='kate'
          What kind of left-over habit is cate?

          Comment


            #6
            Originally posted by SteveRiley View Post
            Code:
            echo particuler | aspell -a
            hehehehehe...
            heh, if only chromium had a pipe to terminal command or a decent bloody spell checker >

            Comment


              #7
              Left-handed kate?

              Actually, it came from typing "cat /somedirectory/somefile" and then wanting to edit it. I would typically up-arrow and backspace to replace "cat" with "kate". Rather than jumping about or backspacing all and retyping the "cat" into "kate" I just add the letter "e" and hit return.

              Genius!!!

              Please Read Me

              Comment


                #8
                Originally posted by oshunluvr View Post
                Personally, I would add using aliases as an important part of any article on bash. I do a lot of command line stuff (old DOS and Apple peeks and pokes geek) and I us the heck out of aliases..
                Aliasing is a good topic, thanks for that (some things are now so obvious to me I forget other don't know about them )

                Though I do admit I find it funnier to install the sl program rather then the sl alias but I think that is just the troll in me eating at my brain..

                Comment


                  #9
                  Originally posted by SteveRiley View Post
                  Well, thinking about this a bit more...
                  • Differences between single and double quotes
                  • Why $() is better than backquotes
                  • The immense utility of xargs
                  • Techniques for avoiding unnecessary subshells
                  • Combine commands appropriately--
                    • foo && bar when you want bar to run only if foo succeeds
                    • foo || bar when you want bar to run only if foo fails
                  To be honest I don't ever use the xargs program, never had a need for it :s so I only have a basic awareness of how it works. The only time I ever though about using it was with find, but then I found the -exec argument

                  The other areas I will probably include though, thanks for that I have also included >, >> and | to complete && || and &.

                  Comment


                    #10
                    Originally posted by oshunluvr View Post
                    Left-handed kate?

                    Actually, it came from typing "cat /somedirectory/somefile" and then wanting to edit it. I would typically up-arrow and backspace to replace "cat" with "kate". Rather than jumping about or backspacing all and retyping the "cat" into "kate" I just add the letter "e" and hit return.

                    Genius!!!
                    Going to cover this but you might be interest now:
                    $ cat somefile
                    $ kate !$

                    or my preferred method:
                    $ alias open=kde-open
                    $ cat somefile
                    $ open !$

                    bash history is such a wonderful thing

                    Comment


                      #11
                      Originally posted by SteveRiley View Post
                      Why $() is better than backquotes
                      Hmm, I seems to be struggling with thinking of a simple useful example of foo $(bar)

                      Comment


                        #12
                        Some more aliases Ive collected:

                        alias rm='rm -i' #Gives a prompt before removing
                        alias mv='mv -i' #Gives a prompt before overwriting
                        alias reload='source ~/.bashrc' #Reloads .bashrc file
                        alias ..='cd ..'
                        alias ...='cd ../..'
                        alias ....='cd ../../..'
                        alias .....='cd ../../../..'
                        alias f***x='xset -dpms' #Seriously, this needs to be fixed

                        Id also mention PATH and how you can add things to your path by adding lines to your .bashrc file.

                        Comment


                          #13
                          Originally posted by james147 View Post
                          Hmm, I seems to be struggling with thinking of a simple useful example of foo $(bar)
                          Code:
                          sudo apt-get purge $(deborphan)

                          Comment


                            #14
                            Originally posted by SteveRiley View Post
                            Code:
                            sudo apt-get purge $(deborphan)
                            Thanks for that, ironically the only useful example I could think of was
                            Code:
                            pacman -Rsunc $(pacman -Qqsdt)
                            Which is does exactly what your command does but for archlinux

                            Comment


                              #15
                              Originally posted by james147 View Post
                              Thanks for that
                              There are other examples. Someplace I found a very informative webpage explaining, with several examples, why $() is better than backquotes. I'll try to find it later when I'm on my PC.

                              Comment

                              Working...
                              X