Conversation started Oct 11, 2020 at 15:05.
Oct 11, 2020 15:05
The first thing to do is open a terminal which usually you can do with Ctrl+Alt+T. If that doesn't work then you can hopefully launch the Terminal application from whatever menu has apps in it on your DE. Or you can press Ctrl+Alt+F2 and log in to the virtual terminal there. To get back to the GUI you can probably press Ctrl+Alt+F1, or maybe Ctrl+Alt+F7.
ok I have my terminal up.
Opened terminal.
On Ubuntu, if you haven't changed anything, opening a terminal starts a Bash shell.
I have my modified terminal up which starts with the menubar visible in 20.04.
When you open a terminal you already see some text in it... This is the prompt. Mine says zanna@peach:~$ on this system. You can customise this and you may have already, but I'll talk about this default one.
It's a useful bit of text as it tells you the user you're logged in as (zanna), the hostname of the system (peach) and where you are in the filesystem (which is the first thing I want to talk about). The @ and : are just for easy reading (zanna at peach:location), and the $ is like end punctuation, although it does also tell you that you're not root (if you are it changes to #).
It's not at all obvious how the prompt tells you where you are in the filesystem because when you start a shell you are in your home directory and the prompt displays an abbreviation for that location, which is the tilde ~ symbol. That symbol expands to the path of the home directory of the current user. Try running:
echo ~
This command echo just outputs its input, but the shell expands ~ to the path of the home directory of the user running the command, so echo receives the input /home/username and outputs it.
Let's move somewhere and see how the prompt shows the location. Try running
cd /
@karel nice :)
Now my prompt says zanna@peach:/$ - the tilde ~ has been replaced with a forward slash /. This character is the directory separator. Like, in the home directory we were in, the full path was /home/username i.e. the directory username (zanna in my case) inside the directory home. But what directory is home inside?
Oct 11, 2020 15:09
~ changed to / for me
@jokerdino me too
@Zanna is home inside /?
Yes, exactly... home is in what I think of as the topmost directory, picturing the filesystem top to bottom, with subdirectories under the directories they are in.

Sometimes this is called the root of the filesystem (which pictures the filesystem bottom to top, I guess). From here run
ls
Are you seeing things with different colours? I hope so. If not, let me know and we'll fix it. So here you can see all the top level directories including /home which we were just in a subdirectory of a minute ago.
@Zanna I can see things with different colours
yes same for me
Oct 11, 2020 15:13
@technastic_tc great... we have a nice question about the meaning of ls colours
400
Q: What do the different colors mean in ls?

RafidWhat do the different colours in Ubuntu's ls command mean? For example, when I type the ls command in one of my folders, I get one of the files in light green, the other (which is a folder) in blue with green highlighting. What do those colours mean, and there is any manual about all the colours?

