By Whitson Gordon Become a Command Line Ninja With These Time-Saving ShortcutsThe command can be quite powerful, but typing in long commands and file paths gets tedious pretty quickly. Here are some shortcuts that will have you running long, tedious, or complex commands with just a few keystrokes. Image remixed from an original by xkcd. Power users love the command line for its ability to perform complicated tasks with just a few keystrokes. But for beginners who don't know the shortcuts and type everything out longhand, it can seem like it takes forever (I know this because I'm just past beginner myself, and I still didn't know most of these shortcuts). These commands apply primarily to *NIX-based command lines, which, out of the box, are included on systems like OS X and Linux. To use them on Windows, install Cygwin. (We highly recommend ditching Windows' crappy command line for Cygwin.) From simple keyboard shortcuts to built-in shorthand to commands you can build and customize yourself, the Terminal has a ton of ways you can speed up your command line work, and here we're going to show you some of the basics (as well some customizable features that you can use to shorten pretty much any command you want). If you're just getting started with the command line, we recommend you also check out our command line primer for beginners. Heck, even if you're not a beginner, skim through it—you're sure to find a few things you didn't know. We'll be touching on a few of those subjects and building on them here, too. Basic Keyboard ShortcutsWe went through a few basic keyboard shortcuts in our beginner's guide, but there are quite a few in there that, while not exactly intuitive, are incredibly useful just for navigating the shell. They also come in handy when you want to refer back to previous commands.
Terminal ShorthandWhether you make a lot of typos, run a lot of the same commands over and over again, or you're dealing with long, annoying file paths, the Terminal has quite a bit of built-in shorthand to keep you from typing everything out yourself. Here are a few great examples. File PathsWhen you're working with files in the Terminal, navigating the folder structure of your system can take forever. Constantly typing long filenames is never fun, so here are a few tricks that'll get those 5-folder-deep paths into the Terminal with just a few taps of your mouse or keyboard. Dragging Files Into the Terminal WindowIf you have a file buried deep within your hard drive, typing out its full path can take forever. Instead of doing that, you can just open up the folder in Nautilus, Finder, Dolphin, or whatever file manager you use and drag the file right into the Terminal window. It will add its file path to the current command. File Path ShorthandWe discussed these briefly in our beginner's guide, but they bear repeating. Say you're
That way, you don't have to retype the entire file path (or even hit the up arrow and delete a folder name—it's literally just a few keystrokes). This also works if you're typing out longer paths. Say you're in
and get there instantly. Another good shortcut is the dash (
Thus, if you're working in, say, your documents folder ( Lastly, if you want to go back to your home directory, there's no need to add any arguments to the Using Your HistoryAccessing recently used commands (or running a small variation of recently used commands) is something Terminal users often need to do. Unfortunately, it's also one of the most tedious parts of the Terminal—who wants to retype the exact same command they just ran but with one minor difference? It makes every typo seem like a punishment. Luckily, there's some pretty nice shorthand, most of which uses the handy bang symbol (!). One of the most useful shortcuts is using
This will run your last used command with root privileges. If the command you want to run is a bit further back in your history, you can use the bang in conjunction with the original string to find it. For example, if you want to run the last command that used
If you just want to see what the last
This will print that command and add it to the end of your history. If you decide you then want to run it, you can just type If you want to run a different command that you ran last, but with the same argument, there's a shortcut for that too. For example, say you had just created a folder using:
To then
The Another common problem is mistyping the command you want to run. Say you wanted to run
Instead of retyping the whole thing, you could just run:
This will find the first instance of While all these shortcuts are fine and dandy, but it's worth mentioning that the
You'll get a list that looks something like this:
You can then pick a command out from that list—say I want to run
Lastly, if you want to keep certain commands out of your history, just put a space before them—i.e. space+ ExpansionsWhen you're working with variations of a file—like backups or different file types—it can get tedious typing out the same commands with small tweaks. Using the brace symbols ( Say you want to rename just part of a filename. Instead of typing out
This runs the command with the same arguments, only with the parts inside the brace changed—the first part corresponding to the first argument, the second part corresponding to the second argument. The most common example of this is when you're backing up a file that you're making changes to. For example, if you are tweaking your
Putting nothing before the comma will just append
Moving the comma to the other end of the brace will remove The braces can also work when moving or creating multiple files at once. For example, if you wanted to create three numbered directories, you could just run:
This will create three folders: myfolder1, myfolder2, and myfolder3. Making Your Own ShorthandWhile these are all pretty handy, the most useful thing you can probably do is make up your own shortcuts. After all, we all have a few commands we run over and over again, but they aren't necessarily the same for everyone. To do so, we're going to edit the To create a custom shortcut (called an
Now, whenever you type
This gives you a more verbose list of files than
This will make your Desktop the working directory with just a few keystrokes. You can, of course, modify this for pretty much any folder that you access regularly.
This moves your working directory one folder up in half the keystrokes.
This is an example of an alias that opens up a file for editing. If you have any files you find yourself constantly editing, this is a good one to keep around—just throw the path to your oft-used file in the quotes and edit the keyword to something that makes sense.
With this, installing programs is much quicker in Ubuntu. You can just type
This will update all your packages in Ubuntu.
This is a neat function we've featured before that will essentially run These are just a few examples of the keyboard shortcuts, shorthand, and custom aliases that can make your life easier. There are really a ton out there, and depending on what you're using the Terminal for so often, different ones will prove useful to you. Of course, since you can make your own using | January 26th, 2011 Top Stories |
Wednesday, January 26, 2011
Become a Command Line Ninja With These Time-Saving Shortcuts
Subscribe to:
Post Comments (Atom)
CrunchyTech
Blog Archive
-
▼
2011
(807)
-
▼
January
(110)
- Learn to Code: The Full Beginner's Guide
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Find Time for Your Personal Life and Get a Handle ...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Why Should I Care About HTTPS on Facebook (or Othe...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Become a Command Line Ninja With These Time-Saving...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Everything You Need to Know About the Verizon iPho...
- Congratulations on your success in our 12th Annive...
- The Latest from Boing Boing
- Learn How to Code Part I: Variables and Basic Data...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Common Sense Security for Your iPhone
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Our Biggest Android Annoyances and How to Fix Them
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- How to Pick Your Next Android Phone: The Specs Tha...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Best Times to Buy Anything in 2011
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- How to Avoid Getting Screwed When Using Your Debit...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- How to Hone the Accuracy of Your Internal Clock an...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- How to Get Tomorrow's iOS Features Today
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- How To Perform Nearly Any Task From Your Browser's...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- De-Crapify Your Windows Printer or Scanner Setup
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Transform Your DSLR into a Supercharged, Professio...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- The Latest from Boing Boing
- Use the One-A-Month Technique to Adopt Habits that...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Why the Mac App Store Sucks
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- How to Create (and Stick to) a Realistic Budget wi...
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
- Resolved: Eat Better, Not Less, for a Healthier Diet
- The Latest from TechCrunch
- The Latest from TechCrunch
- The Latest from Boing Boing
-
▼
January
(110)
No comments:
Post a Comment