« first day (28 days earlier)      last day (22 days later) » 

14:30
Hi all!
Hello!
thanks for coming back :)
hello
14:30
Hello : )
welcome everyone for showing up on time
i mean, thanks
@jokerdino :-D
hahaha
14:31
hello
Let's cd into our directory again
I'll do cd playroom
tomato
if you need to, you can create the directory first, like mkdir playroom && cd playroom
@jokerdino yes, there it is
I hope y'all have some stuff in there
yes i do
if not, for the next bit to make sense, just run mkdir {01..04} or something like that
Last week we were talking about brace expansion (like {01..04})
today we're going to start with another expansion which is super useful
filename expansion or "globbing". Even if this is the first time you ever used a shell program, you might have met globbing in other contexts, like in search engines.
Bash uses a few characters as "wildcards" that can match multiple characters.
I will talk more about globbing later when we have more files to play with, but for now we can try this:
echo *
14:34
yep, it shows all the stuff in my directory
* expanded to match all the files we have (directories are also files).
it matches any number of any characters at all, so basically everything
sounds that acts same as ls but color-less
Except those starting with .
:-)
although by default it excludes paths starting with . (hidden files), yes
@αғsнιη yes, indeed
Double quotes suppress various shell expansions including globbing, tilde expansion and brace expansion. But they don't suppress parameter expansion (which we also talked about some time ago)
try these:
echo "*"

echo "~"

echo {55..59}

echo "{55..59}"