oops but better read it later
You will also see directories like usr bin sbin which contain executable programs, including the bash program itself. bin and sbin are symlinks on my system, meaning attempts to access them redirect to other locations. (I'm hoping to cover symlinks in part 2 of this lesson, some other day!).
If you ls boot you can see the versions of the Linux kernel you have installed. The directories proc and sys give you a peek into the kernel itself.
The directory /etc contains configuration files. You may find yourself changing files in there from time to time. Let's go in and take a look around this place.
cd etc
Check your prompt. Mine says zanna@peach:/etc$ By the way, there's a command to print the path of current directory; it's pwd (print working directory). This always prints the full path.
If you run ls here you can see a whole bunch of stuff. Let's try moving into a couple of these directories. For example, the directory apt
cd apt
Here you can ls and see the software sources files. /etc/apt/sources.list configures the repositories that APT downloads software from. Shall we read it? You can print the contents of a file by using the command cat, like, from here you can run cat sources.list. Try that...
yes, lots of stuff are there
The output is pretty long for me. It went off the top of the terminal even in fullscreen view. I can scroll up, but that's a little bit awkward. So it's more convenient to read files using a pager. The less program is such a thing, so let's try again to read that file, but this time with
less sources.list
for me it has only 3 lines
@αғsнιη I have seen versions like that, where people make a short tidy version. Anyway you can still open it with less
less because you can see more of it by going up and down
Oct 11, 2020 15:19
if you have lots of stuff, now you notice that you are at the top of the file and you can easily scroll around
but less has lots of other useful features
press h to see a summary of them
You can see in here that pressing the spacebar scrolls forward one whole window (the height of the terminal or screen), and pressing b scrolls backward one window. Press return to scroll down here in the help, and you'll see some tips for searching. As you can see, typing /stuff will search forward for stuff and ?things will search backward for things. Pressing n skips to the next occurrence of the pattern you searched for, and pressing N skips back to the previous one.
@Zanna the summary itself is long.. lol
@technastic_tc ikr
even the summary doesn't fit in my full screen terminal hahaha
@Zanna I did 'less sources.list' but when I press Enter, I cannot get back to my prompt. How to exit from 'less' view?
press q to exit less
also, press q to exit from the help inside less, then q again to exit all the way
is anyone still trapped in less?
Oct 11, 2020 15:22
I am out of it
We can practice using less features by taking a look at its manual... Run the command man less
there are a lot of puns you can make with man page titles...
We are now looking at a "man" page. Note that it displays in a pager; in fact man uses less (askubuntu.com/questions/623992/…). That's why I said we can practise using less by reading the manual!
These reference pages provide information on how to use commands, as well as other useful stuff. For simple programs, the man page plus a bit of practice might be all you need to learn how to use the command. But the man page for less is really long. I should really read all this some time...
Try scrolling forward and back by pressing the spacebar and the b key. Also try typing /pattern or (after scrolling down a bit) ?pattern and then pressing n or N to scroll through the results (there are lots of occurrences of the word "pattern" in this man page, but you can also search for anything else you're interested in).
nice, didnt even know you can search a man page
I didn't know about n and N - Eliah Kagan told me about it the other day
let's press q to quit and continue our little tour
We are in /etc/apt as the prompt tells us. Now let's move over to /etc/default. There is more than one way to do that. We could just type in the full path of the directory we want to go to (did I mention that cd is an acronym for change directory?) like this
cd /etc/default
This path is called an "absolute" path because it works anywhere in the filesystem. It is unambiguous and can only mean one particular location.

You can always go back to the most recent location with a neat shortcut
cd -
2
@Zanna mind = blown
will take you back to /etc/apt (assuming you ran the command cd /etc/default) Is anyone lost? Please tell me...
@jokerdino haha <3
Another way we could go from here to /etc/default is to go up out of this directory into /etc and then down into /etc/default in two steps:
Oct 11, 2020 15:27
@Zanna not lost.
I am somewhere near lost+found
2
cd ..
cd default
@jokerdino sounds like the right place :D
Both of the paths we specified here are "relative" paths, meaning that the location they refer to is relative to the current location. .. means the parent directory of the current directory (there's a similar relative path to the current directory, .) and default means the directory default in the current working directory.
those double and single dots are a bit hard to read in chat, even monospaced, but I think y'all know about them anyway
There's one more way. cd - again and we'll try it. We can go up and down again in a single step, like this:
cd ../default
is that a relative path, or an absolute path?
seems like relative
@Zanna bash: cd: ../default: No such file or directory
@technastic_tc probably you didn't enter the previous command because it was very hard to read in the chat
just run cd /etc/apt and then try again
By the way, I should have said, you can press the up arrow to get your previous command in the terminal - most useful thing of all!
Oct 11, 2020 15:32
I think the issue is that if you're in /etc/apt and you run cd .., then you're in /etc, and then if you run cd default and then cd -, then you're back in /etc, not /etc/apt. Running cd ../default in /etc gives that error.
oh right, yes, thank you, totally my bad
@jokerdino yes correct, it means the directory default in the parent directory of the current directory.
looks good
This directory has my favourite file, /etc/default/grub. I wrote about it in my "Ubuntu story"
let's go back up to the top one more time and then we'll head home
you can cd ../..
@Zanna I don't see /etc/default/grub file
by the way I'm on WSL
@αғsнιη type ls and check
Oct 11, 2020 15:36
@αғsнιη ohh
no grub for WSL
@αғsнιη maybe you don't have that file on WSL... does WSL have GRUB?
It doesn't need a boot loader, so it doesn't come with GRUB.
I only see a directory called 'grub.d' and contains only this file '50-cloudimg-settings.cfg'
I wonder what that is for :)
anyway no worries
@jokerdino Ohh, well
Oct 11, 2020 15:37
ok we are back to ../..
After you got back to /, run ls here again and you should see a directory called root which makes the name 'root' for the directory / slightly confusing. This is actually the home directory of the user root. Let's take a look at the contents of that directory
ls root
I dont have the permission
ls: cannot open directory 'root': Permission denied
yes
me too
Oct 11, 2020 15:39
Try running ls -dl root to see why. The -d option causes ls to list directories themselves instead of their contents, and the -l option shows extra information including permissions.
root root and root
zanna@peach:/$ ls -dl root
drwx------ 6 root root 4096 Oct 10 20:15 root
drwx------ 9 root root 4096 Sep 21 20:31 root
This directory doesn't have read permission for anyone except the owner (the leading d means this is a directory, then the next three letters r(ead) w(rite) (e)x(ecute) are the permissions for the owner, then the remaining dashes indicate the lack of permissions for group and others (we are others here!) and the owner, also listed, is root) so we can't ls the contents.
Try again with sudo ls root
With sudo I don't get any error, but I also don't get any output.
it's just empty for me in WSL
Oct 11, 2020 15:41
By default there will be some files there, but, their names start with ., which causes them to be hidden. You can use the -a switch to see them. Try sudo ls -a root
It has the same as / without colors.
sorry
I have three .dot files
Ran the wrong command
you noticed that there are no colors though - that is a great observation
Oct 11, 2020 15:42
.   .bashrc  .config  .hplip  .mysql_history  snap
..  .cache   .dbus    .local  .profile	      .synaptic
I guess that is because the colors in ls appear because you have the alias ls='ls --color-auto' but when you run sudo ls you don't get that alias
I see two items like single dot (.) and double dot dot (..); what are these files/directories?
sudo ls -a --color=auto root
yes, the colour is back
@αғsнιη one dot is the current directory, and two dots is the parent directory
that means there are no files in the directory
@technastic_tc I get something like that. The user root has all this home directory stuff. Let's compare it to our own home by heading back there. You can always go straight to your home directory by typing just cd
Are you back? See how the / in your prompt changed back to ~? Try running ls -a here. You will probably see some of the same files and directories as in root's home, like .bashrc .cache and .config. You will also probably see directories you might be familiar with from the graphical file browser your system uses (if it uses one), like Documents, Downloads, Pictures, etc.
All these folders and files normally belong to your user and you can freely access and modify them, unlike the files in root's home which we had to use sudo just to see.
Oct 11, 2020 15:45
@Zanna hmm, I see, so that's why at above we were doing 'cd ..' to get back to parent directory, right?
@αғsнιη exactly! :)
thanks for clarifying that
Most of the system directories up there outside our home are owned by root, and while for the most part we can read them, we can't modify or delete them without using sudo. That means those files are relatively safe from our typing mistakes and ill-advised commands!
But down here in our home directory we have to be careful (the files here are probably the ones you can't replace - you can reinstall Ubuntu in 30 minutes if you somehow irreparably break it, but you can't reinstall your personal collection of cat photos - so make backups!).
Let's create a directory to play around in to keep the top level of our home directory clean. Maybe you already know the command to create a directory?
is it mkdir?
yes :)
You can call the directory whatever you want. I'm going to call my new directory playroom
cd
mkdir playroom
You can make a name that has spaces, but you have to put quotes around the name you want to use in that case. mkdir takes multiple arguments so if you write, for example mkdir my new directory, three new directories are created with the names my, new and directory. To make just one directory you would put mkdir 'my new directory' (you can also use double quotes " instead of single quotes ', or you can put a backslash before each space like my\ new\ directory).
Various other characters may also cause unexpected things to happen, but I don't want to go through all of them at this point, so just let me know if you get an error.
One of the things that can happen with quoting is that you put one quote and press enter before you type the next quote:
zanna@peach:~$ mkdir 'my
>
yes that happens to me quite a bit
then you get this secondary prompt and it seems like whatever you type you can't get out of it.

Actually the shell is waiting for the closing quote, but unless you actually wanted to enter something spanning multiple lines (you can put newlines in filenames, for example, which is probably not a great idea in general but can be useful for testing scripts) the best thing to do in that situation is usually to press Ctrl+C which will abort the command and allow you to escape back to your normal prompt.
Ctrl+C also works to quit many programs in the terminal so it's very useful. Sometimes you start a command running and realise it's not what you intended to type or it's going on forever, so Ctrl+C can help you out.
@jokerdino me too
Now you have made your directory, let's cd into it. I'll run
cd playroom
I am doing too many things at once here hahaha
Oct 11, 2020 15:51
How so?
There's no TV in here.
copying from one window, typing commands in another window, pasting and typing and reading in another window
Now my prompt says zanna@peach:~/playroom$
Does your prompt show the name of the new directory you created? If so, everything is good. You can run the command pwd to double check your location. Any issues?
@Zanna no issues
Oct 11, 2020 15:53
All good
I am in my playground
:)
We can try playing around with some features of the shell and doing things with files. We'll look at some shell expansions. Probably the most useful expansion is parameter expansion or variable expansion. You can assign a shell variable for the current session by writing something like
foo=bar
There is no output, but we can see the value of our variable foo by asking the shell to
echo $foo
You can't put spaces around = when you are assigning to a variable in Bash. You also need to use quoting (usually you will just want to put single quotes around it) if the value you want to assign to the variable has any spaces (or various other characters that might cause strange things to happen) in it:
zanna@peach:~/playroom$ foo=bar ram ewe

