OMG! 5! – Five Terminal commands/tips

imageToday's daily 5 aims to free up some of your time with some nifty terminal commands.

sudo !!

Ever entered a command but left off the 'sudo' ? Instead of typing the entire thing again, or back-arrowing to the start, just type the following to run the previous command as root.

  • sudo !!

Kill a rogue application using its name

Instead of hunting around the System Monitor to kill a rogue application, just killall it

  • killall app_name

Force install a 32bit application in 64bit

This is one mainly of use for 64bit users but applicable for installing lpia .debs, too. It won't always work but it's worth knowing anyway. To force install a 32bit in deb in 64bit Ubuntu run: -

  • sudo dpkg -i –force-architecture path/to.deb

Auto-complete using TAB

Hopefully you already know this one: typing a command and then hitting the TAB button will auto-complete the command for you. Try it out – type ”gnome-system-m€ and then hit the TAB button – it will auto-complete to gnome-system-monitor.

If there is more than one match possible it will list them.

Pasting commands

If you're reading this blog you've probably pasted commands into a terminal before. Instead of manually using the menu to paste commands into the terminal just press CTRL+SHIFT+V together or use your middle mouse button.

There is a metric tonne of more commands and terminal tips, so be sure to share your wisdom and tricks below!

No related posts.

Post a comment or leave a trackback: Trackback URL.
  • http://mikethecoder.com Mike Crittenden

    One little-known one that I use all the time: in a terminal, hit Ctrl+R, then start typing. It will search your history as you type and complete your command based on commands you’ve entered before.

    Try it: hit Ctrl+R and start typing a command you’ve typed before. It’s great for commonly used commands.

    • daas88

      Great tip dude! thanks!

    • Anonymous

      Ah yes, reverse search :) Gotta love that one. I also use it a lot for ssh, since I only connect to one other computer and this way I can avoid having to remember the darn ip every time.

      • J.

        Looked at using ~/.ssh/config?

        • Anonymous

          Not really, what can you do with it?

          • J.

            Register aliases; then just ‘ssh alias’ to connect.

          • Anonymous

            Really now… I’ll definitely check this out :) Thanks!

          • Guest

            Then you can store the ssh_config file in ubuntu one folder and make a link in ~/.ssh/ and you have your ssh aliases synced :-D

      • Mkarnicki

        you can also define a simple
        alias myfavhost=”ssh …..”

        in your .bashrc, and after you re-open the terminal, just use:
        $ myfavhost
        :)

    • Praveen

      Was trying to search this kind of command for very long time. Thanks

    • Guest

      and ctrl+r again and again to cycle through all

  • http://twitter.com/tedil tedil

    for “history-auto-completion” (say you have typed “someapp –alot –of –parameters” or some variation thereof and that’s already some time ago, you’d probably either end up arrowing-up all your way back to that command, or, if you’re more experienced, hitting ctrl+r to search your history. This, however, allows you to type the first few characters of the command you’re looking for, and when you press arrow-up [or down] it will automatically search your history)
    append
    bind ‘”e[A”‘:history-search-backward
    bind ‘”e[B”‘:history-search-forward
    to your ~/.bashrc
    source ~/.bashrc

  • http://twitter.com/om26er omer akram

    I didnt know the first one

    • Anonymous

      Me too.

  • http://el-bhm.myopenid.com/ el-bhm

    Shift+Insert

    Far easier than weird combo of Sh+Ct+V

  • http://snappytux.com/ snappytux

    awesome

  • Skoal

    I recommend pkill instead of killall…

    • WindPower

      Indeed.

      • http://twitter.com/jfigueroaNYG Jorge Figueroa

        whats the diffrence?

        • http://el-bhm.myopenid.com/ el-bhm

          pkill will use proces’ ids
          killall uses name.
          Overall pkill ends up being more successive.

          • Anonymous

            Do you mean successful?

          • http://el-bhm.myopenid.com/ el-bhm

            Nope. I’m that badass.

        • Guest

          After googling for 10 seconds, I guess pkill doesn’t require a perfect match in the application string. So pkill firef would kill firefox but killall firef wouldn’t.

          • http://omgubuntu.co.uk/ d0od

            Ooooh. this thread is teaching me so much :D

  • Blazé

    I always change shift+ctrl+v into ctrl+v – same for copy – under “Keyboard shortcuts”.

    Is there any reason not to do so?

    • Anonymous

      yes, CTRL+C terminates the currently running program

      (i don’t know what CTRL+V does but probably something)

  • https://creativecommons.net/johnnieingram Count Jocular

    Use “cd -” to move back to the directory you were in before your most recent ‘cd’ command. Thus:me@mybox > pwd/home/me/dir1me@mybox > cd ~/foo/bar/zar/chunky_baconme@mybox > pwd/home/me/foo/bar/zar/chunky_baconme@mybox > cd -me@mybox > pwd/home/me/dir1It’s embarrassing how many years (yes – *years*) I’d been using Bash before somebody showed me this.

    • Anonymous

      No “cd ..” goes up one directory:

      jordanwb@JORDAN-CD3CDA3B:~$ cd /etc/udev/
      jordanwb@JORDAN-CD3CDA3B:/etc/udev$ cd ..
      jordanwb@JORDAN-CD3CDA3B:/etc$

      • Guest

        “cd -” (with a dash) returns to the previous directory

    • Anonymous

      i thought “cd ..” just went up a directory?

    • https://creativecommons.net/johnnieingram Count Jocular

      Well, that was embarrassing. I meant, of course, “cd -”.

      It is late in the day. I have not had enough coffee.

      • Anonymous

        are, that makes more sense (i didn’t know the dash one)

  • rkv

    the best one is the ” .” (alt dot)
    example:
    $cd verybigname
    bash: cd: verybigname: No such file or directory
    $mkdir . –> this will result in the last argument in the last command to come down

    :D

    • Bjul

      Sweet … same as esc .

  • J.

    “Instead of typing the entire thing again, or back-arrowing to the start”

    Up-home?

    • http://www.displayblock.com/ Matt

      I use the up-home method myself. Didn’t know about sudo !!. I think I’ll stick to up-home as well, that way I know for a fact that it will run the command I want. Don’t want to sudo something I didn’t mean to.

  • Anonymous

    paste in terminal:

    shift+insert

    • Jenny

      It’s great to find out about these key combinations.. but I’ll probably still forget, as I currently do… I usually hit ctrl+v out of habit, swear, then do a right-click -> Paste :P

  • guerda

    For pasting, it’s easier to manage it with tah old style shortcut:
    Ctrl + Ins for copying, Shift + Ins for pasting. Special trick: Shift + Del for cutting!

    This combination works in the terminal and it’s easier to grab than Ctrl + Shift + V.

  • http://llawwehttam.blogspot.com Matt

    I use a lot of bash aliases in my -bash_aliases file. On some systems you have to add this file into your .bashrc.

    I have quite a few for instance:

    alias install=’sudo apt-get install ‘
    alias update=’sudo apt-get update && sudo apt-get upgrade’

    are probably my two most common ones but I have a collection that must have at least 50.

  • Anonymous

    I really like the Alt- shortcuts.

    When you are part way through typing a command such as
    $ cd verybigname
    and you remember that verybigname doesn’t exist yet you can hit Alt-Q to put what you have typed so far into a buffer and give you an empty prompt again. Then you can run a single command and it’ll put the buffer back onto the shell. For example after realising the directory doesn’t exist hit Alt-Q then
    $ mkdir verybigname
    will leave you with a shell that looks like:
    $ cd verybigname

    Alt-B and Alt-F are useful – they let you go back and forwards by words instead of by letter. Also Alt- deletes by word.

  • http://twitter.com/holmythegr8 Shawn holmes

    You’re a freakin’ genius! I love this place. “Middle click to insert”!! Thank you!

    • http://omgubuntu.co.uk/ d0od

      Hah! It’s crazy how some of these tips/shortcuts aren’t more well known given they’re so simple + useful :D

    • https://launchpad.net/~navneethc Navneeth

      Apart from the times he gets…how should I put this?…a little too excited over some wallpapers, this place is OK. ;-)I’ve found some very useful commands already in the comments and of course a couple in the post. Many thanks to those sharing them.

      • http://omgubuntu.co.uk/ d0od

        Heh! :P

  • Anonymous

    paste in terminal:

    shift+insert

    another very usefull thing: && separator!!!

    If you want to run two commands, you can do it by writing each one in different lines, but if you want to save some time and wait, you can write it in one line by using the && connector.

    in classic 2 lines mode:
    sudo apt-get update
    sudo apt-get upgrade

    in short with one line:
    sudo apt-get update && sudo apt-get upgrade

    …additionally, you can add the -y option to upgrade, so it wont ask you if you want to install packages, which is obvios because you are running the command, so, if you want to have the latest versions in your ubuntu, just type:

    sudo apt-get update && sudo apt-get upgrade -y

    chears!

    • http://omgubuntu.co.uk/ d0od

      The && very nearly made it into the list, actually – but i never knew about the -y switch, cheers! :D

      • Anonymous

        I’m glad! Enjoy!

    • Anonymous

      And putting a & at the end will open a program from the terminal and keep it running in the background, letting you do other stuff in the same terminal tab meanwhile.

      For instance, “gnome-calculator” will open the calculator but the terminal will be dedicated to it only and won’t allow you to do other things. “gnome-calculator &” will open the calculator in the background, so you can do other stuff with the terminal. This can be useful when working without X as well.

      • Anonymous

        Very interesting… I saw it somewhere, but I didnt understood what was it for. Thanks, now I can use a simple & at the end to run gtk apps. It is very usefull, specially because the alternative is to open ANOTHER terminal… really unconfortable, but now in the past :)

        • Anonymous

          I’m glad someone found the tip useful :)

    • https://launchpad.net/~phiphi.g Philipp Gassmann

      Shift+Insert and middle click don’t paste what you copied but simply what you’ve selected with the mouse.

      This works not just in the terminal, but almost everywhere on Linux. So you can select a URL or anything you want to copy/paste. then you can middle click with your mouse where you want to have it.
      ! It is pasted where your mouse cursor is, not where the text cursor is ! you dont have to set the text cursor where you want to paste it, just place your mouse and middle click.

      • Anonymous

        Cool! I didnt knew that… I dont have middle button in my laptop though… :P But I will keep in mind!!!

        • Bluecanary9999

          Clicking both mouse buttons simultaneously might produce a middle-click. You can try it on a link in a web-browser like Firefox; “middle-clicking” the link should open it in a new tab.

  • edlt

    oo. I like sudo !!

  • http://profiles.yahoo.com/u/C6S22ANL35LHAH27EX43XFQKTQ Klau3

    I love .bashrc xDEnter this to get there:gedit ~/.bashrc &Thats some of the stuff I added (just add them to the end of your file if you want):http://pastie.org/999674

  • https://launchpad.net/~xraya4t XRayA4T

    TAB will also complete parameters. e.g. sudo apt-get in auto completes to sudo apt-get install

    It will also list parameters. e.g. sudo apt-get lists :
    autoclean build-dep clean dselect-upgrade purge source upgrade
    autoremove check dist-upgrade install remove update

  • Donniezazen

    Great post! It would be great idea that you weekly write a post on 5 new Ubuntu/Linux commands. This will help the beginner to join the advance club.

    • Don

      I second this idea. 5 per week for the fledglings to move up in their knowledge.

      • http://omgubuntu.co.uk/ d0od

        Excellent idea!

  • Jman6495

    why not an imperial ton ?

    • Guest
  • Pablo Marchant

    I recently discovered ctrl+r, it allows you to type and do an incremental search on older commands you have run (you can type any part of the command, not neccesarily from the beggining). Very useful instead of looking back trough tons of commands just to remember how you did something a week ago…

  • DFX

    Add the following to your /etc/inputrc to get incremental command history (à la Matlab) in the command window.

    # MATLAB style search
    “e[A”: history-search-backward
    “e[B”: history-search-forward
    “e[C”: forward-char
    “e[D”: backward-char

  • Anonymous

    Tab isn’t just for commands too, you can auto-complete file names, programs, or combinations of both.

  • http://twitter.com/TheSofox Sofox

    Dang, how did I not know of that middle clicking pasting in Terminal.

    Know now anyway.

    • Valid-ed

      not just the terminal, it works everywhere.

  • Anonymous

    Instead of sudo !! , I always just pressed the up arrow then the HOME key if I forgot to put sudo in front. This was because I didn’t know about that tip but now it’s a habit :P

    That tip will help under a TTY and such though. :D

  • Anonymous

    I like this one –

    whatis linux

  • http://twitter.com/RabidWeezle Adam Smith

    Some tricks I like:

    quickly get to the home folder:
    cd[enter]

    piping the output of one app to the input of another (you need to ‘sudo apt-get install cowsay’ for this):
    uptime|cowsay

    using tab completion for installing packages:
    sudo apt-get install frozen-[tab][tab]

    wildcards I love for cleaning my downloads folder quickly:
    rm ~/Downloads/*
    (or if I just want to remove a bunch of pictures)
    rm ~/Downloads/*.jpg

  • Ubuntu Dan

    Great post I need all the help I can get. I was really confused when I first started using Ubuntu as I was used to windows commands. I gathered a heap of terminal commands on my blog Ubuntu dan. I hope they help

    http://www.ubuntudan.com/2010/07/beginners-guide-to-ubuntu-terminal.html