Blog → Post


(TIP) It's a CLI World
Command line tricks for users
by @admin, july 20, 2020, 02:47pm utc

For better or worse, if using Linux, you are likely to spend some time using the CLI (command line interface). However, once you start to do so, you might actually like it -- because the tools there are so powerful.

This post will be a collection spot for some simple, getting started, CLI tricks.

We'll try and organize these in a simplest to more advanced order.

Tip: Four ways to get to the command line:

1. Click the menu icon, Administration, then Terminal,
2. or press Ctrl+Alt+T,
3. or press Alt-F2 and type "Terminal",
4. or press the menu icon and type "Terminal" then enter.

getting to the command line
Clicking to the Terminal

First, off: Returning to home

While in the CLI prompt, you will be situated in a folder (aka a directory). From there, you manuever around to other folders using the cd (change directory) command.

By default, when you open the terminal to get the command prompt, you will be placed into your home folder/directory. So, it will be something like fred@WORK5:~$ (but instead it will show [your user name]@[your machine name]:~$ ).

What all of that just means is that you are placed in your home folder when you open the terminal, and your username is fred. As in:

/home/fred

The little tilde (~) character? That means "home" and is a shortcut for your home folder. When you see it in the prompt that signifies that you are in the home folder.

So, if you wanted to move to your documents folder, which is here (/home/fred/Documents) you would type $ cd Documents



Advanced folks! Just three more basics, please.
(We're also setting up the folder names to be discussed as well)
.


Lets assume that you are in this folder:

/home/fred/Downloads/work to be done/spreadsheets for 2020

There are two 'operators' for relative paths. '.' and '..'.

Here is how those work.

Tip: If at any time you become uncomfortable with cd and the folders; just type $ nemo . .

This will jump you right out into the GUI file manager. You can also press the "Window" key at any time, to pop-up the GUI menu, and to be able to escape that way.

Of course, typing $ exit to leave the terminal will work as well.

$ cd ../ moves you Up a folder.

In relative terms, this is to the 'parent' of where you started.
('.' is the folder that you started from).

So, BOTH of the following commands will move you up to the folder
/home/fred/Downloads/work to be done/

cd "/home/fred/Downloads/work to be done/"
and
cd ../


For the first one, you have to enclose the string in " " otherwise Linux (as well as Windows) does not know how to handle the spaces in the name.

We'll show you a trick for dealing with the spaces in a bit.


pwd

By default, you are shown the bottom-most folder in your path on the prompt.

So if you are in /home/fred/Downloads, your prompt will show fred@WORK:Downloads$

Something that we'll address in another blog post is how to configure the prompt the way that you like, including colors and how to show more, or less, path information.

But anyway, the pwd (print working directory) command shows you the full path to where you are at.

$ pwd returns /home/fred/Downloads


cd ~ and cd -

These are two special parameters to cd.

The first returns you to your home directory from wherever you are. Just cd ~ and you're home.

The second takes you to the folder that you were last at.

So, if you were in /home/fred/Downloads/work to be done/spreadsheets for 2020

and typed either

cd ../../ or cd /home/fred/Downloads

to get in to /home/fred/Downloads ...

...then cd - will pop you right back into
/home/fred/Downloads/work to be done/spreadsheets for 2020


Note: You will remember that '~' means the home folder.
"~" can also be used relatively.

So cd ~/Downloads will also put you into
/home/fred/Downloads



Secondly: Cutting down typing

Obviously, typing out

$ cd /home/fred/Downloads/work to be done/spreadsheets for 2020

is cumbersome.

But you can use the '*' wildcard character to ease the work.

So... cd "/home/fred/Downloads/work to be done/s*"

also gets you to:
/home/fred/Downloads/work to be done/spreadsheets for 2020


cd "/home/fred/Downloads/w/s" will also get you there.

So will cd "/home/fred/D/w/s*"

as will cd ~/D/w/s*

This is tremendously useful if you know right where you want to be.


One slight caution: If for example, there are two 'D' files in the Downloads folder you'll get a "bash: cd: too many arguments" error; because it does not know which of the D items to pick.

But, that's ok, just add another character or two until you have a unique name, and press enter again, to go right to where you want.

tags: Advanced users, Tips
Footer done in Inkscape