The command line 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).
Advertisement
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.)
Geek to Live: Introduction to Cygwin, Part I
Introduction to who? If that's what you thought when you saw the title of this article, thenâ¦
Read more Read
Advertisement
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.
7 days to die edit player file. Advertisement
A Command Line Primer for Beginners
The command line isn't just for wise Linux beards. It's actually an awesome tool withâ¦
Read more Read
Basic Keyboard Shortcuts
We 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.
Advertisement
Advertisement
Terminal Shorthand
Whether 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.
Advertisement
File Paths
When 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.
Advertisement
Dragging Files Into the Terminal Window
If 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.
Advertisement
File Path Shorthand
We discussed these briefly in our beginner's guide, but they bear repeating. Say you're
cd ing around your hard drive but don't want to type out file paths over and over again. If you need to continually access the same folders or files, dragging them in from your file browser can even get tedious. Luckily, you can substitute your current directory and its parent directory with . and . , respectively. For example, if you cd to a folder, running the following command will move you one folder up.
Advertisement
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).
Advertisement
This also works if you're typing out longer paths. Say you're in
~/Documents/Work and you wanted to be in ~/Documents/Play . You could just type:
and get there instantly.
Another good shortcut is the dash (
- ). This will move you back to your last working directory:
Thus, if you're working in, say, your documents folder (
~/Documents ) and moved over to the /etc/ briefly, you could switch right back by typing cd - and hitting Enter.
Advertisement
Lastly, if you want to go back to your home directory, there's no need to add any arguments to the
cd command. Just typing cd and hitting enter will bring you back home.
Using Your History
Accessing 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 (!).
Advertisement
One of the most useful shortcuts is using
!! to represent the last command you ran. This is useful in a ton of situations. For example, if you run a command that needs root privileges but forget to add sudo to the beginning, there's no need to retype the command. Just run:
This will run your last used command with root privileges.
Advertisement
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
cat , you could just type:
If you just want to see what the last
cat command was, you can instead run:
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
!! and hit Enter.
Advertisement
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
cd into that directory, you could just type:
The
!$ represents the arguments from your last command.
Another common problem is mistyping the command you want to run. Say you wanted to run
nano , but accidentally typed nanp :
Instead of retyping the whole thing, you could just run:
This will find the first instance of
nanp in the last run command and replace it with nano .
Advertisement
While all these shortcuts are fine and dandy, but it's worth mentioning that the
history command is your friend. If you want to see all the recent commands you ran that included nano , for example, you could just run:
You'll get a list that looks something like this:
Advertisement
You can then pick a command out from that listâsay I want to run
sudo nano /boot/grub/menu.lst , which grep lists as command 455 âand run it using:
Lastly, if you want to keep certain commands out of your history, just put a space before themâi.e. space+
nano ~/Documents/WorldDominationPlans.txt .
Advertisement
Expansions
When 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 (
{} ), you can easily perform batch operations on multiple versions of a file.
Advertisement
Say you want to rename just part of a filename. Instead of typing out
mv /path/to/file.txt /path/to/file.xml , you could just run:
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.
Advertisement
![]()
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
rc.conf , you'll want to make a backup in case the new one doesn't work. So, to do so, you can just run:
Putting nothing before the comma will just append
-old to the filename after copying it with cp . If your new file doesn't work out and you want to restore the backed up file to its original location, you can just use:
Moving the comma to the other end of the brace will remove
-old from the end of the file and restore it to its original name.
Advertisement
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 Shorthand
Advertisement
While 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
~/.bashrc configuration file (or, if you're on Mac OS X Snow Leopard, ~/.bash_profile ). It's a basic text file, so you can do it with whatever you likeâGedit in Ubuntu, TextEdit on OS X, or even nano within the Terminal. We've talked about doing thisa few times before, but it really is one of the best things you can do to speed up Terminal work.
Turbocharge your terminal
Click to viewWhile the command line isn't the most intuitive place to work, terminal loversâ¦
Read more Read
Advertisement
To create a custom shortcut (called an
alias or function , you'll want to add a new line to your .bashrc file using the following format:
Now, whenever you type
la , the Terminal will run ls with the -a modifier, which includes hidden files. Some of thsee are built into popular Linux distributions already, but there are a ton of other useful ones. Here are some of our favorites:
This gives you a more verbose list of files than
ls does on its own. In Ubuntu, this shortcut already exists, but runs ls -alF .
Advertisement
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.
Advertisement
![]()
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.
Advertisement
With this, installing programs is much quicker in Ubuntu. You can just type
agi chromium to install Chromium, for example. Of course, if you're using a different flavor of Linux, you can replace it with your package manager of choice.
Advertisement
Build a Killer Customized Arch Linux Installation (and Learn All About Linux in the Process)
Don't like Windows 8's new interface? Sick of Ubuntu Unity and the new ads that comeâ¦
Read more Read
This will update all your packages in Ubuntu.
This is a neat function we've featured before that will essentially run
cd and ls at the same time. So, just type cdl /path/to/folder and the Terminal will both make that your working directory and list its contents in one fell swoop.
Advertisement
Change Directories and View Files in One Custom Command
We occasionally enjoy geeking out at the command line, so we love timesaving Terminal shortcuts.â¦
Read more Read
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
alias and function , the only limits are your imagination (though if you aren't that imaginative, we post some good ones around here from time to time). Got any of your own favorites that you'd like to share with us? Sound off in the comments.
Advertisement
Simply powerful.
Using a Mac has always inspired great work. Now macOS Mojave brings new features inspired by its most powerful users but designed for everyone. Stay better focused on your work in Dark Mode. Automatically organize files using Stacks. Take more kinds of screenshots with less effort. Try four handy new built-in apps, and discover even more in the redesigned Mac App Store. Now you can get more out of every click.
Dark ModePut your best work forward.
Dark Mode is a dramatic new look that helps you focus on your work. The subtle colors and fine points of your content take center screen as toolbars and menus recede into the background. Switch it on in the General pane in System Preferences to create a beautiful, distraction-free working environment thatâs easy on the eyes â in every way. Dark Mode works with built-in apps that come with your Mac, and third-party apps can adopt it, too.
Choose what works best for you â the familiar light appearance or the new Dark Mode.
Dynamic DesktopA desktop whose time has come.
Introducing two new time-shifting desktops that match the hour of the day wherever you are.
Slide to see how the Dynamic Desktop changes throughout the day.
StacksA really neat way to manage files.
Stacks keeps your desktop free of clutter by automatically organizing your files into related groups. Arrange by kind to see images, documents, spreadsheets, PDFs, and more sort themselves. You can also group your work by date. And if you tag files with project-specific metadata, like client names, sorting by stacks becomes a powerful way to manage multiple jobs. To scrub through a stack, use two fingers on a trackpad or one finger on a Multi-Touch mouse. To access a file, click to expand the stack, then open what you need.
FinderNew ways to view.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |