« first day (14 days earlier)      last day (36 days later) » 
14:00 - 16:0016:00 - 21:00

2:57 PM
Welcome everyone to day 2 of Ask Ubuntu 10th year anniversary celebrations classes.
Hopefully we will have another session of awesome stuff.
We have @Zanna with the introduction to commandline for beginners starting pretty soon.
Let's say aye so we can take attendance. :P
 
looks like the people who are currently in the room are all experts
 
aye
 
aye
just you and me then ;)
 
@Zanna nah..
 
@technastic_tc haha great :)
 
3:00 PM
Well, I'm in no way an expert
 
@jokerdino aye
 
aye
 
well I'm a beginner and I learned some stuff from preparing it so maybe it will be useful to others
 
let's wait for another 3-5 minutes for people to drop by, if it's ok
 
good idea
 
3:02 PM
hi and welcome to our classroom @mercury0114
 
aye
 
Why does the word 'aye' remind me of the UK parliament voting?
 
before starting I have to thank @EliahKagan for generously reading several versions of my blathering preparation and offering many important corrections and suggestions!
 
thank you @EliahKagan
 
thank you for the introduction and extensive moral support @jokerdino
 
3:04 PM
@Zanna No problem. :)
 
@Zanna cool..
 
Though I didn't notice much blathering. Unless you added some since the last version I read... :)
 
hahaha
 
aye
 
OK let's start!
 
3:04 PM
Ok whenever you are ready @Zanna. The stage is yours.
 
did I mention I suffer from performance anxiety?
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.
 
3:07 PM
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?
 
~ 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
 
3:13 PM
yes same for me
 
@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
 
3:19 PM
less because you can see more of it by going up and down
 
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?
 
3:22 PM
good
 
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
 
3:27 PM
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:
 
@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
 
3:31 PM
@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!
 
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
 
3:35 PM
@αғsнιη type ls and check
 
@αғ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
 
3:37 PM
@jokerdino Ohh, well
 
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
 
3:39 PM
me too
 
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.
 
3:40 PM
it's just empty for me in WSL
 
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
 
3:42 PM
you noticed that there are no colors though - that is a great observation
 
.   .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
 
3:44 PM
@αғ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.
 
@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
 
3:50 PM
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
 
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
 
Ah.
 
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?
 
3:53 PM
@Zanna no issues
 
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
 
yes
 
I'm curious about your PATH on WSL...
 
3:56 PM
can I run all these in same go?
 
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?
 
3:59 PM
We didn't start on time though
 
@user3140225 true
 
@EliahKagan It is definitely alright
but I already learned too much and brain is overflowing
 
14:00 - 16:0016:00 - 21:00

« first day (14 days earlier)      last day (36 days later) »