7 Linux terminal basics every beginner should learn first – and why

Jack Wallen / Elyse Betters Picaro / ZDNET

Follow ZDNET: Add us as a preferred source on Google.


ZDNET’s key takeaways

  • The Linux terminal isn’t nearly as hard as you think.
  • Understanding the fundamentals will help get you started.
  • These concepts apply to all Linux distributions.

When many think about Linux, they think of awkward and complicated commands that are far beyond the reach of new users. What those people may not know is that modern Linux distributions don’t require that they work with the command line.

But to get to the real power of Linux, the command line is something people should at least understand, because eventually, it might be needed.

Also: There’s a new coolest Linux distribution ready to wow you

To start your journey with the Linux command line, it’s important to know a few things before diving in. These aspects of the terminal are fundamental to getting the most out of the tool.

Shall we begin our journey?

1. Terminal/shell/prompt/CLI – what’s the difference?

The terminal is actually an app, such as GNOME Terminal, KDE Plasma’s Konsole, iTerm2, and many others.

But what is the shell? Simply put, the shell is a command-line interpreter that acts as an intermediary between the user and the Linux kernel.

Also: Linux desktop frozen? My 5 go-to tricks to try – before forcing a hard reboot

The prompt is where you type your commands, and is generally displayed like this:

username@hostname:

CLI stands for Command Line Interface and is a bit of a mystery to most because it’s hard to define. Typically, the CLI is where you run commands. I like to think about it as the above three components (terminal, shell, and prompt) working together.

2. History

Did you know that the shell maintains a history of the commands you run? Even better, you have access to that history. If you type history at the prompt and hit Enter, you will see the last 100 commands you’ve run. Here’s a cool trick. When you view your history, each command has an associated number. If you see the command you want to run, you can recall it by typing the ! character immediately followed by the number of the command you want to run. 

Also: Here’s how I finally cracked a tricky Linux problem with this AI terminal app

Let’s say you want to run command number 10 (as shown in your history). To run it from the history, simply type:

!10

3. Tab completion

Another handy feature is tab completion. 

Also: Want to learn Linux? These 5 games make it fun – and they’re free

The Linux shell knows its commands and can help you out. Say, for example, you don’t remember the command you used recently, but you know it starts with ca. Type ca and hit Enter, and you’ll be presented with all of the commands that begin with those two letters. I’ve used this quite a bit over the years because sometimes I just can’t remember the name of a command.

4. $PATH

The Linux $PATH is a bit complicated to explain, but here goes. If you’ve ever run a command in Windows, you know you have to type out the explicit path for whatever it is you want to run. Let’s say you want to run the command zdnet (which isn’t really a Windows command). You can’t just type zdnet and hit Enter, because Windows won’t know what to do. 

Also: New to Linux? 5 desktop environments I recommend you try first – and why

On Linux, however, commands are typically global, so if you run zdnet, as long as the command is in a directory associated with your $PATH, it’ll run. So, the Linux $PATH includes directories that house commands that can be run globally. If you type $PATH, the output will include directories like /usr/bin/, /usr/local/bin, /usr/sbin, and so on. You can temporarily add a directory to your path with a command like export PATH=”/Directory1:$PATH”. If you want to make that permanent, you edit the ~/.profile file.

5. What are the dots for?

Let’s say you have a shell script you created and you want to run it. Say you created the ~/scripts folder and have all of your scripts housed in there. If you are in that directory, you could run a script like ./script.sh. That leading . tells the shell that whatever you are doing is in the current working directory. Two dots, on the other hand, refer to the parent directory. If we’re talking about /home/jack/scripts, then using a single dot refers to /home/jack/scripts, and a double dot refers to /home/jack.

6. Case sensitivity

The Linux terminal is case sensitive. In other words, if you have the command zdnet, you have to type it in all lowercase. If the command is ZDNET, you have to type it in uppercase. If the command is zDnEt, you have to type it exactly as it appears.

7. What happened to copy/paste?

Have you tried to paste something into the Linux terminal with the tried-and-true Ctrl+v keyboard shortcut? If so, you found out it doesn’t work. But why? I’ll avoid the history lesson here, but Ctrl+c is a keyboard shortcut to kill a command. 

Because of that, Ctrl+c and Ctrl+v do not work as expected. Instead, use Ctrl+Shift+c and Ctrl+Shift+v.

You’ll get used to it.

Also: 5 surprisingly productive things you can do with the Linux terminal

Now that you understand these fundamental concepts, you’re ready to start your journey with the Linux terminal.

I mean, shell.

I mean, prompt.

I mean, CLI.



Original Source: zdnet

Leave a Reply

Your email address will not be published. Required fields are marked *