*** 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 | |
dcammue | Good 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 | |
mulbah | How are you doing shmohamud | 12:58 |
mulbah | Good morning Mr. Cole | 13:00 |
mulbah | How are you doing | 13:00 |
ubuntourist | Hi | 13:00 |
ubuntourist | Having my usual slow morning... | 13:01 |
ubuntourist | How about you? | 13:01 |
mulbah | I'm good | 13:02 |
*** shmohamud has quit (Ping timeout: 480 seconds) | 13:02 | |
mulbah | Mr. Cole tboimah will not be with us today because he isn't feeling well | 13:02 |
mulbah | Malaria is giving he hard time | 13:02 |
ubuntourist | Yeah, Jeff said on Saturday that he was suffering with that. Ouch! | 13:03 |
ubuntourist | I hope he recovers soon. You and the log can fill him in on what he misses. | 13:03 |
ubuntourist | So.... We stopped last time right at the point where I said "Now it gets harder" in my notes. | 13:04 |
mulbah | I pray so too | 13:04 |
ubuntourist | I think, before continuing with that, I'd like to make a short detour to show | 13:06 |
ubuntourist | one of my most usful aliases. | 13:07 |
ubuntourist | So crank up tmate. | 13:07 |
mulbah | ssh vqff9HLtqMvEzTnk8mhX3UgKe@lon1.tmate.io | 13:08 |
ubuntourist | And now ssh to your server | 13:08 |
ubuntourist | OK. This is all about egrep today - egrep is the Extended version of grep, | 13:10 |
ubuntourist | It 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 |
ubuntourist | We're going to be looking at a systems administration configuration file. | 13:11 |
ubuntourist | You don't have to understand what this particular file does. At least, not yet. | 13:11 |
ubuntourist | cd /etc | 13:11 |
ubuntourist | egrep -cr "^[[:space:]]*#" * | 13:12 |
ubuntourist | Colon not semicolon | 13:13 |
ubuntourist | Missing the "e" | 13:13 |
ubuntourist | Now, an explanation of what you just saw. | 13:14 |
ubuntourist | I mentioned that wildcards and regular expressions are related, but different. This command used both. | 13:15 |
ubuntourist | The asterisk at the very end is a wildcard. We want to search "all files" in the directory. | 13:15 |
mulbah | I'm not understanding the -cr | 13:16 |
mulbah | but for the other | 13:16 |
ubuntourist | I was starting to type that explanation. ;-) | 13:16 |
ubuntourist | The -cr is a cobination of two options together. You could write it as "-c -r" (or "-r -c") | 13:17 |
mulbah | okay | 13:17 |
ubuntourist | The "-r" means "recursive". That means search directories in directories in directories... | 13:17 |
ubuntourist | Without the "-r" egrep would only search the files in /etc, but not in /etc/X11/ or /etc/vim/ or any subdirectories. | 13:18 |
ubuntourist | We want to search all files under the /etc directory. So "-r" | 13:18 |
ubuntourist | The "-c" is for "count". Instead of showing each line that matches the search, show me how many matches you found | 13:19 |
ubuntourist | even if that is zero. So, for example, the file "X11/rgb.txt" had NO matches. You can see: | 13:20 |
ubuntourist | X11/rgb.txt:0 | 13:20 |
ubuntourist | The middle part -- the actual regular expression "^[[:space:]]*#" you say you understood. | 13:21 |
ubuntourist | Do you want to explain it? | 13:21 |
mulbah | Yeah | 13:22 |
ubuntourist | OK... Give it a go. | 13:22 |
mulbah07_ | the ^[[:space:]]*# it say matches start of all space characters | 13:25 |
ubuntourist | There's a little more to it... | 13:26 |
ubuntourist | (Should I continue and explain? Or are you figuring it out?) | 13:28 |
ubuntourist | ACTION 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 upper | 13:29 |
ubuntourist | OK. | 13:30 |
*** mulbah has quit (Ping timeout: 480 seconds) | 13:30 | |
ubuntourist | The simpler "grep" has a few patterns that use a backslash followed by a letter for some special meanings. | 13:31 |
ubuntourist | For example "\d" means any digit. \d* would be any string of zero or more digits. There is a combination like | 13:32 |
ubuntourist | that 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 |
ubuntourist | One means "word" the other means "not a word". One searches for strings of consecutive letters. The other seearches | 13:35 |
ubuntourist | for strings of consecutive NON-letters. Like space, semicolon, colon, period, quotes etc. puctuation and spaces. | 13:35 |
ubuntourist | But egrep can use more descriptive patterns. [[:space:]] means any kind of space character. So, spaces and tabs, mostly. | 13:36 |
ubuntourist | You had the right idea, but with a little bit of information missing: | 13:37 |
ubuntourist | ^ = Starting at the beginning of a line | 13:37 |
ubuntourist | [[:space:]] = a space or a tab | 13:38 |
ubuntourist | * = zero or more of those | 13:38 |
ubuntourist | and finally "#" which just means "#". No special meaning. | 13:38 |
ubuntourist | So the command is: | 13:38 |
*** mulbah has quit (Remote host closed the connection) | 13:39 | |
ubuntourist | So the full meaning of the command is: | 13:39 |
ubuntourist | Give 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 |
ubuntourist | Let me know when you're caught up. | 13:40 |
mulbah | yeah I have | 13:41 |
ubuntourist | OK. 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 |
ubuntourist | And I am making you go through the steps I went through to find an example. | 13:43 |
ubuntourist | So, let's add to the command: We're going to use the pipe to filter out all files that have zero matches. | 13:43 |
ubuntourist | egrep -cr "^[[:space:]]*#" * | grep -v "\:0$" | 13:44 |
ubuntourist | This 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 | |
kjcole | Oops | 13:46 |
kjcole | Now you should see that "X11/rgb.txt:0" is no longer in the list. | 13:47 |
kjcole | Use Ctrl-R instead of scrolling up and down | 13:48 |
kjcole | Sometimes, if "grep" or "egrep" cannot open a file, or if the file that maches cannot be printed to the screen, | 13:49 |
kjcole | grep 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 right | 13:50 |
kjcole | We could say "send the error to a file instead of the screen" or "send the error to... nowhere" | 13:51 |
kjcole | To send the error to "nowhere" it is "2> /dev/null" | 13:51 |
kjcole | So we're going to ignore errors with: | 13:52 |
kjcole | egrep -cr "^[[:space:]]*#" * 2> /dev/null | grep -v "\:0$" | 13:52 |
kjcole | BUT | 13:52 |
kjcole | BEFORE YOU START TYPING... | 13:52 |
kjcole | We're going to use some of those keyboard shortcuts I've talked about being very important to learn. | 13:52 |
kjcole | so. Up-arrow. Then, escape then b. Repeat ESC b until you are at the * | 13:54 |
kjcole | Well if you're doing Ctrl-R just type "grep" and it should find the last grep | 13:54 |
kjcole | Hmmm... | 13:55 |
kjcole | It should have found it... | 13:55 |
kjcole | Ah, it did. | 13:55 |
*** JulianMolina has quit (Remote host closed the connection) | 13:55 | |
kjcole | But it found my commented one. So, Ctrl-A, and then Ctrl-D, then Ctrl-E, THEN ESC b a few time. | 13:56 |
kjcole | Never mnd. | 13:56 |
kjcole | It looks like you have the whole command there. | 13:56 |
kjcole | Go ahead | 13:57 |
mulbah | okay | 13:57 |
kjcole | The 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 |
kjcole | We're going to add a little mmore to the end... | 13:58 |
kjcole | But before you type it, I will explain the new part: | 13:59 |
kjcole | egrep -cr "^[[:space:]]*#" * 2> /dev/null | grep -v "\:0$" | sort -n -t ":" -k 2 | 13:59 |
kjcole | We are adding a pipe to sort -n -t ":" -k 2 | 14:00 |
mulbah | Mr. Cole what the ":" means | 14:00 |
kjcole | I 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 |
kjcole | When 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 |
kjcole | sometimes you would want to sort by their last name. But maybe sometimes you want to sort by their ages. | 14:02 |
kjcole | So 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 |
kjcole | All of the lines that were printed back to you looked like: | 14:03 |
kjcole | directory/filename:number | 14:03 |
kjcole | directory/filename:number | 14:04 |
kjcole | directory/filename:number | 14:04 |
kjcole | You can see that on your screen now. | 14:04 |
kjcole | The ":" is the "field delimiter" or "field separator" or "field terminator" (they all mean the same thing.) | 14:05 |
kjcole | also, 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 |
kjcole | For 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 |
kjcole | It should instead interpret "8" as "08" and "50" as "50". Now it compares "0" to "5" and says "0 is less". | 14:09 |
kjcole | So... 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 |
kjcole | So, 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 |
kjcole | Go ahead. I need to step away for a bathroom break. | 14:12 |
mulbah | okay | 14:12 |
*** shmohamud has quit (Remote host closed the connection) | 14:12 | |
kjcole | I'm back. So, look at that last number! Wow! | 14:17 |
kjcole | As you know from Python, and from the command line, "#" starts a comment and comments are ignored. | 14:18 |
kjcole | We just found a system administration file with 1,961 liines that are comments! | 14:18 |
kjcole | That's a hell of a lot of comments! | 14:19 |
kjcole | So, take a look at the contents of the file, using most... (You should be able to figure that out for yourself now.) | 14:19 |
kjcole | Nope. 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 | |
kjcole | Maybe explain back to me what you see on the screen | 14:22 |
mulbah | on my terminal | 14:22 |
kjcole | Yes. | 14:23 |
kjcole | (Without typing anything in the terminal, what are you seeing in the terminal window right now?) | 14:24 |
mulbah | I'm seeing a list of files | 14:24 |
kjcole | And? | 14:25 |
kjcole | (I mean, explain the list more.) | 14:25 |
mulbah | I'm not understanding what you means Mr. Cole | 14:28 |
kjcole | OK. 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 |
kjcole | And 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 |
kjcole | First we found files that matched the pattern. | 14:32 |
kjcole | Then we eliminated files with zero matches. | 14:33 |
kjcole | Then we eliminated error messages. | 14:33 |
kjcole | Then we sorted the list, so that the files with the most matches would appear last. | 14:34 |
kjcole | Now 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 |
kjcole | ACTION waits... But only 23 minutes left today... | 14:37 |
ubuntourist | Hello? Still there? | 14:41 |
mulbah | Yeah | 14:41 |
mulbah | trying to understand what you means | 14:41 |
ubuntourist | OK. 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 |
ubuntourist | Do you know what I mean by sorting the list of matching file names? | 14:44 |
mulbah | no | 14:45 |
ubuntourist | ok.... Look at the list right now on the screen and try to remember the last two or three lines. | 14:46 |
ubuntourist | Actually, I'll copy them here: | 14:46 |
ubuntourist | login.defs:274 | 14:46 |
ubuntourist | fail2ban/jail.conf:314 | 14:46 |
ubuntourist | locale.gen:500 | 14:47 |
ubuntourist | postgresql/13/main/postgresql.conf:623 | 14:47 |
ubuntourist | lvm/lvm.conf:1961 | 14:47 |
ubuntourist | Now look at the last few lines... (I removed the sort.) | 14:48 |
ubuntourist | Compare that to the lines that I copied into the IRC above. | 14:49 |
mulbah | they are different | 14:50 |
ubuntourist | Can 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 |
ubuntourist | Only 7 minutes left... | 14:54 |
ubuntourist | OK... 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 |
ubuntourist | Refer back to the log, and to your "history" command. | 14:58 |
mulbah | okay Mr. Cole | 14:58 |
ubuntourist | Once 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 |
mulbah | Thanks for today Mr. Cole I will try to do that | 15:01 |
ubuntourist | Jeff 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 |
ubuntourist | He 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 |
ubuntourist | Bye for now. I will keep an eye open for your e-mail. | 15:04 |
mulbah | okay | 15:04 |
mulbah | Bye | 15: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/!