« first day (35 days earlier)    last day (15 days later) » 
14:00 - 16:0016:00 - 19:00

14:28
Hello!
Hi! good to see y'all
I am going to cd playroom again
Hey all!
If you weren't here previously, and don't have a bunch of stuff in here to play with already, to make the following examples I have prepared work, you could run these commands
mkdir playroom
cd playroom
echo $USER > name
echo chocolate > "shopping list"
mkdir numbers
touch numbers/{1..100}
hello everyone
14:32
I see some folks who were here last time, and I think we were using the mv command last
@jokerdino Hello!
I was going to give you a challenge to summarize the behaviour of mv
@Zanna It can be used to move the location of a file and it can also be used to rename the file. Am I right?
@technastic_tc yes, correct
in more detail though, I'll ask some questions :)
1. What does mv do, if you provide exactly two words (ignoring any options, such as the -v option, which I like (words after the first word of a command can be called "arguments", but we don't need to fight about it), and the first one is the name (or more accurately, the path) of a file that does exist, and the second one is not the name of an existing file
I mean like
mv file-that-exists word-that-is-not-the-name-of-an-existing-file
example here (assuming you don't have a file called imaginary-friend)
mv name imaginary-friend
will it rename file?
from name to imaginary-friend.
14:37
yes :) the file name will be renamed imaginary-friend
2. What will mv do if the first word (ignoring options) is a file that exists and the second word is the name of a directory that exists?
example here:
mv imaginary-friend numbers
it will move imaginary-friend file to the directory named numbers
sounds about right
yes
3. there are more than two arguments and the last one is not a directory?
(we saw that last time too)
14:42
sorry I must leave, I do not feel well today
@nobody take care!
no problem!
@nobody Take care.
I hope you're feeling better soon!
@Zanna I didn't get the question. Please give some example.
14:44
@technastic_tc sorry!
mv one two three
I guess.. file one will be renamed to two. Now two will be renamed to three. I might be wrong..
that would be bad, right?
so mv will complain that the last argument is not a directory, because you would lose at least one file otherwise, as two files can't have the same name
@Zanna oh.. ok..
but if you give more than 2 arguments and the last one is a directory what would happen?
if you want, you can try it with the last example, do
touch one two
mkdir three
mv one two three
it will move the renamed file to directory three?
14:49
nope
since file names can't be same for two files.. the command will fail?
Why not try it?
both the files one and two will be moved to directory three..
yes :)
@EliahKagan just now tried it :)
14:51
:)
so the last argument is always assumed to be the target
@technastic_tc sorry I should have said that you can try it, it wasn't meant to be like a memory test or anything
but there is a useful option -t to specify the target even if it's not the last argument
@Zanna oh.. ok.
sorry my bad
@Zanna Never mind!
so you can try this command
mv -t numbers three
14:54
mv: cannot overwrite non-directory 'numbers/three' with directory 'three'
what a useful error :)
Hey - sorry for the delay
so it tried to move the directory three into the directory numbers, (or to rename ./three to numbers/three) exactly as we asked, instead of trying to move numbers into three
but you already have a file called three in there so it failed - your file didn't get overwritten
which is good
you could just specify a different name like this (sorry I should be using the -v flag!)
mv -t numbers/three2 three
@ArturMeinild no worries! welcome back!
mv: failed to access 'numbers/three2': No such file or directory
Must the directories exist before moving into them or mv creates the necessary ones?
14:59
@technastic_tc Hi! and same error for me too
@αғsнιη Hello! ok..
@Zanna The operand to -t has to identify a directory, right?
@technastic_tc oh, same here, I was expecting it to work, but it didn't
@BeastOfCaerbannog the directories must exist, mv will not create them.
@EliahKagan apparently :D
I guess we should rename our directory three first, and then move it
like mv three three2 && mv -t numbers three2
phew it worked for me
15:01
@terdon That's why @technastic_tc had this error.
yes
@Zanna So mv x y and mv -t y x don't mean quite the same thing. y need not identify a directory in mv x y and if it doesn't then x is renamed to y instead of being renamed to y/x (i.e., instead of being moved into y), but in mv -t y x it is required that y identify a directory. man mv summarizes the -t syntax as:
mv [OPTION]... -t DIRECTORY SOURCE...
@BeastOfCaerbannog well, the numbers directory exists
@EliahKagan thank you :) :)
if I remember rightly, last time we had an example where mv overwrote a file - if you mv some-file file-that-existed-already, the contents of file-that-existed-already get replaced with the contents of some-file
to create a new directory, we use mkdir
@Zanna that's terrible
@jokerdino yes
and yess
15:05
that will not ask us for confirm?
:|
nope
No. This is Linux, not Windows.
@terdon haha..
> It is not UNIX’s job to stop you from shooting your foot. If you so choose to do so [sic], then it is UNIX’s job to deliver Mr. Bullet to Mr Foot in the most efficient way it knows.
@terdon lol..
15:07
: )
You can make mv prompt you, if you like, by using mv -i:
@terdon :-D
$ mv -i file file1
mv: overwrite 'file1'?
@terdon nice
@terdon Oh, that looks good
15:08
So, tell unix you are holding a gun first
what about if you mv a file into a directory that already has a file with the same name (actually we just saw mv refuse to do that when the file we were trying to move in was a directory and there was a non-directory with the same name there already, but it might not be the same with two non-directories)
I am going to test it...
You will simply overwrite the destination.
mkdir useful-stuff
mv -v shopping\ list useful-stuff
As long as the destination exists, mv will either copy the source into it (when the destination is a directory) or will overwrite it (when the destination is a file). It doesn't matter if the destination is in the same directory or not.
@Zanna renamed 'shopping list' -> 'useful-stuff/shopping list'
15:10
oh wait what was in that shopping list?
cat useful-stuff/shopping\ list
seems we lost our shopping list
oh no
what will we do??
really?
I still have mine...
@terdon yes...
sorry, mine moved to useful-stuff directory
15:12
phew, so we still have it
@Zanna (yeah, sorry, I thought you were asking, I hadn't realized you were going for the Socratic method)
@Zanna yes, and I only have a chocolate in it
I find the tree command useful for seeing a whole directory tree. (It is not installed by default on all flavors and releases of Ubuntu, but it is provided by the tree package.)
I also like the tree very much.
yes! but the output is messed up a bit by this directory full of numbers right now
@αғsнιη good, remember that!
now let's write a new shopping list
15:14
But tree snap package may not list all files and directories :/
let us write a file using a text editor!
@Zanna GUI <3
I am going to use nano which is an easy command line text editor
@technastic_tc no need to resort to extreme measures
@terdon Note, though, that the destination being a directory does not mean no file will be lost, because the destination may itself contain a file of the same name as the file being moved, and if that file is not itself a directory then it will be replaced. (If it is a directory then mv gives an error about not being able to overwrite a directory with a non-directory.)
@Zanna ok..
15:15
nano 'shopping list'
Yes, of course. In that case, the destination is a file (targetDir/originalFileName) so it is overwritten.
I have cheese and oregano
@jokerdino I planted (I mean installed) a tree and that's cool
@jokerdino oh, it's supposed to be empty
I also have those items, though the oregano is first.
15:17
@Zanna mine is empty
@Zanna yeah.. since we already moved the file to useful stuff.. a new file will be created in playroom I guess..
@technastic_tc yessss
Should we rename our shopping list so nano works on a new file?
I think I should abandon this example
and go for a walk
15:18
:(
and y'all carry on hahahaha
I will create a new shopping list
@Zanna May as well go buy yourself some cheese and oregano.
I have to make my own cheese cause I'm vegan
@EliahKagan we already moved the old shopping list, so we should already be working on a new one
I opened shopping list on playground so it's empty now
15:19
but when we move it to the same place, it will have the same name
OK, so what to buy now?
I guess y'all were trying to compensate for my mistakes
@αғsнιη anything you like
I am going to buy some apples and bananas. Maybe some bread too.
@Zanna emm, I just back from shopping half hour ago
: )
cashews
dates
pistachios
15:21
@Zanna Sorry, i must've missed a command.
Anyway I am editing a brand new shopping list with nano.
11 mins ago, by Zanna
mkdir useful-stuff
mv -v shopping\ list useful-stuff
@Zanna then we can buy with echo cashews dates pistachios >>shopping\ list?
@EliahKagan I'm sorry for the confusion <3
@αғsнιη we are learning how to use nano
15:22
@αғsнιη sure yes, but they will all be on one line then
or we can take by ourselves
@jokerdino yess
My new shopping list is open in nano
Oh and my identity has appeared, hello all
@SirGuelph hello
15:23
hello
:)
after you wrote your list, you can press Ctrl+O to save it
then you have to confirm the file name by pressing enter
then press Ctrl+X to exit
all these instructions are at the bottom of the window, helpfully
@αғsнιη oh no, what happened?
I press Ctrl+O then Ctrl+X but for later it play a ding sound
15:25
it worked alright for me
I don't know what went wrong
did you press enter?
after Ctrl + O
@Zanna Ahh, that was waiting for my confirmation.
:)
Yeah. When you press Ctrl+O, you are prompted to tell nano how you want to name the file. Since you gave nano a name already, it shows that name. You can just press enter to have it use that name.
@EliahKagan thanks :)
15:26
that worked for me ^
ok, now let's mv the new shopping list into the useful-stuff directory
Will that clobber my oregano and cheese?
innocent face
maybe?
@EliahKagan cannot do save and exit in one short-cut?
15:28
@EliahKagan my new list eaten the old list
@αғsнιη You can do Ctrl+X without saving first. Then nano asks if you want to save.
@jokerdino oh no!
same here
we lost our old list
@EliahKagan thanks
but there is an option to not do that, which is -n (--no-clobber)
@jokerdino we can back to buy that again :P
15:30
@Zanna oh
let's rewrite the old shopping list and try it (hope you remember what was in it)
what will it do?
try it and see...
Where should we put the new old shopping list?
I guess I just lost everyone's trust
15:31
yes, it did not move. I have two lists now
@EliahKagan I'll put it in playroom
I want to find how many shopping list do I have first
@αғsнιη maybe tree can tell you
I have one in the playground and one in usefulstuff
@jokerdino excellent!
better rename one of them
15:33
I used mv to rename the new old list
good job
now you can safely move it to the same directory as the other one
you can also rename the file inside nano
interesting!
just put a different name when it asks you to confirm and then confirm again
I've named the file as shopping list old
@technastic_tc good job
15:34
@Zanna helpful, thanks
@Zanna Doesn't that make a copy with a new name, rather than changing the name of the existing file?
@EliahKagan yes
I think so yes
I also deleted the old new old list to remove any incriminating evidence
but then you can remove the old one using... rm
@jokerdino hahaha
We've unfortunately run out of time :(
15:36
oh no
oh no
that's terrible
how did I waste so much time?
I thought we were going to finish early
I'm so sorry
we didn't pay yet for our shopping
We've always run a bit over before and there's a half-hour gap before the next class, so I assume it is okay to wrap up rather than stopping immediately.
lots of errors with command executions today..
@Zanna Don't be sorry. It's ok.
15:37
yeah we should try to quickly finish up right now
there is only a small bit remaining
@EliahKagan sure!
let's goo
the rm command is also one to be careful with
is removes files and they don't go to trash or anything, they just go
Let's try removing the empty number files we created earlier
we can use a character class for that job, like...
there's quite a few of them
15:39
rm -v numbers/[1..9]*
nothing removed for me
removed 'numbers/1'
removed 'numbers/10'
removed 'numbers/100'
removed 'numbers/11'
removed 'numbers/12'
removed 'numbers/13'
removed 'numbers/14'
removed 'numbers/15'
removed 'numbers/16'
removed 'numbers/17'
removed 'numbers/18'
removed 'numbers/19'
removed 'numbers/9'
removed 'numbers/90'
removed 'numbers/91'
removed 'numbers/92'
removed 'numbers/93'
removed 'numbers/94'
removed 'numbers/95'
removed 'numbers/96'
removed 'numbers/97'
removed 'numbers/98'
removed 'numbers/99'
@technastic_tc nice
for some reason, I have some files between 2-8
15:41
I got the same result as @technastic_tc
here I should mention that shell globs are different from regex, in case you have any familiarity with regex!
@jokerdino what happened?
 ls numbers/
2   22  25  28  30  33  36  39  41  44  47  5   52  55  58  60  63  66  69  71  74  77  8   82  85  88    three
20  23  26  29  31  34  37  4   42  45  48  50  53  56  59  61  64  67  7   72  75  78  80  83  86  89    two
21  24  27  3   32  35  38  40  43  46  49  51  54  57  6   62  65  68  70  73  76  79  81  84  87  four
In regex `[1-9]*` matches zero or more of any of the characters 1, 2, 3, 4, 5, 6, 7, 8 or 9
Here, it matches exactly one character which can be 1, 2, 3, 4, 5, 6, 7, 8 or 9, and any number of any characters at all after that.
Ohh, that's [1-9] not [1..9]?
@jokerdino that is interesting
15:42
wait, I run [1..9]*
@αғsнιη same
The issue is that [1..9] matches a character that is a 1 or a . or a . or a 9 (which is the same as matching a 1 or a . or a 9, since . is the same as .).
@Zanna I remember we should use {1..9} but you used [1..9]
@αғsнιη yeah, not [1..9] ... that would be any file starting with 1, 9, or . (but rm does not operate on . .. iirc)
I typed the right command when I ran it
but I typed the wrong command here
sorry!
@Zanna That's what's important! :D
15:44
hahaha omg I suck
For some reason, some people seem to add the -r and -f options every time they use rm. That's bad! The -r option makes rm recursive, so that it can remove directories and their contents. Obviously, if you mess up and type the wrong thing as an argument, you would lose a lot more data with -r than without. So you should only use -r when you're sure you want to completely and permanently remove a directory.
4
anyway, I deleted the right number of numbers with [1-9]*
-f prevents rm from prompting the user before deleting files it thinks you might not have intended to delete and from complaining about files you've specified not existing. I just never use that option at all, but it is useful for non-interactive scripts.
@jokerdino sorry hahaha
OK last command for working with files
@Zanna Indeed. I also had made a file called 5ive in numbers, and rm -v numbers/[1-9]* deleted that too. :)
@EliahKagan nice :) :)
cp which copies stuff!
create a file
echo magic > rainbow
copy it
cp rainbow unicorn
15:47
cat is actually for conCATenating files...
cat rainbow unicorn
magic
magic
oh lol
magic
magic
I have been using it for just viewing files
didn't even know it does that
:)
15:48
ek@Kip:~/playroom$ cat useful\ stuff/*
cashews
dates
pistachios
three books
an owl
oregano
cheese
ek@Kip:~/playroom$ ls useful\ stuff/
'shopping list'  'shopping list.orig'
I can even cat unicorn twice
haha yes
@EliahKagan yay for books
Can we cat files and save the result in another file?
yes! with redirection
I think we used the >> for that
15:50
like cat unicorn rainbow > smile
@jokerdino yes > or >> to append instead of overwriting
As with mv, cp will overwrite its target if it is an existing file!
@Zanna sweeet
zanna@peach:~/playroom$ echo sunshine > happy
zanna@peach:~/playroom$ cat rainbow
magic
zanna@peach:~/playroom$ cp happy rainbow
zanna@peach:~/playroom$ cat rainbow
sunshine
lost the magic^
@SirGuelph :)
Also similar to mv, if its target is an existing directory, cp creates files in that directory
in that way, it kinda works like mv?
zanna@peach:~/playroom$ ls numbers
four  one  three  three2  two
zanna@peach:~/playroom$ mkdir words
zanna@peach:~/playroom$ cp numbers/* words
cp: -r not specified; omitting directory 'numbers/three2'
zanna@peach:~/playroom$ ls words
four  one  three  two
@jokerdino yes, only it doesn't remove the files you already had
15:53
I see
that's right
numbers/* expands to match all the files in numbers, so cp copied all those files to the new directory words
got it
but it won't move directories - you have to add the -r (recursive) flag for that
Won't copy them, you mean?
yes!
(mv doesn't have an -r flag, and it does move directories)
15:56
thanks, noted
OK very last thing
the type command shows you what kind of command a command is
I see we can use cp and rm to simulate the mv command? right?
@αғsнιη definitely, yes
you can try type on the commands we have used
@αғsнιη O_O
wonder if mv actually does that in the backend
type less man mv ls cd type
15:57
less is /usr/bin/less
man is hashed (/usr/bin/man)
mv is hashed (/bin/mv)
ls is aliased to `ls --color=auto'
cd is a shell builtin
type is a shell builtin
ls is an alias (a nickname for a command), but the alias contains ls. So to find out what kind of command the "real" ls is you can run type -a ls
yes same ^
type -a shows information for all the versions of a command, if there is more than one command with the same name.
@jokerdino Copies and then deletes the original? Only if it is moving a file to a different filesystem.
cd and type are built into the shell. Commands that are shell builtins don't have individual man pages (their man page can be accessed with man bash, but it's extremely long (you may find it easier to read the Bash manual online) but you can usually run help command to get information about how to use them. For example
15:58
:56015826
less is /usr/bin/less
less is /bin/less
man is /usr/bin/man
mv is /bin/mv
ls is aliased to `ls --color=auto'
ls is /bin/ls
cd is a shell builtin
type is a shell builtin
help type
help cd
@EliahKagan thanks
Notice that the output doesn't come in a pager like when we run man. How can we solve this?
use pipe
pipe it into less!
@jokerdino yayyy
15:59
yay
help cd | less
2
14:00 - 16:0016:00 - 19:00

« first day (35 days earlier)    last day (15 days later) »