Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 51

Thread: Handy command-line aliases and tricks

  1. #11
    Join Date
    Apr 2006
    Beans
    Hidden!
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Handy command-line aliases and tricks

    Let's not forget to mention one of the greatest tips -- how to cancel any running program in CLI ! Ctrl+C. I realize you mention it with bash history search, but people might take it to be a function of *just* that search.

  2. #12
    Join Date
    Jul 2006
    Beans
    23

    Re: Handy command-line aliases and tricks

    Quote Originally Posted by mssever View Post
    Put the aliases in ~/.bashrc, not ~/.bash_profile. .bash_profile only gets read by login shells (e.g., at the console or via ssh). All shells, however, read .bashrc.

    EDIT: You don't have to restart your computer. Type exit and restart the shell, and if your aliases are in the right place, they will be available.
    worked like a charm, thanks for the information, that would have drove me nuts all day tomorrow. also, thanks for explaining why, helps a ton

  3. #13
    Join Date
    Nov 2005
    Beans
    2,322
    Distro
    Ubuntu Intrepid Ibex (testing)

    Re: Handy command-line aliases and tricks

    Quote Originally Posted by mssever View Post
    Put the aliases in ~/.bashrc, not ~/.bash_profile. .bash_profile only gets read by login shells (e.g., at the console or via ssh). All shells, however, read .bashrc.

    EDIT: You don't have to restart your computer. Type exit and restart the shell, and if your aliases are in the right place, they will be available.
    I suggest to use .bash_aliases for custom aliases. This file can be sourced from ~/.bashrc by uncommenting the following
    Code:
    if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
    fi
    I recently found handly command line trick, Ctrl-w for cut last word and Ctrl-y to paste it back.
    I often find myself renaming/copying files to slightly different name, and this comes very handy for that purpose.

    Maybe my most often used alias is
    Code:
    alias lsd='ls -d */'
    Building on Ubuntu using [pbuilder]
    Other resources [Upgrading from CVS, Gaim2, Anjuta, Rhythmbox]

  4. #14
    Join Date
    Jul 2006
    Beans
    23

    Re: Handy command-line aliases and tricks

    this isnt exactly alias, but i tried to make a function that shows the date (i found it on a site) and i put it into .bashrc just like alias' and nothing happened. Any suggestions?

  5. #15
    Join Date
    Mar 2005
    Beans
    Hidden!

    Re: Handy command-line aliases and tricks

    Quote Originally Posted by mssever View Post
    If you have any other aliases, etc. that might be useful to others, please add them here.
    Use history expansion to save typing

    As an example, let's assume I want to install a program foobar:

    Code:
    apt-get install foobar
    That fails because I forgot sudo. Now I could hit the up-arrow to go back to the last command, scroll to the beginning of the line and add sudo, but it's easier to just type this:

    Code:
    sido !!
    !! will be substituted with the entire last command in the history, so it is equivalent to:

    Code:
    sido apt-get install foobar
    Which still won't work because I misspelled sudo.
    Typing

    Code:
    ^i^u
    will replace the first occurance of i in the previous command with u, thus fixing the mistake:

    Code:
    sudo apt-get install foobar

    Now to run the program foobar I just type:

    Code:
    !$
    which will be substituted with the last argument of the previous command, i.e. foobar.

    Info on more advanced history expansion can be found in the bash manual:
    http://www.gnu.org/software/bash/man...ef.html#SEC114

  6. #16
    Join Date
    Mar 2005
    Beans
    Hidden!

    Re: Handy command-line aliases and tricks

    Quote Originally Posted by sublimeprogie View Post
    this isnt exactly alias, but i tried to make a function that shows the date (i found it on a site) and i put it into .bashrc just like alias' and nothing happened. Any suggestions?
    Post the relevant part from your .bashrc, it's hard to tell what could be wrong without the specifics.

  7. #17
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Handy command-line aliases and tricks

    Quote Originally Posted by kabus View Post
    Use history expansion to save typing
    Great tip! Thanks.

  8. #18
    Join Date
    Jul 2006
    Beans
    23

    Re: Handy command-line aliases and tricks

    Quote Originally Posted by kabus View Post
    Post the relevant part from your .bashrc, it's hard to tell what could be wrong without the specifics.
    sorry, forgot to post that along with it

    Code:
    function today {echo "Today's date is:"date +"%A, %B %-d, %Y"}
    
    alias l='ls -la'

  9. #19
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: Handy command-line aliases and tricks

    Quote Originally Posted by sublimeprogie View Post
    Code:
    function today {echo "Today's date is:"date +"%A, %B %-d, %Y"}
    Try this:
    Code:
    function today { echo -n "Today's date is: "; date +"%A, %B %-d, %Y"; }
    Alternatively, you can display it thus:
    Code:
    function today {
        echo -n "Today's date is: "
        date +"%A, %B %-d, %Y"
    }
    The single-line version requires each line to be terminated with a semicolon.

  10. #20
    Join Date
    Jul 2006
    Beans
    23

    Re: Handy command-line aliases and tricks

    Quote Originally Posted by mssever View Post
    Try this:
    Code:
    function today { echo -n "Today's date is: "; date +"%A, %B %-d, %Y"; }
    Alternatively, you can display it thus:
    Code:
    function today {
        echo -n "Today's date is: "
        date +"%A, %B %-d, %Y"
    }
    The single-line version requires each line to be terminated with a semicolon.
    thanks alot, i figured something was just missing from the funtion, i just had no clue what it would be

    *edit: ok that didnt seem to take either

    this shows up when i open my terminal

    Code:
    bash: /home/me/.bashrc: line 11: syntax error near unexpected token `}'
    bash: /home/me/.bashrc: line 11: `}'
    Last edited by sublimeprogie; July 18th, 2006 at 09:23 PM.

Page 2 of 6 FirstFirst 1234 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •