IRC log of #novawebdev for Monday, 2023-09-11

*** shmohamud has quit (Ping timeout: 480 seconds)00:01
*** shmohamud has quit (Ping timeout: 480 seconds)00:21
*** shmohamud has quit (Remote host closed the connection)00:39
*** shmohamud has quit (Remote host closed the connection)00:43
*** shmohamud has quit (Ping timeout: 480 seconds)01:22
*** shmohamud has quit (Ping timeout: 480 seconds)01:59
*** shmohamud has quit (Ping timeout: 480 seconds)06:49
*** shmohamud has quit (Remote host closed the connection)07:00
*** shmohamud has quit (Ping timeout: 480 seconds)08:10
dcammueGood morning jelkner 10:55
*** dcammue has quit (Read error: Connection reset by peer)11:02
*** jelkner has quit (Quit: Leaving)11:12
*** svaye_ has quit (None)11:20
*** svaye has quit (Ping timeout: 480 seconds)11:21
*** shmohamud has quit (Remote host closed the connection)12:15
mulbahHow are you doing shmohamud12:58
mulbahGood morning Mr. Cole13:00
mulbahHow are you doing13:00
ubuntouristHi13:00
ubuntouristHaving my usual slow morning...13:01
ubuntouristHow about you?13:01
mulbahI'm good13:02
*** shmohamud has quit (Ping timeout: 480 seconds)13:02
mulbahMr. Cole tboimah will not be with us today because he isn't feeling well 13:02
mulbahMalaria is giving he hard time13:02
ubuntouristYeah, Jeff said on Saturday that he was suffering with that. Ouch!13:03
ubuntouristI hope he recovers soon. You and the log can fill him in on what he misses.13:03
ubuntouristSo.... We stopped last time right at the point where I said "Now it gets harder" in my notes.13:04
mulbahI pray so too13:04
ubuntouristI think, before continuing with that, I'd like to make a short detour to show 13:06
ubuntouristone of my most usful aliases.13:07
ubuntouristSo crank up tmate.13:07
mulbahssh vqff9HLtqMvEzTnk8mhX3UgKe@lon1.tmate.io13:08
ubuntouristAnd now ssh to your server13:08
ubuntouristOK. This is all about egrep today - egrep is the Extended version of grep,13:10
ubuntouristIt has a few more fancy things it can do. And like before, we're going to build up to a reason for using it.13:10
ubuntouristWe're going to be looking at a systems administration configuration file.13:11
ubuntouristYou don't have to understand what this particular file does. At least, not yet.13:11
ubuntouristcd /etc13:11
ubuntouristegrep -cr "^[[:space:]]*#" *13:12
ubuntouristColon not semicolon13:13
ubuntouristMissing the "e"13:13
ubuntouristNow, an explanation of what you just saw.13:14
ubuntouristI mentioned that wildcards and regular expressions are related, but different. This command used both.13:15
ubuntouristThe asterisk at the very end is a wildcard. We want to search "all files" in the directory.13:15
mulbahI'm not understanding the -cr13:16
mulbahbut for the other13:16
ubuntouristI was starting to type that explanation. ;-)13:16
ubuntouristThe -cr is a cobination of two options together. You could write it as "-c -r" (or "-r -c")13:17
mulbahokay13:17
ubuntouristThe "-r" means "recursive". That means search directories in directories in directories...13:17
ubuntouristWithout the "-r" egrep would only search the files in /etc, but not in /etc/X11/ or /etc/vim/ or any subdirectories.13:18
ubuntouristWe want to search all files under the /etc directory. So "-r"13:18
ubuntouristThe "-c" is for "count". Instead of showing each line that matches the search, show me how many matches you found13:19
ubuntouristeven if that is zero. So, for example, the file "X11/rgb.txt" had NO matches. You can see:13:20
ubuntouristX11/rgb.txt:013:20
ubuntouristThe middle part -- the actual regular expression "^[[:space:]]*#" you say you understood. 13:21
ubuntouristDo you want to explain it?13:21
mulbahYeah13:22
ubuntouristOK... Give it a go.13:22
mulbah07_the ^[[:space:]]*# it say matches start of all space characters13:25
ubuntouristThere's a little more to it...13:26
ubuntourist(Should I continue and explain? Or are you figuring it out?)13:28
ubuntouristACTION waits to find out if the network is dead again.13:29
mulbah07_really I'm not understanding the "space" that is in the bracket I'm only familiar with the dight lower and upper13:29
ubuntouristOK.13:30
*** mulbah has quit (Ping timeout: 480 seconds)13:30
ubuntouristThe simpler "grep" has a few patterns that use a backslash followed by a letter for some special meanings.13:31
ubuntouristFor example "\d" means any digit. \d* would be any string of zero or more digits. There is a combination like13:32
ubuntouristthat which means space. But I always forget what it it is. (Either \w or \W -- I forget which is which, is "close" to what I want.13:34
ubuntouristOne means "word" the other means "not a word". One searches for strings of consecutive letters. The other seearches13:35
ubuntouristfor strings of consecutive NON-letters. Like space, semicolon, colon, period, quotes etc. puctuation and spaces.13:35
ubuntouristBut egrep can use more descriptive patterns. [[:space:]] means any kind of space character. So, spaces and tabs, mostly.13:36
ubuntouristYou had the right idea, but with a little bit of information missing:13:37
ubuntourist^ = Starting at the beginning of a line13:37
ubuntourist[[:space:]] = a space or a tab13:38
ubuntourist* = zero or more of those13:38
ubuntouristand finally "#" which just means "#". No special meaning.13:38
ubuntouristSo the command is:13:38
*** mulbah has quit (Remote host closed the connection)13:39
ubuntouristSo the full meaning of the command is:13:39
ubuntouristGive me the count of all lines that start with zero or more spaces followed by  the number sign. Search all files and subdirectories.13:40
ubuntouristLet me know when you're caught up.13:40
mulbahyeah I have13:41
ubuntouristOK. What I want to do is find a good example file to work with. And so, I'm searching for a file with LOTS of lines starting with "#"13:42
ubuntourist(or "           #") I want the first non-space character to be "#" 13:42
ubuntouristAnd I am making you go through the steps I went through to find an example.13:43
ubuntouristSo, let's add to the command: We're going to use the pipe to filter out all files that have zero matches.13:43
ubuntouristegrep -cr "^[[:space:]]*#" *  | grep -v "\:0$"13:44
ubuntouristThis says: Instead of printing the results, search for lines that do NOT match ":0" at the end.13:45
*** ubuntourist has left #novawebdev (Leaving)13:45
kjcoleOops13:46
kjcoleNow you should see that "X11/rgb.txt:0" is no longer in the list.13:47
kjcoleUse Ctrl-R instead of scrolling up and down13:48
kjcoleSometimes, if "grep" or "egrep" cannot open a file, or if the file that maches cannot be printed to the screen,13:49
kjcolegrep or egrep will give an error message. If we don't want to see the error, we can "redirect" the error to somewhere else.13:50
mulbah-r right13:50
kjcoleWe could say "send the error to a file instead of the screen" or "send the error to... nowhere"13:51
kjcoleTo send the error to "nowhere" it is "2> /dev/null"  13:51
kjcoleSo we're going to ignore errors with:13:52
kjcoleegrep -cr "^[[:space:]]*#" * 2> /dev/null  | grep -v "\:0$"13:52
kjcoleBUT13:52
kjcoleBEFORE YOU START TYPING...13:52
kjcoleWe're going to use some of those keyboard shortcuts I've talked about being very important to learn.13:52
kjcoleso. Up-arrow. Then, escape then b. Repeat ESC b until you are at the *13:54
kjcoleWell if you're doing Ctrl-R just type "grep" and it should find the last grep13:54
kjcoleHmmm...13:55
kjcoleIt should have found it...13:55
kjcoleAh, it did.13:55
*** JulianMolina has quit (Remote host closed the connection)13:55
kjcoleBut it found my commented one. So, Ctrl-A, and then Ctrl-D, then Ctrl-E, THEN ESC b a few time.13:56
kjcoleNever mnd.13:56
kjcoleIt looks like you have the whole command there.13:56
kjcoleGo ahead13:57
mulbahokay13:57
kjcoleThe list looks basically the same. But trust me. The first time, there were errors (if I remember right). This time, the errors were ignored.13:58
kjcoleWe're going to add a little mmore to the end...13:58
kjcoleBut before you type it, I will explain the new part:13:59
kjcoleegrep -cr "^[[:space:]]*#" * 2> /dev/null  | grep -v "\:0$" | sort -n -t ":" -k 213:59
kjcoleWe are adding a pipe to         sort -n -t ":" -k 214:00
mulbahMr. Cole what the ":" means14:00
kjcoleI want to sort the results, so that the largest number is at the end. Remember: We're looking for a file with LOTS of lines starting "#"14:00
kjcoleWhen you sort a file, sometimes you do not want to sort from the start of a line. For example, if you had a list of people, and you had their names and ages,14:01
kjcolesometimes you would want to sort by their last name. But maybe sometimes you want to sort by their ages. 14:02
kjcoleSo you need a way to tell the sort command which part of the line you want to sort. The parts are called "fields" or "keys" (or sort key, key field, etc.)14:03
kjcoleAll of the lines that were printed back to you looked like:14:03
kjcoledirectory/filename:number14:03
kjcoledirectory/filename:number14:04
kjcoledirectory/filename:number14:04
kjcoleYou can see that on your screen now.14:04
kjcoleThe ":" is the "field delimiter" or "field separator" or "field terminator" (they all mean the same thing.)14:05
kjcolealso, when you have numbers of different lengths ( for example, 0, 22, 403, 1022)  sort needs to know that it sould sort them as numbers with iimaginary zeros at the start. (Leading zeros.)14:06
kjcoleFor example, if it does not know that the values are supposed to be numbers, it will say that 8 is bigger than 50, because it compares the "8" and the "5" and then it compares the end of the line with "0".14:08
kjcoleIt should instead interpret "8" as "08" and "50" as "50". Now it compares "0" to "5" and says "0 is less".14:09
kjcoleSo... Now the parts of the sort command.14:09
*** shmohamud has quit (Remote host closed the connection)14:09
kjcole"-n" means "I want you to interpret the sort key as a number, not as a text string."14:10
kjcole-t ":" means "the field terminator is a colon. Colon separates the fields."14:10
kjcole-k 2 means "I want to sort on the second field"14:11
kjcoleSo, I want sort to interpret everything after the first (and in this case only) colon as a number, and use that to sort by.14:12
kjcoleGo ahead. I need to step away for a bathroom break.14:12
mulbahokay14:12
*** shmohamud has quit (Remote host closed the connection)14:12
kjcoleI'm back. So, look at that last number! Wow!14:17
kjcoleAs you know from Python, and from the command line, "#" starts a comment and comments are ignored.14:18
kjcoleWe just found a system administration file with 1,961 liines that are comments!14:18
kjcoleThat's a hell of a lot of comments!14:19
kjcoleSo, take a look at the contents of the file, using most... (You should be able to figure that out for yourself now.)14:19
kjcoleNope. I want you to look at the file, not the list of files.14:21
*** shmohamud has quit (Remote host closed the connection)14:21
kjcoleMaybe explain back to me what you see on the screen 14:22
mulbahon my terminal 14:22
kjcoleYes.14:23
kjcole(Without typing anything in the terminal, what are you seeing in the terminal window right now?)14:24
mulbahI'm seeing a list of files14:24
kjcoleAnd?14:25
kjcole(I mean, explain the list more.)14:25
mulbahI'm not understanding what you means Mr. Cole14:28
kjcoleOK. I was hoping for an explanation like:14:29
kjcole"I am seeing a list of files  which conatain lines that start with "#" or spaces followed by "#"  and the count of the number of matches. This list is sorted from the files with the fewest matches, to the files with the most matches."14:31
kjcoleAnd earlier, I wanted you to show me the contents of the file with the most matches, by using the "most" command to view the contents of that file.14:32
kjcoleFirst we found files that matched the pattern. 14:32
kjcoleThen we eliminated files with zero matches.14:33
kjcoleThen we eliminated error messages.14:33
kjcoleThen we sorted the list, so that the files with the most matches would appear last.14:34
kjcoleNow I want to see what is in the file with the most matches.14:34
kjcole(It may seem silly, but we're building up to a reason for doing all of this.)14:36
kjcoleACTION waits... But only 23 minutes left today...14:37
ubuntouristHello? Still there?14:41
mulbahYeah14:41
mulbahtrying to understand what you means14:41
ubuntouristOK. I have failed to explain something. But I am not sure where I failed. So, ask more questions. Maybe I can make it clearer.14:42
ubuntouristDo you know what I mean by sorting the list of matching file names?14:44
mulbahno14:45
ubuntouristok.... Look at the list right now on the screen and try to remember the last two or three lines. 14:46
ubuntouristActually, I'll copy them here:14:46
ubuntouristlogin.defs:27414:46
ubuntouristfail2ban/jail.conf:31414:46
ubuntouristlocale.gen:50014:47
ubuntouristpostgresql/13/main/postgresql.conf:62314:47
ubuntouristlvm/lvm.conf:1961 14:47
ubuntouristNow look at the last few lines... (I removed the sort.)14:48
ubuntouristCompare that to the lines that I copied into the IRC above.14:49
mulbahthey are different14:50
ubuntouristCan you explain anything about the differences in the two lists? The order in which the two are listed?14:50
*** shmohamud has quit (Ping timeout: 480 seconds)14:51
ubuntourist(Sorting = rearranging the order, rearranging the sequence.)14:52
ubuntouristOnly 7 minutes left...14:54
ubuntouristOK... Send me e-mail with what you DO understand about what we did today. Explain each step that you feel confident in understanding. Then, let me know where you stopped understanding.14:57
ubuntouristRefer back to the log, and to your "history" command.14:58
mulbahokay Mr. Cole14:58
ubuntouristOnce I know where things went wrong, I can try to improve my explanation.14:59
ubuntourist(And keep a file with your own personal notes and progress. I still do that for myself a lot, because it is very hard to remember everything. Good journals help.)15:00
mulbahThanks for today Mr. Cole I will try to do that15:01
ubuntouristJeff likes to keep a blog of some of his progress. But he mixes in everything: Stories about trips, philosophy of socialism, which books he's listening to, and his progress with technology.15:01
ubuntouristHe also writes for other people to read. I keep my notes strictly about technology, and they are to help ME more than anyone else. (If I discover something really clever, I write a separate explanation -- with a lot less cursing -- for other people to read.)15:03
ubuntouristBye for now. I will keep an eye open for your e-mail.15:04
mulbahokay15:04
mulbahBye15:04
*** ubuntourist has quit (Quit: Leaving)15:04
*** mulbah has quit (Quit: Leaving)15:04
*** Guest2498 has quit (Ping timeout: 480 seconds)16:13
*** shmohamud has quit (Remote host closed the connection)18:13
*** shmohamud has quit (Remote host closed the connection)18:19
*** shmohamud has quit (Ping timeout: 480 seconds)18:39
*** shmohamud has quit (Remote host closed the connection)18:49
*** shmohamud has quit (Ping timeout: 480 seconds)19:09
*** shmohamud has quit (Ping timeout: 480 seconds)19:51
*** shmohamud has quit (Ping timeout: 480 seconds)20:17
*** scooper has quit (None)21:24
*** shmohamud has quit (Ping timeout: 480 seconds)22:07
*** shmohamud has quit (Ping timeout: 480 seconds)23:31

Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!