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