# GÓC CÔNG NGHỆ > Hệ điều hành > Linux > English Room >  Save Time in the Linux Terminal with These 20 Shortcuts

## phuonganh2012

The terminal can be an intimidating place, but there’s a good chance you will open one during your Linux experience. If you spend quite a bit of time there, you may find that it’s actually not so bad. I’ve come to prefer using the terminal for some tasks, such as installing and updating software.

Whether you’re a terminal newbie or someone who got over the fear long ago, there are ways you can make things go more smoothly. Here are 20 shortcuts that can help you overcome some of the command line’s awkwardness.



*Moving the Cursor*


At first, even moving around the terminal seems more difficult. Fortunately, it’s not harder, just different. Remove your hand from your touchpad, take a deep breath, and smile. The keyboard is about to become your best friend.

*1. Jump Between Parts of a Line*


Use *Ctrl + Left* and *Ctrl + Right* to move between the various parts of line. Let’s say you’ve typed out the following line.

dnf install kde-desktop-environment

Tapping *Ctrl + Left* moves you to the beginning of _environment_, _desktop_, _kde_, _install_, and _dnf_, in that order.

*2. Hop to the Beginning or End of a Line*


*Home* or *Ctrl + A* move the cursor to the beginning of the line. *End* or *Ctrl + E* moves you back to the end.

Which keys you use depends on your keyboard layout. Not all PCs have *Home* and *End* keys. MacBooks don’t. Either way, *Ctrl + A/E* should work.

*3. Clear Parts, or All, of a Line*


*Ctrl + K* takes everything from your current position to the end of the line and gives it the boot. *Ctrl + W* goes after only the word immediately before the cursor. *Ctrl + U* erases the entire line.

*4. Autocomplete a Command or Directory*


Pressing tab completes the name of the current command or directory.

Let’s imagine you’re navigating to your downloads folder using this line:

cd /home/user/Downloads

You can hit tab once you’re at _cd /home/user/Dow_ to automatically finish the word.

Say you want to install a bunch of apps using _apt-get install_. You can type _apt-get ins_ and hit tab.

When the terminal can’t predict what you’re trying to say, it typically lets you know with a beep.

*Recycling*


Those of us who grew up in the era of Windows and Mac have grown accustomed to clicking on icons to get stuff done. There’s none of that in the terminal. This means we need to type out every command. Fortunately, we have ways to avoid re-typing things over and over and over again.

*5. Switch Between Recently Used Lines*


Press the *Up* arrow to get to the last command you used. Tap it again to retrieve the one before that. Press the *Down* arrow if you’ve gone too far.

The terminal saves your history even when you close the window, so you can do this to recall commands you used days ago.

*6. Copy the Previous Line*


Let’s say you’re looking to repeat a command you just issued, but with root privileges. Chances are you forgot to begin the line with _sudo_ (more on this later). In that case, rather than retyping the entire command, you can simply enter:

sudo !!

The double exclamation points tell the terminal that you want to re-enter the previous line.

*7. Copy the Previous Line Containing a Specific Command*


What if the command you want to repeat isn’t the last one you used? The command illustrated above, _!!_, won’t work anymore. Instead, you’ll want to use a single exclamation point combined with the beginning of the command you wish to retrieve.

For example, you could use _!apt-get_, _!dnf_, or _!pacman_ to try checking for updates again. The technique also works with _cd_, _man_, and other essential commands.



*8. Copy the Previous Argument*


After copying and pasting a folder to a new location, you may want to start doing other things in that target directory. Try this:

cd !$

The _!$_ indicates the last argument used. Keep in mind, arguments consist of any information you give a command to complete a task, so directories are hardly the only things you can recycle using _!$_.

*9. Fix Typos*


Sometimes typos happen. In an article, they can lead to embarrassment. In the terminal, they stop commands from working. Fortunately, there’s an easy fix.

Let’s say you want to look up all the things you can do with Fedora’s package manager, DNF. To do so, you fire up your terminal and type:

man dfn

Well, that isn’t right. The terminal’s telling you that there is _“No manual entry for dfn.”_

You know this. To fix the issue, you type:

^dfn^dnf

When you hit enter, the terminal will repeat the command using the new spelling.

*Navigating Directories*


Launching applications is hardly the only thing you do on your computer, and the same is true once you dive into the terminal. Sometimes you simply have to move files around and dig through folders.

