Latest / CyberSecurity Summary / Linux Command Line and Shell Scripting Bible
Transcript
- 0:00Speaker 1: All right, get ready to dive into the world to
- 0:02Speaker 1: the Linux command line. Yeah, we're going to turn you
- 0:05Speaker 1: into a command line ninja with this twenty twenty one
- 0:09Speaker 1: edition of the Linux command Line and Shell Scripting Bible.
- 0:14Speaker 2: This book, oh wow, the Bible.
- 0:16Speaker 1: Huh, it's a big one.
- 0:17Speaker 2: Yeah.
- 0:18Speaker 1: We've got basic commands, advanced commands. Yeah, we're going to
- 0:21Speaker 1: get into managing files and directories, understanding how the shell
- 0:25Speaker 1: actually works, working with data, and then even getting into
- 0:29Speaker 1: the scripting side of things.
- 0:30Speaker 2: Yeah, this is going to be fun.
- 0:32Speaker 1: So you navigate the file system like a pro, write
- 0:35Speaker 1: some really cool scripts.
- 0:37Speaker 2: I think a good place to start would be just
- 0:39Speaker 2: talking about the different ways that you can even access
- 0:42Speaker 2: the command line.
- 0:43Speaker 1: Okay, yeah, that's a good point. So you've got like
- 0:46Speaker 1: virtual consoles, graphical terminal emulators. That's just like a fancy
- 0:51Speaker 1: way of saying the same thing.
- 0:52Speaker 2: Well, I would say it's important to know the difference
- 0:55Speaker 2: because it affects how you interact with the system. So
- 0:58Speaker 2: when you think about virtual consoles, you want to think
- 1:01Speaker 2: about it's like a direct connection to your system's heart.
- 1:05Speaker 2: It runs right on the system memory. Oh, so it
- 1:08Speaker 2: gives you that old school no frills command line experience. Now,
- 1:12Speaker 2: terminal emulators are like command line windows within your graphical
- 1:16Speaker 2: desktop environment. Okay, they're going to give you more flexibility
- 1:20Speaker 2: and features, but they do have a little bit of
- 1:23Speaker 2: a performance trade off.
- 1:25Speaker 1: Yeah, I guess that makes sense. It has to run
- 1:27Speaker 1: inside of the graphical environment. Okay, So choosing between those
- 1:31Speaker 1: two is like choosing if you're going to be a
- 1:33Speaker 1: survivalist or if you want like the modern conveniences of
- 1:35Speaker 1: the graphical environment. But in both cases you're still using
- 1:40Speaker 1: that command line. So now that we're in the command line,
- 1:43Speaker 1: how do you find your way around? It's not like
- 1:45Speaker 1: Windows with folders and icons and all of that.
- 1:47Speaker 2: That's right. So we've got the Linux file structure. It
- 1:51Speaker 2: is quite a bit different from what you might be
- 1:54Speaker 2: used to, but once you grasp it, it's pretty logical
- 1:58Speaker 2: actually and efficient. Fit like a tree with the root
- 2:01Speaker 2: directory as the trunk. Everything kind of branches out from there.
- 2:05Speaker 1: I see.
- 2:05Speaker 2: And then here's where it gets interesting. Mount points Okay,
- 2:08Speaker 2: you know those are those connectors that let you attach
- 2:10Speaker 2: additional storage devices like hard drives USB drives, Yeah, and
- 2:14Speaker 2: make them appear as part of this unified tree structure.
- 2:17Speaker 1: So no matter where I plug a new device in,
- 2:20Speaker 1: it's going to show.
- 2:21Speaker 2: Up in that one seamlessly integrated.
- 2:23Speaker 1: Okay, it's pretty cool. But with all those directories and files,
- 2:27Speaker 1: how do you it can get.
- 2:29Speaker 2: A little bit daunting. Yeah, especially with those really long
- 2:32Speaker 2: file names that Lennox.
- 2:33Speaker 1: Is known for. Right, yeah, yeah, exactly, exactly.
- 2:36Speaker 2: Yeah. So you've got a master tab completion. Okay, that's
- 2:40Speaker 2: your first step towards being a command line ninja. Right,
- 2:43Speaker 2: just start typing a command or file name, hit the
- 2:46Speaker 2: tab key, and then the shell will just magically complete
- 2:49Speaker 2: it for you. It's going to give you suggestions. It
- 2:51Speaker 2: is a real time saver, right.
- 2:52Speaker 1: Find me up for that. So I've got tab completion.
- 2:56Speaker 1: What other tips?
- 2:57Speaker 2: Okay? So another tip is to look out for those
- 3:00Speaker 2: hidden files.
- 3:01Speaker 1: Okay.
- 3:01Speaker 2: They start with a period, and they're normally invisible, right okay,
- 3:05Speaker 2: and they often contain some pretty important configuration settings or
- 3:09Speaker 2: system data. So if you ever need to delve into
- 3:12Speaker 2: that hidden world, the LSA command is your go to.
- 3:16Speaker 2: It's like putting on X ray vision for the file system.
- 3:19Speaker 1: Oh okay, So I need to be careful not to
- 3:21Speaker 1: delete anything that I can't see them. If it's important, you.
- 3:24Speaker 2: Don't want to accidentally delete something important?
- 3:26Speaker 1: Yeah, yeah, okay, Now let's get into actually managing these files, right,
- 3:31Speaker 1: I mean, what good is a command line if you
- 3:33Speaker 1: can't move, copy, delete these files?
- 3:36Speaker 2: Absolutely, So this book it dives into those essential commands
- 3:40Speaker 2: CEE for copying, m V for moving or renaming, and
- 3:44Speaker 2: then of course we've got the infamous RMM for deleting. Yeah,
- 3:48Speaker 2: but before you go on a deleting spree, we've got
- 3:51Speaker 2: to talk about.
- 3:51Speaker 1: In noodes innodess a little technical.
- 3:53Speaker 2: Yeah, they are a little technical, but they're also very cool.
- 3:56Speaker 2: They're like unique fingerprints for each file. So even if
- 4:00Speaker 2: you change a file's name or move it, it's in
- 4:03Speaker 2: a number stays the same.
- 4:04Speaker 1: So it's not just about the name, that's right, it's
- 4:07Speaker 1: an underlying identifier. Okay, So imagine if you need to
- 4:10Speaker 1: find a file that's been moved or renamed. In odes
- 4:13Speaker 1: are your secret weapon. I see, Yeah, you can find
- 4:15Speaker 1: that file no matter where it is. Wow.
- 4:17Speaker 2: Okay, yeah, Now what about dealing with the output of commands?
- 4:22Speaker 2: Sometimes you get this massive wall.
- 4:24Speaker 1: Of text that's right scrolling by.
- 4:26Speaker 2: Is there a way to kind of capture that information?
- 4:28Speaker 1: Yes, So that's where we've got output redirection. Okay, this
- 4:32Speaker 1: is one of those aha moments. Once you learn how
- 4:34Speaker 1: to use it. The symbol is your friend here. Okay,
- 4:38Speaker 1: you can readirect the output of a command to a file,
- 4:41Speaker 1: so instead of seeing it on the screen, you can
- 4:44Speaker 1: capture it, put it in a file, and use it
- 4:47Speaker 1: later for analysis or reference. Oh that's so useful. Yeah,
- 4:51Speaker 1: instead of it just flying by on the screen.
- 4:53Speaker 2: Yeah, just capture it.
- 4:54Speaker 1: You can actually. Yeah, okay, brilliant.
- 4:55Speaker 2: Yeah, it's a good one.
- 4:56Speaker 1: Now we keep hearing the word shell. Exactly is a shell?
- 5:00Speaker 2: Ah? Yes, the shell?
- 5:02Speaker 1: And why should I care about it?
- 5:03Speaker 2: The shell? So think about this. This is your command
- 5:05Speaker 2: line interpreter, the bridge between you and the Linux kernel,
- 5:10Speaker 2: which is the heart of the operating system. Right, So
- 5:12Speaker 2: it's taking your commands, figuring out what you mean, and
- 5:15Speaker 2: then it instructs the kernel to make it happen.
- 5:18Speaker 1: Gotcha.
- 5:18Speaker 2: And there's not just one shell. There's several.
- 5:21Speaker 1: Oh interesting, So I don't have to just use one shell.
- 5:24Speaker 2: No, And this book delves into the different types of shells,
- 5:27Speaker 2: like the very popular beast shell off in the default,
- 5:31Speaker 2: and then you have alternatives like TS and DASH.
- 5:35Speaker 1: Wow. Okay, so there's each one has its choices.
- 5:38Speaker 2: Yeah, they each have their own personality, their own quirks strengths.
- 5:42Speaker 1: So it's like choosing your weapon, choosing your.
- 5:44Speaker 2: Exactly which one fits your style and needs.
- 5:47Speaker 1: Now, every time I hit enter, it creates a child process.
- 5:51Speaker 2: That's right, a child process to handle that command.
- 5:54Speaker 1: So there's a whole family going on every time I
- 5:56Speaker 1: hit a key.
- 5:57Speaker 2: It's like a parent shell gives both to it childs
- 6:00Speaker 2: shell to kind of carry out your instructions.
- 6:02Speaker 1: I see. Okay. And then they also mentioned subshells are
- 6:05Speaker 1: subshells like the rebellious teenager of the shell world.
- 6:08Speaker 2: Huh.
- 6:09Speaker 1: I like that.
- 6:10Speaker 2: Yeah, kind of subshells are temporary shells created within your
- 6:15Speaker 2: main shell. Okay, So think of it as a sandbox
- 6:19Speaker 2: where you can play around commands and environment variables without
- 6:22Speaker 2: really affecting your main shell.
- 6:24Speaker 1: So if I mess up in the subshell, it doesn't
- 6:26Speaker 1: blow up my main shell exactly.
- 6:28Speaker 2: That's the beauty of it. What happens in the subshell
- 6:30Speaker 2: stays in the subshell.
- 6:31Speaker 1: Okay, I like that. Yeah, all right, now let's talk
- 6:33Speaker 1: about environment variables.
- 6:34Speaker 2: Hmmm.
- 6:36Speaker 1: That sounds a little bit intimidating.
- 6:38Speaker 2: I know, I know they can be. Yeah, but think
- 6:40Speaker 2: about like this. They're the settings that control how your
- 6:45Speaker 2: shell and other programs behave. So it's like a behind
- 6:48Speaker 2: the scenes control panel for your system.
- 6:50Speaker 1: I see.
- 6:51Speaker 2: Now you have global environment variables those apply system wide, okay,
- 6:56Speaker 2: and then you have local ones, which are specific to
- 6:59Speaker 2: your current shell session.
- 7:01Speaker 1: So global or like the laws of the Lenox universe,
- 7:04Speaker 1: and local are like my own personal preference.
- 7:06Speaker 2: There you go. Okay, that's a great way to put it.
- 7:08Speaker 1: Now. The book mentions these VIP environment variables. Yes, like path, home, shell, term.
- 7:18Speaker 2: It's a path.
- 7:18Speaker 1: Yeah, where are those?
- 7:19Speaker 2: So? Path that tells the shell where to look for
- 7:22Speaker 2: executable commands. Okay, so it's like a roadmap guiding the
- 7:26Speaker 2: shell to find those tools.
- 7:27Speaker 1: Gotcha.
- 7:28Speaker 2: And then home that points to your home directory, your
- 7:32Speaker 2: personal space within that file system. Shell specifies which shell
- 7:37Speaker 2: you're using, and then term defines your terminal type okay,
- 7:41Speaker 2: so that programs understand how to display information properly.
- 7:44Speaker 1: So these variables are kind of like setting the stage
- 7:46Speaker 1: for how everything's going to do.
- 7:48Speaker 2: That's right, how everything is going to run okay. Yeah,
- 7:50Speaker 2: and then you've got commands like set envy and print him.
- 7:55Speaker 2: Those are going to be your tools for viewing and
- 7:57Speaker 2: manipulating these environment variables.
- 8:00Speaker 1: So we can actually modify these settings totally customize our environments. Yep.
- 8:04Speaker 1: All right, Now we need to talk about these shell
- 8:06Speaker 1: startup files okay, before we get too far into the
- 8:09Speaker 1: scripting side.
- 8:10Speaker 2: Right, So these are those secret ingredients that make your
- 8:13Speaker 2: shell experience really personalized. Okay, So shell startup files like
- 8:19Speaker 2: et cetera profile, dot bash profile, dot bash rc. There're
- 8:24Speaker 2: scripts that run every time you log in or start
- 8:26Speaker 2: a new shell session.
- 8:27Speaker 1: So it's like a set of instructions for how the
- 8:29Speaker 1: shell's going.
- 8:29Speaker 2: To exactly how it's going to set up. Okay, you
- 8:31Speaker 2: know you can customize your command prompt, set environment variables,
- 8:35Speaker 2: define aliases for those frequently used commands. Wow.
- 8:38Speaker 1: So it's like my own little personal exactly. It's like
- 8:40Speaker 1: your assistant.
- 8:41Speaker 2: It's like having a personal assistant just for your shell,
- 8:44Speaker 2: taking care of all the yeah, taking care of all
- 8:46Speaker 2: the tedious stuff so you can focus on the fun stuff.
- 8:48Speaker 1: Okay, So now we've got our environments set up, it's
- 8:51Speaker 1: time to write a shell script.
- 8:52Speaker 2: All right? Are you ready?
- 8:53Speaker 1: Yeah? How do we bring these shell scripts to life?
- 8:57Speaker 2: All right? So first thing you want to do is
- 9:00Speaker 2: you want to create a simple text file. Okay, you're
- 9:03Speaker 2: going to write your commands in plain text, just like
- 9:06Speaker 2: you would type them at the command line, right, and
- 9:08Speaker 2: then you need to make that script executable using the
- 9:11Speaker 2: chron command.
- 9:13Speaker 1: So we're giving it permission to do its things.
- 9:15Speaker 2: Exactly, you're giving it permission to do its thing. You're
- 9:18Speaker 2: changing the file permissions and telling the system, hey, this
- 9:20Speaker 2: is a program. This can be executed.
- 9:23Speaker 1: Gotcha. So what kind of commands can we put inside
- 9:26Speaker 1: of these scripts?
- 9:27Speaker 2: So you've got the Echo command. That's your basic communication tool.
- 9:31Speaker 1: Okay.
- 9:31Speaker 2: You can display messages on the screen, so it's good
- 9:34Speaker 2: for providing feedback or debugging your script.
- 9:38Speaker 1: So if I wanted to say Hello World, I could
- 9:41Speaker 1: do that with Echo.
- 9:42Speaker 2: You got it. Echo is your friend?
- 9:44Speaker 1: All right? What about making these scripts a little more dynamic,
- 9:48Speaker 1: like working with data?
- 9:49Speaker 2: Ah? Okay, so we're going to bring in variables.
- 9:51Speaker 1: Okay.
- 9:52Speaker 2: Variables are like containers that hold data within your script.
- 9:56Speaker 2: So think of them as like labeled boxes store information
- 10:01Speaker 2: and then refer to that information by that label or
- 10:05Speaker 2: variable name.
- 10:06Speaker 1: So it's like giving the script a memory.
- 10:08Speaker 2: Then you got it. You're giving it a memory. And
- 10:10Speaker 2: this book shows you how to assign values to those variables,
- 10:16Speaker 2: and then use those values within your script. It even
- 10:19Speaker 2: shows you how to capture the output of a command
- 10:22Speaker 2: and store that in a variable.
- 10:24Speaker 1: Really yeah, so I could run a command and then
- 10:27Speaker 1: take that output and use it somewhere else.
- 10:29Speaker 2: And feed it into your script. Yeah.
- 10:31Speaker 1: That's awesome.
- 10:32Speaker 2: Yeah, that's a good one.
- 10:33Speaker 1: So how do you do that?
- 10:34Speaker 2: So there's a couple of ways to do it. One
- 10:36Speaker 2: is using backticks. That's the older syntax okay, and then
- 10:39Speaker 2: you've got the newer syntax for command substitution.
- 10:42Speaker 1: Okay.
- 10:42Speaker 2: Both achieve the same goal. They're capturing the output of
- 10:46Speaker 2: that command to data stream and then you can feed
- 10:49Speaker 2: that into your script, so I.
- 10:50Speaker 1: Can build mini pipelines right inside my script. That's right. Wow, yeah,
- 10:54Speaker 1: pretty cool? Right, this is really cool. Yeah.
- 10:56Speaker 2: So we've covered the foundations of shell scripting here, but
- 10:59Speaker 2: there's so much more to explore.
- 11:01Speaker 1: I'm ready. What's coming up next?
- 11:03Speaker 2: Okay? Well, next we're going to dive into more advanced
- 11:05Speaker 2: scripting techniques like conditional statements and loops. Those allow your
- 11:09Speaker 2: scripts to make decisions and repeat actions.
- 11:12Speaker 1: Okay, cool, let's get into it all right, So.
- 11:14Speaker 2: Are you ready to go beyond those scripting basics and
- 11:17Speaker 2: give those scripts some intelligence.
- 11:19Speaker 1: I'm ready.
- 11:19Speaker 2: How do we do that with conditional statements and loops?
- 11:22Speaker 1: Ooh that sounds interesting.
- 11:24Speaker 2: Yeah, they're really cool. It's like adding a brain to
- 11:27Speaker 2: your script so they can adapt to different situations and
- 11:30Speaker 2: automate those tedious, repetitive tasks. Right.
- 11:33Speaker 1: Oh yeah, yeah, okay, so let's start with conditional statements.
- 11:36Speaker 1: How do those work? It kind of sounds like teaching
- 11:38Speaker 1: the script to think.
- 11:39Speaker 2: Yeah, it's kind of like that the if then statement. Okay,
- 11:42Speaker 2: it's your building block for decision making. You know. Think
- 11:45Speaker 2: of it like a gatekeeper evaluating a condition and only
- 11:49Speaker 2: letting those commands through if the condition is true.
- 11:52Speaker 1: So it's like saying, hey, script, if this is true,
- 11:55Speaker 1: then do that. If not, skip it, that's right. Okay,
- 11:59Speaker 1: what kind of condition can we actually put in there?
- 12:01Speaker 2: Well? Remember those exit status codes. You know, the command
- 12:04Speaker 2: typically exists with the status of zero if it's successful,
- 12:07Speaker 2: or a non zero status if there's an error. Right, right, Well,
- 12:11Speaker 2: conditional statements use those statuses to make decisions.
- 12:13Speaker 1: Oh okay, so the command is actually reporting back to
- 12:16Speaker 1: the script saying hey I did it, or hey I
- 12:19Speaker 1: had a problem that's right. You decide what to do
- 12:21Speaker 1: next exactly.
- 12:22Speaker 2: So in an if then statement, if that preceding command
- 12:26Speaker 2: exits with a zero, the commands in the then block
- 12:30Speaker 2: get executed. Otherwise they get skipped.
- 12:32Speaker 1: Okay, So what if you want to have an alternative
- 12:34Speaker 1: like run these commands if it's true, but if not,
- 12:38Speaker 1: then do something else.
- 12:39Speaker 2: Ah, so you want a backup plan?
- 12:40Speaker 1: Yeah, exactly.
- 12:41Speaker 2: Well that's where if then else comes in. It's giving
- 12:44Speaker 2: your scripts two possible paths. Okay, one for when the
- 12:47Speaker 2: condition is true and one for when it's false.
- 12:50Speaker 1: I like having options. You got it now. I also
- 12:52Speaker 1: see nested if statements. Yes, are those like nsted if statements?
- 12:59Speaker 1: Those rush yes exactly, like those Russian nesting dolls with
- 13:03Speaker 1: one if statement inside of another. Okay, So that allows
- 13:07Speaker 1: you to create more complex decision making logic. You know,
- 13:11Speaker 1: it's like creating a multi level decision tree.
- 13:13Speaker 2: So it's like adding layers of intelligence to that script.
- 13:16Speaker 1: That's right.
- 13:17Speaker 2: It can evaluate more sophisticated scenarios.
- 13:19Speaker 1: Exactly.
- 13:20Speaker 2: Wow. Okay, now we need to talk about loops.
- 13:23Speaker 1: Okay, So loops for those repetitive tasks exactly. Loops are
- 13:27Speaker 1: the workhorses of automation. Okay, the book covers several types
- 13:31Speaker 1: of loops, for loops and wild loops.
- 13:33Speaker 2: You know, imagine if you had to process one hundred files,
- 13:36Speaker 2: or maybe you're waiting for a specific condition to change. Yeah,
- 13:40Speaker 2: you know loops. Let you handle those situations without writing
- 13:43Speaker 2: the same commands over and over again.
- 13:45Speaker 1: Okay, yeah, I can see where that would get really tedious.
- 13:47Speaker 2: Yeah, I would get really tedious.
- 13:48Speaker 1: Okay, let's start with the four loop.
- 13:50Speaker 2: All right. So the four loop.
- 13:51Speaker 1: How does that one work?
- 13:52Speaker 2: It's design to iterate through a list of values, okay,
- 13:56Speaker 2: and execute a set of commands for each value. It's
- 13:59Speaker 2: like a processing You take each item from that list,
- 14:02Speaker 2: you run it through the same set of instructions.
- 14:05Speaker 1: Gotcha. So if I had a list of file names,
- 14:07Speaker 1: I could run the same action on all those files exactly.
- 14:10Speaker 1: That's pretty cool. What about the wile loop?
- 14:12Speaker 2: All right? So the wile loop?
- 14:13Speaker 1: Why would I use that one?
- 14:14Speaker 2: So the wile loop is like this persistent little engine. Okay,
- 14:18Speaker 2: It keeps running as long as a specific condition remains true. Okay,
- 14:23Speaker 2: So it's perfect for situations where you don't know in
- 14:26Speaker 2: advance how many times you need to repeat those commands.
- 14:29Speaker 2: So imagine you're monitoring a system log file okay, and
- 14:33Speaker 2: you're waiting for a specific error message to appear. Yeah,
- 14:38Speaker 2: a while loop can keep checking that file, oh okay
- 14:41Speaker 2: until that message pops out.
- 14:43Speaker 1: Yeah, so it's just constantly checking and checking.
- 14:45Speaker 2: Until exactly continually monitoring.
- 14:47Speaker 1: Okay. What if I need to bail out of a
- 14:50Speaker 1: loop early?
- 14:51Speaker 2: Ah, well, we've got the brake command for that.
- 14:55Speaker 1: Okay.
- 14:55Speaker 2: You know, that's your emergency exit for loops. So if
- 14:59Speaker 2: a certain condition is met within that loop, yeah, break,
- 15:03Speaker 2: we'll stop it right there, preventing any further iteration, like.
- 15:06Speaker 1: The loop stopping Superhero.
- 15:08Speaker 2: That's right, that's right. So what about skipping over certain
- 15:11Speaker 2: iterations of a loop?
- 15:12Speaker 1: Oh? Yeah? What if I want to just process certain
- 15:14Speaker 1: files like that meet certain criteria.
- 15:16Speaker 2: Well, for that, you have the continued command OKA that
- 15:19Speaker 2: lets you jump to the next iteration of the loop
- 15:22Speaker 2: without executing those remaining commands.
- 15:25Speaker 1: It's like, nope, not that one, move on to the
- 15:26Speaker 1: next exactly exactly. Okay. These loop control commands are really cool.
- 15:31Speaker 1: So I've got conditional statements for decision making, we've got
- 15:34Speaker 1: loops for repeating actions. What else can we do to
- 15:37Speaker 1: make our scripts a little more interactive and powerful.
- 15:40Speaker 2: Well, how about giving them the ability to take constructions
- 15:44Speaker 2: directly from the user? Oh okay, you know with command
- 15:47Speaker 2: line parameters.
- 15:47Speaker 1: Okay, so like giving it instructions or settings when I
- 15:50Speaker 1: start the.
- 15:51Speaker 2: Script exactly exactly. You know, you pass information to the
- 15:55Speaker 2: script when you run it, customize its behavior on the fly.
- 15:58Speaker 1: Okay.
- 15:59Speaker 2: Within the script, you access those parameters using special variables
- 16:03Speaker 2: like one dollar, two dollars, and so on. One dollars
- 16:06Speaker 2: is the first parameter, two dollars is the second.
- 16:08Speaker 1: Okay, that's pretty straightforward. What if I've got a script
- 16:11Speaker 1: that takes a bunch of parameters, Well, you know, the.
- 16:14Speaker 2: Book explains special variables like hashtag that gives you the
- 16:17Speaker 2: total number of parameters past ok and then you have
- 16:20Speaker 2: at which lets you access all of them as a
- 16:22Speaker 2: single unit.
- 16:23Speaker 1: Gotcha.
- 16:24Speaker 2: And then there's even a clever trick to access the
- 16:27Speaker 2: very last parameter using ash.
- 16:29Speaker 1: Wow. It's pretty handy.
- 16:31Speaker 2: Yeah, it's pretty handy. So how about those single letter
- 16:33Speaker 2: command line options, right, you know, like L for the long.
- 16:37Speaker 1: Listing with l's Yeah, yeah, exactly.
- 16:40Speaker 2: You can use those in your scripts too.
- 16:41Speaker 1: Really.
- 16:42Speaker 2: Yeah, So the book outlines three ways to handle those options, okay,
- 16:45Speaker 2: so you can process them directly as parameters. You can
- 16:48Speaker 2: use if statements to check for specific options, or the
- 16:52Speaker 2: most elegant approach is to use the get tops command
- 16:56Speaker 2: get tops get tops. You know that's your built in
- 16:59Speaker 2: option parsing wizard.
- 17:00Speaker 1: Oh wow.
- 17:01Speaker 2: It handles both short and long options, whether they have
- 17:04Speaker 2: associated values or not.
- 17:05Speaker 1: Wow.
- 17:06Speaker 2: And you can even specify which options are expected.
- 17:09Speaker 1: So it's kind of streamlining all that option handling exactly.
- 17:11Speaker 2: It streamlines it and makes it more robust.
- 17:13Speaker 1: Okay, very cool. So we've got conditional statements, loops, we've
- 17:17Speaker 1: got these command line parameters and options. Anything else we
- 17:21Speaker 1: can do well.
- 17:22Speaker 2: One of the most powerful techniques is to encapsulate those
- 17:25Speaker 2: reusable code blocks into functions.
- 17:29Speaker 1: Functions okay, yeah, functions in programming.
- 17:31Speaker 2: Yeah, just like in programming. They are like mini scripts
- 17:34Speaker 2: within your main script. They help you avoid repetition and
- 17:37Speaker 2: make it way more readable and maintainable. Okay, it's like
- 17:41Speaker 2: building your own custom command library.
- 17:43Speaker 1: Oh that's cool. So I can create my own commands,
- 17:46Speaker 1: that's right.
- 17:46Speaker 2: And the book walks you through defining those functions, okay,
- 17:50Speaker 2: giving them names, calling them. When you need that specific functionality,
- 17:54Speaker 2: you can even pass arguments to functions, just like you
- 17:57Speaker 2: do with regular commands.
- 17:59Speaker 1: So it's like building as some toolbox of all these
- 18:01Speaker 1: components exactly all right, Now the book mentions this local keyword. Yes,
- 18:05Speaker 1: what is local all about?
- 18:08Speaker 2: So local is your friend when it comes to keeping
- 18:11Speaker 2: variables organized within those functions. It lets you declare variables
- 18:16Speaker 2: that are only visible inside that function. Okay, prevents naming
- 18:20Speaker 2: conflicts with variables in your main scriptstcha, you know, other functions.
- 18:25Speaker 2: It's good practice to use local variables within functions to
- 18:29Speaker 2: keep things nice and tidy.
- 18:31Speaker 1: Okay. So it's like giving each function its own little workspace.
- 18:34Speaker 2: That's right, its own little private.
- 18:35Speaker 1: Workspace prevents them from interfering with each other exactly. Okay. Now,
- 18:40Speaker 1: Linux has a ton of commands and utilities built in.
- 18:44Speaker 1: Are there any external tools? Yes, that can help us
- 18:47Speaker 1: with scripting.
- 18:48Speaker 2: So there is a package called stool Okay, you know,
- 18:51Speaker 2: think of that like your Swiss army knife for scripting.
- 18:54Speaker 1: Right.
- 18:54Speaker 2: It provides a collection of pre built functions for all
- 18:57Speaker 2: sorts of common tasks, from platform to detection, text manipulation,
- 19:02Speaker 2: interactive prompts.
- 19:04Speaker 1: So it's like having a whole team of expert scriptwriters
- 19:07Speaker 1: at my disposal.
- 19:08Speaker 2: That's right. That's right.
- 19:09Speaker 1: That's really cool. So I can use those functions both
- 19:11Speaker 1: from the command line and within my scripts.
- 19:13Speaker 2: That's right. Gives you a lot of flexibility.
- 19:15Speaker 1: Wow. Okay, we've covered a lot we have. We've covered
- 19:19Speaker 1: advanced scripting techniques, We've looked at external tools. One thing
- 19:23Speaker 1: we haven't talked about, though, is how do you actually
- 19:25Speaker 1: write these scripts? Ah?
- 19:28Speaker 2: Yes, so what tools are we actually using?
- 19:31Speaker 1: Yeah? Are we just using a plain text editor? Is
- 19:34Speaker 1: there anything more specialized?
- 19:36Speaker 2: Yeah? So choosing the right text editor can really boost
- 19:39Speaker 2: that scripting productivity.
- 19:41Speaker 1: Okay.
- 19:41Speaker 2: The book dedicates a whole chapter to exploring various text
- 19:45Speaker 2: editors like Vim, Emacs, Nano, k Write, Kate, get it.
- 19:50Speaker 1: Wow. That's a lot.
- 19:52Speaker 2: Yeah, quite a lineup, right.
- 19:54Speaker 1: Are there any standouts? What would you recommend for someone
- 19:57Speaker 1: just starting out?
- 19:59Speaker 2: Well, really depends on personal preference, learning style.
- 20:03Speaker 1: You know.
- 20:04Speaker 2: Vim is renowned for its power and efficiency, but it
- 20:07Speaker 2: does have a steep learning curve.
- 20:09Speaker 1: I've heard it's a blessing and a curse.
- 20:11Speaker 2: Yeah, that's a good way to put it. You know.
- 20:13Speaker 2: Emacs is another powerhouse known for its extensibility and customizability,
- 20:18Speaker 2: but it also has a learning curve.
- 20:19Speaker 1: Okay.
- 20:20Speaker 2: Nano is a more simple, user friendly editor, good for
- 20:23Speaker 2: quick edits, Okay, might be good for beginners.
- 20:26Speaker 1: So there's kind of an editor for everyone's right, every taste?
- 20:30Speaker 2: Yeah, for every taste.
- 20:31Speaker 1: Now, what about those graphical editors like k write and
- 20:35Speaker 1: kate and get it.
- 20:37Speaker 2: So those offer a more visual and intuitive editing experience. Okay,
- 20:43Speaker 2: you know they features like syntax highlighting, autocompletion, even built
- 20:47Speaker 2: in terminal emulators, which can be super helpful for testing
- 20:50Speaker 2: your scripts as you write them.
- 20:52Speaker 1: Oh okay, Yeah, so we've got our scripting environment set up. Okay,
- 20:55Speaker 1: we've learned how to write scripts, make them interactive, automate tasks,
- 20:59Speaker 1: and even organize our code with functions. That's right. What
- 21:02Speaker 1: else is there? What other powerful techniques are out there?
- 21:05Speaker 2: Well? Next app will delve into the world of data
- 21:07Speaker 2: manipulation and unlock those secrets of Said and Gok and
- 21:11Speaker 2: discover the power of regular expressions.
- 21:14Speaker 1: Set in gowk. Those sound like characters from a sci
- 21:17Speaker 1: fi movie.
- 21:18Speaker 2: Ah, yeah, they do.
- 21:19Speaker 1: What are we getting into?
- 21:20Speaker 2: Don't worry, They're not as intimidating as they sound. Okay,
- 21:22Speaker 2: you know Said and Gok are powerful text processing tools
- 21:25Speaker 2: that can transform, filter, and analyze data with incredible speed
- 21:31Speaker 2: and precision.
- 21:32Speaker 1: All right, I'm ready to hear more about these SET
- 21:34Speaker 1: and GOCK tools. So these SET and GOCK tools tell
- 21:38Speaker 1: me more.
- 21:39Speaker 2: Yeah. So SAID stands for stream editor, okay, and it's
- 21:42Speaker 2: all about working on streams of text, processing data line
- 21:46Speaker 2: by line. So imagine you have a massive log file
- 21:50Speaker 2: or a databased stump. Instead of loading the whole thing
- 21:53Speaker 2: into memory, right, said, lets you process it efficiently one
- 21:57Speaker 2: line at a time.
- 21:58Speaker 1: Oh okay.
- 21:58Speaker 2: You can make changes, you can extract information, even transform
- 22:02Speaker 2: the entire structure.
- 22:04Speaker 1: It's like a specialized assembly line for text. Exactly each
- 22:07Speaker 1: line is going through getting modified.
- 22:09Speaker 2: That's right.
- 22:09Speaker 1: Okay.
- 22:10Speaker 2: And one of the keys to Said's power is using
- 22:13Speaker 2: regular expressions.
- 22:15Speaker 1: Yeah, regular expressions.
- 22:16Speaker 2: You know, they might seem a bit cryptic at first.
- 22:18Speaker 1: Yeah, they can be a little intimidating.
- 22:20Speaker 2: Yeah, I know. But they're like a secret language for
- 22:22Speaker 2: pattern matching. Okay, you can specify some really complex search criteria.
- 22:26Speaker 1: I've seen them used, but I've never really understood how
- 22:29Speaker 1: they work.
- 22:30Speaker 2: Yeah, I understand. So the book it breaks them down
- 22:33Speaker 2: into manageable pieces, explaining like those anchor characters, character classes, quantifiers,
- 22:39Speaker 2: and even how to combine these to create really specific
- 22:42Speaker 2: matching rules.
- 22:44Speaker 1: So it's like learning a new language for working with data.
- 22:47Speaker 2: That's a great way to put it.
- 22:48Speaker 1: Okay, can you give me example of how said and
- 22:51Speaker 1: regular expressions actually work together.
- 22:54Speaker 2: Sure. Let's say you have a file with a list
- 22:56Speaker 2: of names. Okay, each one's on a separate line, like
- 22:59Speaker 2: John Smith, Jane Do, and so on, and you want
- 23:02Speaker 2: to just extract the last names from those lines. Okay, Well,
- 23:06Speaker 2: with said and a simple regular expression, you can do
- 23:09Speaker 2: that instantly. Oh wow, The regular expression would target the
- 23:12Speaker 2: space between the first and last name. Oky, Intel said
- 23:15Speaker 2: to only output the part of the line after the space.
- 23:19Speaker 1: Wow. Okay, yeah, so that's said. What about gok How
- 23:23Speaker 1: is that different? So?
- 23:24Speaker 2: Gawk is another powerhouse, but it's more like a programming
- 23:27Speaker 2: language specifically designed for data manipulation, so it goes beyond
- 23:31Speaker 2: that simple text manipulation. Allows you to perform calculations, use variables,
- 23:37Speaker 2: even structure your code with conditional statements and loops, just
- 23:42Speaker 2: like you would in a traditional programming language.
- 23:44Speaker 1: It's like having a mini programming environment.
- 23:46Speaker 2: Yeah, that's a great way to put it.
- 23:47Speaker 1: Specifically designed for working with data exactly.
- 23:51Speaker 2: And it's great for tasks like extracting specific fields from
- 23:54Speaker 2: a file okay, cleaning up MESSI data, generating reports, even
- 23:59Speaker 2: performing base statistical analysis.
- 24:01Speaker 1: So GAWK is definitely something I need to learn more about.
- 24:04Speaker 2: Yeah, it's a good one. And it also uses regular
- 24:06Speaker 2: expressions for pattern matching just like I said, but GAWK
- 24:10Speaker 2: offers some additional features and flexibility. What well, you can
- 24:14Speaker 2: use variables within your regular expressions, making them even more dynamic.
- 24:18Speaker 1: It's like a turbocharged regular expression engine it is.
- 24:21Speaker 2: Yeah, and it also has a rich set of built
- 24:24Speaker 2: in functions for working with strings, arrays, okay, mathematical operations.
- 24:29Speaker 1: There's so much power in the command line.
- 24:31Speaker 2: Yeah, it's really amazing all the things you can do.
- 24:34Speaker 1: It's really making me think differently about what's possible.
- 24:37Speaker 2: That's right. Now.
- 24:37Speaker 1: We talked about the Bash shell earlier, but there are
- 24:40Speaker 1: some alternative shells that we could use too.
- 24:42Speaker 2: Right, yes, yes, So each shell has its own philosophy,
- 24:46Speaker 2: features and little quirks. Okay, So this book talks about
- 24:49Speaker 2: the dash shell. It's a lightweight alternative to Bash, often
- 24:55Speaker 2: the default shell in Debian based distributions like a Buntu
- 25:00Speaker 2: because it's so efficient, but it might not have all
- 25:02Speaker 2: those advanced features.
- 25:04Speaker 1: So it's kind of like if Bash is a Swiss
- 25:06Speaker 1: army knife, Dash is like a simple pocket knife.
- 25:09Speaker 2: There you go, that's a great way to put it.
- 25:11Speaker 1: Just gets the job done.
- 25:12Speaker 2: That's right.
- 25:12Speaker 1: Now, what about this shell?
- 25:14Speaker 2: Ah, you know, that's like the luxury Sedan of shells, okay,
- 25:18Speaker 2: known for its power customization features like plug and support
- 25:23Speaker 2: advanced command line editing.
- 25:25Speaker 1: So it's for power users who really want to customize
- 25:27Speaker 1: everything exactly. Wow.
- 25:28Speaker 2: Yeah. So the book does a great job of highlighting
- 25:31Speaker 2: the strength and weaknesses of each shell, helps you choose
- 25:35Speaker 2: the best one for your needs.
- 25:37Speaker 1: So we've covered file management, shell scripting, data manipulation, even
- 25:41Speaker 1: alternative shells. Is there anything else in this book that
- 25:44Speaker 1: we need to know?
- 25:45Speaker 2: Well, there's one more essential aspect of scripting, especially when
- 25:48Speaker 2: collaborating or working on complex projects, and that's version control.
- 25:53Speaker 1: Version control.
- 25:54Speaker 2: Yeah, version control.
- 25:55Speaker 1: I've heard that.
- 25:56Speaker 2: Yeah. It's super important for scripts, okay, just like it
- 25:58Speaker 2: is for code. It helps you keep track of changes
- 26:01Speaker 2: to your scripts okay, allows you to revert to previous versions,
- 26:05Speaker 2: compare different versions, even merge changes from multiple people.
- 26:09Speaker 1: So it's like a time machine for your scripts exactly.
- 26:12Speaker 2: So, GET is the most popular version control system out there,
- 26:16Speaker 2: and the book gives a great overview of those core concepts. Repositories, commits, branches, Okay,
- 26:22Speaker 2: the importance of using a remote repository.
- 26:25Speaker 1: For backup, so if I met something up, I can
- 26:27Speaker 1: always go back. Wow. This has been an incredible journey
- 26:30Speaker 1: into the world of the Linux command line.
- 26:32Speaker 2: It has.
- 26:33Speaker 1: We went from the basics all the way to Wow,
- 26:36Speaker 1: some really advanced stuff he did. What really stood out
- 26:39Speaker 1: to me was the versatility and power of the command line.
- 26:42Speaker 2: Yeah, for sure.
- 26:43Speaker 1: It's not just about typing in commands. It's about understanding
- 26:45Speaker 1: how the system works, that's right, and being able to
- 26:48Speaker 1: create your own tools and automate tasks.
- 26:50Speaker 2: It really is about taking control of your computing environment.
- 26:54Speaker 1: Yeah, making it work for you exactly. So for everyone
- 26:57Speaker 1: listening out there, how can you use these tools and
- 27:00Speaker 1: scripting skills to automate tasks in your own work or
- 27:03Speaker 1: personal life.
- 27:04Speaker 2: Yeah, that's the real challenge, right, and the real fun.
- 27:07Speaker 2: It's about taking these skills and applying them to those
- 27:10Speaker 2: real world problems.
- 27:11Speaker 1: What repetitive tasks can you eliminate?
- 27:14Speaker 2: That's right?
- 27:14Speaker 1: What data can you process more efficiently? What tools can
- 27:17Speaker 1: you create to make your life easier?
- 27:19Speaker 2: Exactly?
- 27:20Speaker 1: This has been a great deep dive. Remember, mastering the
- 27:23Speaker 1: panline is a journey. Keep experimenting, keep learning, keep pushing
- 27:27Speaker 1: those boundaries, and you'll be amazed at what you can achieve.
- 27:30Speaker 2: And who knows, maybe one day you'll even teach your
- 27:32Speaker 2: computer to dance. All right, thanks for joining us, Thanks
- 27:36Speaker 2: for having me, Mack