echo "$USER"
@αғsнιη True!
14:38
To suppress all expansions, we can use single quotes:
echo '$USER'
aha
yes, it prevented most expansions except the env variable?
but the single quote blocked that as well
yes, double quotes don't prevent parameter/variable expansion, but single quotes do
Some expansions, globbing (which we just mentioned) and word splitting, are performed on the result of parameter expansion. "Word splitting" refers to the text being split into fields ("words") by whitespace characters. Double quotes prevent this, so it is very advisable to quote one's variables, especially if their values are unpredictable, since these further expansions generally produce something unexpected.
I'll try to demonstrate... try
echo '*'
what did you get?
@αғsнιη Same..
right... so try
x='*'
echo $x
14:42
01 02 03 04 kernel name tomato
@BeastOfCaerbannog Same
so, parameter expansion was performed - x got expanded to *, but then after that globbing was performed
now do
echo "$x"
@BeastOfCaerbannog same
@jokerdino same
14:44
no globbing after x is expanded to * - we get literal *
now
can I use this to multiply stuff?
echo '$x'
@jokerdino probably yes... do you mean the * character?
@jokerdino you can use it for that in arithmetic context like this echo $((5*8))
in arithmetic context (inside (( ))) it is a multiplication operator :) nice question!
inside double parentheses hahaha
14:47
nice
@technastic_tc right, yes, we got $x, meaning there was no variable expansion (no expansions at all) because of the double quotes
Now I'll try to show you word splitting
d='new directory'
mkdir $d
ls -1
ls -1 prints one filename per line
@Zanna Do you mean because of the single quotes?
@EliahKagan oops yes! sorry
sorry @technastic_tc
that was a very confusing mistake
@Zanna It's ok!
@Zanna Now I have a new directory! And a directory directory! :)
14:49
@Zanna this created two new directories
@EliahKagan haha me too
Yeah two dirs
01
02
03
04
directory
kernel
name
new
tomato
I mean, I got one new and one directory directories
Wordsplitting happened on the result of expanding d, so mkdir received two separate arguments new and directory
you can do
mkdir "$d"
ls -1
14:50
I see
I got a new directory
no wordsplitting - we got a directory with a space in its name. Since idk when (but definitely some time after I got used to the old behaviour), ls prints files that have special characters with quotes around them, even though the quotes are not in the filenames. Personally I find this confusing, but at I guess it makes it easier to see which files have special characters and their full names.
@jokerdino hahaha I should have picked a better name
you can even do
mkdir '$d'
ls -1
01
02
03
04
directory
kernel
name
new
'new directory'
tomato
@technastic_tc nice - it worked
I have a '$d' directory now
yeah... the quotes added by ls are really confusing there - but at least you can see there was no parameter expansion
14:52
'$d'
01
02
03
04
directory
kernel
name
new
'new directory'
tomato
@technastic_tc good job!
@Zanna :)
what I'm trying to demonstrate is why you should quote your variables (with double quotes) as otherwise you will probably end up with something you didn't really want, like a new directory and a directory directory instead of a new directory...
ok double quotes it is
Let's clean up these empty directories. We can do that with the rmdir command, which only deletes empty directories so is pretty safe to use (but type it carefully!) We can use a glob here to remove all the empty directories:
rmdir *
14:54
@Zanna disable that "ls --quoting-style=literal -1"
or ls -N1
@Zanna neat
@αғsнιη oh thanks! That would have been useful for this. Yes I think -N does it
Yes. The -1 is just a separate option (same as before).
rmdir *
rmdir: failed to remove 'kernel': Not a directory
rmdir: failed to remove 'name': Not a directory
yeah... If there are any non-directories, or non-empty directories, we get some nice informative errors about them, but that's ok; the empty directories still got removed.
Let's go back to working with files a bit
I want to give my file tomato a more descriptive name. I can rename it without changing the contents using the mv command. mv is short for move. If the name of a file is an address, a location in the filesystem, then renaming a file is moving it, right?
Before we do anything with mv, it might be smart to take a glance at its man page
man mv
So we can see the syntax of the command is mv source destination, and we have a -v option for verbose mode, which I like to use
press q to get out of the man page
I'll try this
mv -v tomato shopping list
14:58
@Zanna thanks
@jokerdino :D
list is not a directory :/
Yes, I get an error that list is not a directory. That is because, given a list of more than two arguments, mv will take the last one to be the destination for all the others, and it would obviously be bad if we renamed two files to have the same name, because then one of them would be overwritten (we would end up with only one file).
So mv will not do that - it will only move more than one file if the destination is a directory.
I see
how can we rename the file to shopping list?
15:00
can we use single-quote here?
welcome @user.dz!
@αғsнιη yes!
I used double quotes
we can also use double quotes
or we can just escape the space
with a backslash
all work fine
does triple quote do anything?
backlash is \
or is it /
15:01
zanna@peach:~/playroom$ mv -v tomato shopping\ list
renamed 'tomato' -> 'shopping list'
Hi everyone, Thanks @jokerdino. I won't interrupt you. coming late :)
@Zanna Should there be a space after backslash?
@jokerdino backlash is something else I think. But backslash goes from top left to bottom right, the opposite way to the directory separator
@technastic_tc yes... the backslash is quoting the character immediately after it
@jokerdino In a shell, ''' is effectively the same as ' because the second ' ends quoting started by the first ' and then the third ' reopens quoting. Likewise, """ is effectively the same as ".
15:04
good question :D
@EliahKagan thanks
We need a command to create more files. Let's see what files we have here. This time when running ls, let's add the -l (long) option to get some extra detail...
Backslash is the "escape" character
Any character after is taken "as is", and not as special character
@ArturMeinild thanks :)
@ArturMeinild what if the character was on a cameo?
15:06
@jokerdino xD
smh
here's what I have
zanna@peach:~/playroom$ ls -l
total 12
-rw-rw-r-- 1 zanna zanna 103 Oct 18 20:53  kernel
-rw-rw-r-- 1 zanna zanna  11 Oct 18 20:44  name
-rw-rw-r-- 1 zanna zanna  23 Oct 18 20:47 'shopping list'
Take note of the timestamp that comes just before the name of the file.
Now run the command touch on the file you just created:
touch shopping\ list
Did I mention tab completion? You rarely have to type full paths or filenames because after you've typed the first few characters, when you press the tab key, Bash will complete whatever you have so far typed if it matches exactly one thing, or, if it matches multiple things, pressing the tab key twice will show you the matches so you can type the next character or so to match unambiguously...
@Zanna There's no output
15:08
@Zanna what is total 12 at first line? mine is saying total 0
@αғsнιη I have a question about that!
@Zanna oh.. cool!
but I have those files same as you
@technastic_tc In general, you don't get output if anything is successful
28
Q: Why does `ls -l` count more files than me?

ZannaApparently I cannot count. I think there are three files in /media $ tree /media /media ├── foo ├── onex └── zanna 3 directories, 0 files However, ls -l finds 12. $ ls -l /media total 12 drwxr-xr-x 2 root root 4096 Jul 31 20:57 foo drwxrwxr-x 2 root root 4096 Jun 26 06:36 onex drwxr-x---+ 2...

15:09
We need more encouraging messages from bash
@jokerdino hahahha I agree
Then you need to ask for it with -v (verbose) :-D
@ArturMeinild oh.. ok
The biggest encouragement you normally get from bash is silence ;-)
@αғsнιη apparently it's the number of disk blocks being used by the directory as a whole
15:11
hmm, I see, thanks
I see *visible confusion*
so 0 means no block is used? is this OK then?
@jokerdino ikr
@αғsнιη idk why it's zero for you
it's because it's wsl
but I'm sure it's ok
15:12
@jokerdino yes, it's WSL
anyway, touching the file updated the time to right now
I see now that there is a problem with my demonstration of the touch command, which is that after running it we all got distracted so when we check the timestamp again we won't realise it got updated haha
@jokerdino phew! You saved the day
run ls -l again and look at the timestamp of shopping list
and you will note that touch updated it!
afk 15-20 minutes - back shortly :-)
@ArturMeinild cya soon :)
I don't know when that might be useful, but at least you know what happens when you run touch on a file that already exists. Now try it on a file that doesn't exist.
yes it did
15:14
touch one
ls -l
@αғsнιη I don't think it has to do with WSL. Perhaps all the files in your directory are empty. It's total disk usage (by default in 1024-byte blocks) so if all the files are empty and there are no subdirectories then it's 0.
makes sense. I wonder why this directory of mine is using so many blocks
you might have a secret hidden file somewhere
:)
when we run touch on a file that doesn't exist, it creates a new empty file with that name
have you got a file one?
I touched a potato
15:16
@EliahKagan still shows 0; maybe we can check after class finished?
@jokerdino nice haha
It also takes multiple arguments, so we can create as many files as we like
@Zanna yes
touch two three four
mkdir alphabet numbers
touch alphabet/{a..z} numbers/{1..100}
@αғsнιη Okay.
(Sorry for the distraction.)
no worries! :)
ls also takes multiple directory arguments
zanna@peach:~/playroom$ ls alphabet numbers
alphabet:
a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z

numbers:
1    12  16  2   23  27  30  34  38  41  45  49  52  56  6   63  67  70  74  78  81  85  89  92  96
10   13  17  20  24  28  31  35  39  42  46  5   53  57  60  64  68  71  75  79  82  86  9   93  97
100  14  18  21  25  29  32  36  4   43  47  50  54  58  61  65  69  72  76  8   83  87  90  94  98
11   15  19  22  26  3   33  37  40  44  48  51  55  59  62  66  7   73  77  80  84  88  91  95  99
15:18
why is it not sorted properly?
It looks like perfectly good lexicographic order to me. :)
@jokerdino good question!
You can use -v.
ek@Kip:~/playroom$ ls -v alphabet numbers
alphabet:
a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z

numbers:
1  5  9   13  17  21  25  29  33  37  41  45  49  53  57  61  65  69  73  77  81  85  89  93  97
2  6  10  14  18  22  26  30  34  38  42  46  50  54  58  62  66  70  74  78  82  86  90  94  98
3  7  11  15  19  23  27  31  35  39  43  47  51  55  59  63  67  71  75  79  83  87  91  95  99
4  8  12  16  20  24  28  32  36  40  44  48  52  56  60  64  68  72  76  80  84  88  92  96  100
-v is for verbose?
(I don't know why someone has decided that they should sort like that, but I vaguely think there are some nice answers about it on U&L and probably on AU too)
15:21
No, it stands for "version" based on the idea that, when filenames contain version numbers, passing -v sorts them in the order users expect.
-v     natural sort of (version) numbers within text
I will just pretend to understand for the time being
we can investigate it later, I would also like to know more
Now that we have some files to play with we can try some more globbing. As well as the greedy *, which matches everything, as we saw earlier, there's ? which matches exactly one of any character. Also, you can match one of a selection of characters by putting the options in square brackets.
For example, in this directory
zanna@peach:~/playroom$ ls -l
total 20
drwxrwxr-x 2 zanna zanna 4096 Oct 25 20:48  alphabet
-rw-rw-r-- 1 zanna zanna    0 Oct 25 20:47  four
-rw-rw-r-- 1 zanna zanna  103 Oct 18 20:53  kernel
-rw-rw-r-- 1 zanna zanna   11 Oct 18 20:44  name
drwxrwxr-x 2 zanna zanna 4096 Oct 25 20:48  numbers
-rw-rw-r-- 1 zanna zanna    0 Oct 25 20:47  one
-rw-rw-r-- 1 zanna zanna   23 Oct 18 20:47 'shopping list'
-rw-rw-r-- 1 zanna zanna    0 Oct 25 20:47  three
-rw-rw-r-- 1 zanna zanna    0 Oct 25 20:47  two
I can do
touch *
it did nothing
zanna@peach:~/playroom$ ls -l
total 20
drwxrwxr-x 2 zanna zanna 4096 Oct 25 20:53  alphabet
-rw-rw-r-- 1 zanna zanna    0 Oct 25 20:53  four
-rw-rw-r-- 1 zanna zanna  103 Oct 25 20:53  kernel
-rw-rw-r-- 1 zanna zanna   11 Oct 25 20:53  name
drwxrwxr-x 2 zanna zanna 4096 Oct 25 20:53  numbers
-rw-rw-r-- 1 zanna zanna    0 Oct 25 20:53  one
-rw-rw-r-- 1 zanna zanna   23 Oct 25 20:53 'shopping list'
-rw-rw-r-- 1 zanna zanna    0 Oct 25 20:53  three
-rw-rw-r-- 1 zanna zanna    0 Oct 25 20:53  two
same timestamp!
oh yeah
it didn't create * but touched everything there
15:24
total 0
drwxr-xr-x 1 user user 4096 Oct 25 18:53 ./
drwxr-x--- 1 user user 4096 Oct 25 18:00 ../
drwxr-xr-x 1 user user 4096 Oct 25 18:54 alphabet/
-rw-r--r-- 1 user user  114 Oct 25 18:54 kernel
-rw-r--r-- 1 user user   11 Oct 25 18:54 name
drwxr-xr-x 1 user user 4096 Oct 25 18:54 numbers/
-rw-r--r-- 1 user user    0 Oct 25 18:54 one
-rw-r--r-- 1 user user    0 Oct 25 18:54 shopping list
@jokerdino how could you create a file named *?
@Zanna I quote it
:)
@αғsнιη nice - * didn't match . and .. so they didn't get touched
what if we want to match files with exactly 4 characters in their names
we could do ls ????
but, in case there are any directories that have four-letter names, with ls you should probably use the -d flag, otherwise you will get the contents of the directories instead, like
15:27
Is there a short-way not repeating "?" 4 times?
zanna@peach:~/playroom$ ls ???????
1    12  16  2   23  27  30  34  38  41  45  49  52  56  6   63  67  70  74  78  81  85  89  92  96
10   13  17  20  24  28  31  35  39  42  46  5   53  57  60  64  68  71  75  79  82  86  9   93  97
100  14  18  21  25  29  32  36  4   43  47  50  54  58  61  65  69  72  76  8   83  87  90  94  98
11   15  19  22  26  3   33  37  40  44  48  51  55  59  62  66  7   73  77  80  84  88  91  95  99
@Zanna four name
@αғsнιη maybe but I don't know the way. Like in regex you can do .{4} but I don't know if there are quantifiers for shell wildcards (which are different from regex)
@technastic_tc same here :)
@Zanna that was really confusing... what I really wanted was
zanna@peach:~/playroom$ ls -d ???????
numbers
Let's say we want to match all the files whose names start with t. How could we do that?
I think the same
15:31
right :)
What about if we want to match files whose names start with o, t or f? This is a good use for a character class:
ls -d [oft]*
t* o* f* ?
@Zanna four one three two
@αғsнιη yes, that also works
@technastic_tc same here :)
ls [tof]*
[fot]*
15:33
hahah yes
Globbing doesn't only work with ls - it's a feature of the shell itself. It's not ls that expands stuff, it's Bash. ls receives the arguments four one three and two because the shell expands [otf]* to all the filenames that expression matches. So, we can use globbing with all sorts of commands.
Let's mv some files into a directory.
mv -v [otf]* numbers
I like to mv mv it.
lol
I got this
renamed 'four' -> 'numbers/four'
renamed 'one' -> 'numbers/one'
renamed 'three' -> 'numbers/three'
renamed 'two' -> 'numbers/two'
@Zanna same..
again I feel there's a sorting problem haha
How can we check with ls where our files are now?
ls **?
15:35
ls -R
@Zanna ls numbers?
haha all work
@jokerdino just one * will do the same
I just want to be sure
hahaha
ls * also works; what is the difference of single * and double **, output is same
15:36
Back :-)
@αғsнιη I haven't a clue
level may be
* only first cildren
@αғsнιη there is no difference at the moment, and there will never be a difference in this directory structure, but if you turn on the globstar option, by doing shopt -s globstar then** becomes recursive, so I think you would see all the levels of a directory structure, like with ls -R
we ran out of time again
oh no :(
@Zanna hmm..
15:39
sorry I overran
I didn't notice
we didn't run any date command today..
@Zanna It's ok!
:)
@jokerdino haha but we did check timestamps
@Zanna nice!
@Zanna Why not in this directory structure?
15:40
because none of the directories have subdirectories
thanks everyone for making today's class a great one again! @αғsнιη @Zanna @EliahKagan @technastic_tc @user.dz @BeastOfCaerbannog @karel @ArturMeinild
Thanks for the lesson @Zanna
Thanks!
thanks @jokerdino <3
Thank you
15:42
Thanks
thanks all; thanks @Zanna for the lesson
can we continue again next week?
yes please
Sure
So coffee-/biobreak and back in 15 minutes with SSH/Rsync/Cron (for those interested)
15:45
@ArturMeinild yesss! looking forward to it! Hope some more people will come
Is it in same room here ?
yes, don't miss the next class happening right here in 15 minutes time!
Sorry I misspelled: {coffee,bio}break - wont happen again! xD
we hope you extend the same amount of help and support to @ArturMeinild
@user.dz yes, here
:) good thank you
15:47
@jokerdino Woohoo!
@Zanna That's what I had thought would happen, but when I tried it I got different results. That is, it looks like ** with globstar in bash works differently from ** in some other settings where it is supported (such as ksh and zsh). In playroom, after shopt -s globstar, I do get different results from ls -d * and ls -d ** (as well as different results without -d, though with -d it's easier to see what's going on).
ek@Kip:~/playroom$ shopt -s globstar
ek@Kip:~/playroom$ ls -d *
 alphabet   greeting   kernel   name   numbers   outputfile  'shopping list'   sieve  'two words'   vars   x
ek@Kip:~/playroom$ ls -d **
 alphabet     alphabet/r    numbers/13   numbers/3    numbers/46   numbers/62   numbers/79   numbers/95
 alphabet/a   alphabet/s    numbers/14   numbers/30   numbers/47   numbers/63   numbers/8    numbers/96
 alphabet/b   alphabet/t    numbers/15   numbers/31   numbers/48   numbers/64   numbers/80   numbers/97
O.O
@αғsнιη So I guess you're right. I tried it in a WSL 2 system. I don't have a WSL 1 system to test with but perhaps that's what makes the difference. Do you get zero as the total even when you have nonempty regular files? (I'm wondering if the difference, in WSL 1, is specific to disk usage from directories.)
I was just going to try it too
I guess that makes sense
Zanna has added an event to this room's schedule.
15:54
@EliahKagan file ** returns everything is empty except for parent directory says "directory"
@EliahKagan What's surprising there? I missed the session so I guess it may have been explained, but that seems like the normal output I'd expect from **: it is descending into subdirs.
I added some text to a one file like echo 'something' >name then did 'ls -l' but still ls saying total 0
echo {1..100} >>name
ls -l
no difference
@terdon just me saying wrong stuff
The size of the file won't affect the "total" returned by ls, @αғsнιη. That should be the total number of hardlinks pointing to the directory, if I remember correctly. Usually that is the number of files in the directory.
echo {1..1000} >>name
ls -l
total 8
now it's changed to 8
WSL1 here
15:58
Duh, you're right, sorry. It's not the number of hardlinks.
looks like it's the number of blocks but I'd need to check to be sure
file size is now 4195
@terdon It's blocks, reported (by default) in units of 1024 bytes. (POSIXLY_CORRECT changes that to units of 512 bytes.)
OK. Can you find a reference for that? I assumed as much based on the output, but I don't see it in man ls or info ls so far.

« first day (28 days earlier)      last day (22 days later) »