Command 'ram' not found, but there are 15 similar ones.

zanna@peach:~/playroom$ foo='bar ram ewe'
zanna@peach:~/playroom$ echo $foo
bar ram ewe
Only this shell knows about that variable. If you run a script (scripts run in a new shell that is a child process of the shell that calls them), or open a new shell inside this one (you can do that by typing bash), that shell won't have a value for foo. Also if you open a new terminal, which starts a new shell, it won't know about foo. But there are some variables that any shell you open will know about. For example, you can try these
echo $USER
echo $HOME
echo $PATH
I'm curious about your PATH on WSL...
can I run all these in same go?
Oct 11, 2020 15:56
yes definitely
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/ProgramData/Oracle/Java/javapath:/mnt/c/Program Files (x86)/Intel/iCLS Client/:/mnt/c/Program Files/Intel/iCLS Client/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/Program Files (x86)/Intel/OpenCL SDK/2.0/bin/x86:/mnt/c/Program Files (x86)/Intel/OpenCL SDK/2.0/bin/x64:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Prog
O.O
it's huge
Anyway, those are all environment variables. The shell you are running inherited them from the program that started it. And, any programs the shell starts (child processes of the shell) will also inherit them. A script you run from here will conveniently know, for example, the value of PATH, which is the list of directories where the shell will search for commands.
For example, the sudo program, which we used earlier, is a file in the directory /usr/bin. When you run sudo, Bash looks in /usr/bin (among other places) to find a file with that name to execute.
@jokerdino seems whatever you type in the terminal it's bound to exist somewhere and get executed XD
I hope so
oh no, it's almost end of session
Is it okay to run longer?
We didn't start on time though
Oct 11, 2020 15:59
@user3140225 true
@EliahKagan It is definitely alright
but I already learned too much and brain is overflowing
Brain overflow is off topic here. We only answer questions about Ubuntu.
3
@terdon lol
@jokerdino hugs
Oct 11, 2020 16:01
we can do another 15 minutes and keep the remaining for the next day/weekend?
yes, there is loads more. Let's go on for a bit and find a good place to stop, and schedule another class for the rest?
@Zanna ok..
I'm OK
Me too
same here
Oct 11, 2020 16:02
OK
:)
You can pass variables into the environment with the export command.
For example, you can export foo. This causes all child processes of the shell where you run export to know about that variable. You can change the value later and the change will also be passed to child processes (so you only need to export a variable once).
liah Kagan gave me a nice example for this. The handy GNU date command will look for the TZ variable, and use it if it is set, which it probably is not on your system yet. Try running it
date
zanna@peach:~/playroom$ date
Sunday 11 October 2020 09:34:15 PM IST
what's a TZ?
@Zanna Sun Oct 11 19:34:36 +0330 2020
some kind of animal? or could it be a time zone? or maybe a variable that we haven't set yet
Sun Oct 11 12:04:23 EDT 2020
Oct 11, 2020 16:05
Sun 11 Oct 19:04:24 EEST 2020
Now try running it like this
TZ=UTC date
Sun 11 Oct 16:05:48 UTC 2020
This syntax is very useful - you can run one command with variable=value by prepending it with variable=value like that.
Sunday 11 October 2020 04:05:44 PM UTC
Sun Oct 11 16:06:00 UTC 2020
Oct 11, 2020 16:06
@Zanna Sun Oct 11 16:06:04 UTC 2020
now run date again
Sun Oct 11 16:05:48 UTC 2020
@Zanna Back to:
Sun Oct 11 12:06:23 EDT 2020
Back to the previous
Now try this:
TZ=UTC
date
Oct 11, 2020 16:07
no changes
yes, same again
Sun Oct 11 19:37:13 +0330 2020
it is what it is
you have set TZ for the shell - you can echo $TZ, but `date doesn't know about it
so now run export TZ
Oct 11, 2020 16:08
zanna@peach:~/playroom$ export TZ
zanna@peach:~/playroom$ date
Sunday 11 October 2020 04:08:23 PM UTC
Magic!
:)
(great example BTW)
credit to @EliahKagan
now change it again:
we are all in same time zone now
Oct 11, 2020 16:09
TZ=Asia/Hong_Kong
and again run date
@jokerdino :)
@Zanna Thanks @EliahKagan
Thanks EK
It changed
That's very kind, but I only contributed the idea to demonstrate environment variables by running date with TZ set, not the specific progression of commands and explanation -- which is actually better than the way I have shown people, and I shall be linking to it here, I think, to help people in the future.
Mon 12 Oct 00:10:22 HKT 2020
Oct 11, 2020 16:11
@user3140225 I should be sleeping then..
Can we try something like TZ=Asia/Kolkata?
@user3140225 yes :) that demonstrates that you don't have to export again after changing the value - the date command got the update. This is always the case when you change an environment variable - you don't have to export a variable that is already in the environment, you can just assign a new value to it (although nothing bad happens when you unnecessarily export a variable that is already exported).
@technastic_tc sure, but I guess that's what you had at the start?
I mean, at the start you had IST
But how can we go back to the default?
yes I want to go home
I am stuck in HK now
@Zanna yeah.. let's say we don't know what the TZ variable is equal to. How do we find it?
Oct 11, 2020 16:13
hahaha well you can close the terminal and open a new one
or you can run unset TZ
Bash also has export -n
@technastic_tc we are totally coming to that!
@jokerdino Wouldn't be bad
@EliahKagan what does it do?
Oct 11, 2020 16:13
If you want to keep the shell variable set but unexport it.
@EliahKagan neat!
You can also run export variable=value, combining the two steps of assigning a value to a variable and passing it into the environment into one step. So instead of doing TZ=UTC and then later export TZ, We could have just run export TZ=UTC
Note that if you open a new terminal, the shell that opens won't be a child of the shell you exported from, so it will not know about that variable. To set an environment variable that all shells will know about, you could export it in .profile.
There is a command that lists only environment variables - it is printenv
try running it without any arguments
whole lot of stuff
a lot of stuff
I've just noticed that the value of my LS_COLORS environment variable is quite long. :)
If you want to know the value of a particular environment variable, or know whether it is set, you can run, for example, printenv TZ (@technastic_tc)
@EliahKagan same here - more than 11 lines on the full screen
same for a bunch of them, like printenv USER HOME PATH
@Zanna I got no ouput..
Oct 11, 2020 16:17
yeah same
@technastic_tc did you unset TZ earlier?
@Zanna nope.. May be that's why..
If TZ is set and exported, printenv TZ should print its value.
@technastic_tc oh haha I was expecting you to say yes
I reopened a new terminal, oops
Oct 11, 2020 16:18
@jokerdino that explains it :)
I don't have TZ set by default
date gets its information from somewhere else if TZ isn't set, not sure where but maybe /etc/timezone
@technastic_tc did you open a new terminal?
how do I find out what kind of time zones are available for me to set?
@Zanna no.. I didn't change the TZ values..
@jokerdino that's a damn good question. I found out on Wikipedia but maybe there is something in the system
@technastic_tc ok, anyway it will most likely just be unset by default for you, like it is for me
@jokerdino Look in: /usr/share/zoneinfo
@jokerdino locale -a will list the ones you have generated on your system, the ones that can be used now.
Ah sorry. That's locales in general not timezones.
Oct 11, 2020 16:22
@jokerdino Or here
good stuff, thanks all
Sorry for not allowing enough time
@technastic_tc Is echo $TZ printing anything?
@EliahKagan UTC
But printenv TZ does not print anything?
Oct 11, 2020 16:24
@EliahKagan yeah
Then it seems to be set as a shell variable but not exported as an environment variable.
yes, needs to be exported I think
When you run date by itself, is the output affected by the value of TZ?
Like, is it in UTC?
Sunday 11 October 2020 09:55:07 PM IST
I suppose we can wrap it up for the day with the session.
Oct 11, 2020 16:25
Yeah, it's set but not exported.
@jokerdino Ok.. Bye!
We can continue another day with the lesson, if folks are interested
@technastic_tc export TZ=UTC
Or just export TZ since it's set.
@Zanna Sure.
@Zanna Of course!
Oct 11, 2020 16:28
great stuff so far
:) any suggestions for a day? We could continue same time next week
 
Conversation ended Oct 11, 2020 at 16:28.