This comes with a learning curve, but with these basics memorized, you will get the hang of it in no time.

*10. Navigate to a Specific File or Folder*


As I was saying, manipulating files can be a real chore. You have to remember a file’s location and know how to type out the path explicitly. Who does that?

An easier approach is to drag a file or folder into the terminal. This will append the path to the end of your current command.



*11. Navigate Between Folders*


Once you’ve already started managing folders inside the terminal, dragging and dropping can start to feel like, well, a drag. At that point, these two dots will become your best friend. When you’re using _cd_ to move around, follow that command with _.._

No, that’s not an unfinished ellipses. Here, let’s try this.

cd ..

_cd_ followed by two periods will move you into the parent directory.

To switch between folders within the parent directory, use _cd .._ followed by the name. Pretend you’re managing files in your _/Music/Black_Eyed_Peas_ folder, you finish the job, and now you want to hop over to _/Music/Lindsey_Stirling_. Simply enter:

cd ../Lindsey_Stirling
*12. Return to the Previous Directory*


Halfway through editing files in _/Lindsey_Stirling_, you realize you forgot to remove one of the unnecessary album art images cluttering up your _/Black_Eyed_Peas_ folder. To get back instantly, use a dash. As in –

cd -
*13. Return to the Home Directory*


When you’re ready to go home, so to speak, just enter _cd_. That’s it.

*14. See Your Current Directory*


Okay, you’ve been navigating for a while, and you no longer know where you are. It happens. Enter _pwd_ to see the path to your location.

*15. Go to the Root Directory*


Oh, so you’re legit. If you’re looking to navigate straight to your root directory and start _cd_-ing around in the terminal, you clearly know your way around Linux. To get straight to the meat and potatoes of your operating system, use:

cd /
*16. Keep Root Access*


Yes, I could have placed this one anywhere on the list, but to manipulate any of the files in the root directory, you need administrator access. The best way to do this can vary depending on your distribution. One option is to place *sudo* at the beginning of your command.

Another approach, assuming you have the root password, is to use *su* instead. This will sign you in as the administrator and let you perform any changes you wish without worrying about re-entering your password. It can save time if you plan on making a bunch of modifications at the root level. But don’t do this if you’re even the slightest bit unsure of what you’re doing.

*Multitasking*


You’ve learned the basics. Now, are you ready to take your terminal-fu to the next level?

*17. Run Multiple Commands*


To do this, you’re going to need a couple ampersands. You run a command, enter _&&_, and follow up with a second task that will only begin if the first one doesn’t fail. Here’s an (admittedly silly) example.

echo "Where's Lindsey Stirling?" && echo "Here she is!" && cd /home/user/Music/Lindsey_Stirling

The terminal will display the text “Where’s Lindsey Stirling?” Then it will then say “Here she is!” before taking you to the appropriate music folder.

You can think of _&&_ as *and*. As in, you’re telling the terminal to do this *and* this* and* this.

*18. Run a Command with a Backup Plan*


The double ampersands signal to run the subsequent command only if the previous one succeeded. Maybe you want the opposite, to run a command only if the first one _fails_. In that case, swap _&&_ for _||_.

*19. Run a Command in the Background*


Place a single & at the end of a line. The terminal will show you a process number and then, so long as nothing went wrong, return back to normal as though nothing were going on.



To see which processes are currently running, enter the *jobs* command. You can use *kill* followed by the process number provided to force a task to stop running. Alternatively, you can bring the operation back to the foreground using *fg*.

*20. Run Multiple Commands in the Background*


As you might expect, the _&_ does this too. After you end your first command with an _&_, follow up with another one.

rmdir /home/user/Public/ & killall chromium-browser & sudo apt-get update &

All of these tasks will run in the background. Each will activate regardless of whether the others succeed or fail.

*Are You Ready for the Terminal?*


By the time you’ve worked through all of these shortcuts, that mysterious black window with white text should start feeling familiar. You might even find yourself keeping a terminal window open somewhere on your desktop at all times.

In that case, it’s time to get acquainted with the fun stuff. If you’re feeling confident, you can advance to managing partitions? Alternative, you may want to spend more time learning the basics. Whatever you do, there are certain commands you should never run.

*What are your favorite terminal shortcuts? Are there any commands you would recommend learners commit to memory? Share your knowledge in the comments!*

----------

