Episode 1 echo "Hello!"
Welcome to Command Line TV, a new video podcast to help you learn and master
the UNIX shell. In this first episode, we talk about our backgrounds, the scope
of this endeavor, opening your terminal, and using basic commands like cd
and
ls
to explore a directory tree.
You can follow along using the same directory structure by downloading it from https://github.com/commandlinetv/sample-files.
Note: we have a few minor problems in this first episode with audio synchronization and a somewhat noisy environment. It gets better in future episodes!
28 July 2015
•
[Rhythmic, dark electronic intro music] | |
League |
•
Welcome to Command Line TV. •This is a video podcast designed to help you learn the Unix Shell. •I’m Chris League. I am a professor of computer science at LIU Brooklyn. •And with me is my co-host Christian Lopes. Tell us a little about yourself. |
Lopes |
•
My name is Christian Lopes. •I’m currently an undergraduate at LIU Brooklyn studying computer science. •I’ve always been interested in computers and tinkering with things. •So I will be learning along with our viewers today. |
League |
•
Great! Let’s begin by discussing the scope of what we’re going to do here. •We’re going to learn about shell commands available on Linux and Mac OS X. •Not so much the Windows command prompt. A little bit about my technological biases. •and where I’m coming from. I have been a full time Unix user since the early 90’s. •I have used Linux quite a bit since then, and also part time on Mac OS X. •What’s your background with tech? |
Lopes |
•
My background is primarily with Windows, I did start using Ubuntu Linux on a spare laptop. •I know that we use shell commands and a lot of programming commands so, •I’d like to understand more about how they work. |
League |
•
Great! That’s what we’ll be doing. |
Lopes |
•
My first question will be, why would you use a Linux terminal as opposed to a desktop environment. |
League |
•
Yeah, it’s kind of unusual, these days to stick to a command terminal. •It’s not the easiest thing to learn, but it gives you a lot of flexibility, power, and precision. •So, any commands that you type on a command line can be almost as easily scripted and automated, •So that you can take your work flow and automate a lot of things. •Which I think is a really great way to work. •Also, when you control things from the command line it can be configured endlessly •And adapted to the way that you like to work. Desktop environments and graphical applications •Are often called “WYSIWYG”. Which is, uhh, What You See Is What You Get, •And that’s a positive to some extent because, you know, when you’re dealing with a graphical program, •You want to see what you’re producing. But another way of thinking of that is •What You See Is All You’ve Got, and so the power of those types of programs can be limited •by having to manually select and click on things and work with menus. •So those types of apps have their place. I probably wouldn’t create graphics for a website •using only the command line. I certainly wouldn’t edit a video using only a command line, •but there are command line tools for doing image processing and video transcoding, and •I use them all the time because we can automate them. So we’re going to look at some of •those commands later on as we get a little more advanced. Also, Unix is often used in server situations. •So the Unix machine is just in a data center somewhere. It’s not something •Where there’s even a monitor or a keyboard attached to it, and so a graphical desktop •environment would be a waste of resources. You can log in to that machine remotely •and just get the command prompt and it is very simple to take care of things that way. |
Lopes |
•
Also, most of the software on Linux is free, •so once you start using it you become part of that big community. |
League |
•
Yeah, free software it’s contributed by lots of people around the world. So the goal •of this podcast is to help our viewers become adept at the command line and to join in this •community of people that are users and power users, developers – although you don’t have to •be a software developer to be interested in this – and that’s what we’ll do. |
Lopes |
•
Alright, well let’s get hacking! So, I guess the first thing we should learn is how to •actually access the command line that we’ll be working in. •How do we do that using a Mac, like we are now? |
League |
•
So, in the Finder application, which is your basic file explorer, on the ‘Go’ menu, •it refers to a folder called ‘Utilities’. Within the Utilities folder you can find an app called •‘Terminal’, and when you open that, it gives you this little window with your prompt in it. •There are other terminal programs available for the Mac. Some people might actually prefer •them over the one that is built in. One that I’ve used is called iTerm. They just have •different minor capabilities and we can discuss those differences at a later time. •So, I’m going to actually log in as a different user so I can have an environment set up •strictly for this podcast, and let’s not worry about what that command is at the moment. •You can make your terminal font bigger or smaller
using command and also going to go full-screen so that we aren’t distracted by other pictures and things. •We’re starting out here with this prompt. What does all of this mean? |
Lopes |
•
Well, the first part of it, “agenor”, that would be the computer’s name. •It’s just a reference to what the computer is labeled as when it communicates with other •machines on the network. After the “colon”,
you have the “tilde” ( the home directory that the computer is in. |
League |
•
Right! |
Lopes |
•
After that you have what we see here “cltv”, which is the user that we are currently logged in as. |
League |
•
Then the “dollar sign” just means that the terminal is here waiting for me to type a command. •That “dollar sign” is kind of interesting because when you do things as an administrator, as the •‘super user’ of the system, than that often will change to a pound sign, and that’s your •indication that, when there is a “pound sign” there it means that the commands can have a •greater effect on the system. I can do a lot more things in that case because I am the administrator. |
Lopes |
•
What about Linux systems, would you access the terminal in the same way? |
League |
•
It’s very similar, but there’s not a whole lot of uniformity in the Linux world. •There are a ton of different Linux distributions and we’ll talk later about the •differences between some of them. Even within a distribution there can be different desktop •environments and window managers and terminal programs. So, for now all you want to do is go •through menus to try and find something called terminal. It might be “Gnome” terminal or •Konsole, or a program like that and you get to your command line prompt, that’s all we need for now. |
Lopes |
•
What about Microsoft systems? |
League |
•
Yeah, it’s not quite the same. There is a command line for Microsoft Windows and it’s •– the application that is called “Command Prompt”, but it’s a completely different language, •and in my judgement not nearly as flexible and useful. However, there are some ways to run a •Unix like shell on Windows. One of them if you’re a software developer is, you may have •heard of the version control system called Git, and when you install Git on Windows it comes •with an app called Git Bash. Bash is one of the Unix shells, and what it is doing there is •emulating the Unix environment on Windows so that you can operate Git more efficiently, or •more effectively. So that has a limited form of the Unix shell you can use. There’s another •system you can get for Windows called Cygwin, and Cygwin is more of a complete command line •environment. You can install different applications in it and it’s not perfect as far as an emulation •of Linux, but it allows you to do a lot of the same things we are going to cover on Windows. •So we are going to start just by exploring the filesystem. The files and folders on your •system are structured as a tree. Here’s a diagram that we’ve got of a directory tree. •This exact set of files and folders can be downloaded if you want to follow along with what •we’re doing exactly. Check out the link in the show notes for directions for doing that. •So what were the first couple of commands we learned for navigating around the file system? |
Lopes |
•
I think the first two commands I’ve
learned were |
League |
•
Sure, and what do they do? What’s the difference between them? |
Lopes |
•
what folders and files you have accessible to
you. or down that file system. |
League |
•
Yeah, and just as a note, we’re going to use the terms ‘folder’ and ‘directory’ interchangeably. •They mean the same thing. Directory is just an older-school term for it, but a lot of people •more familiar with the desktop environments would use folder, and that means the same thing. •So at the top of this directory tree we have the tilde character, which represents our home directory. •two of its sub-directories are So let’s say I want to look into that
|
Lopes |
•
You can do cd Downloads |
League |
•
Right! So I just type show me that I am in the ls• So say that we want to get down to this |
Lopes |
•
Well, the We can do cd django cd media cd js |
League |
•
Yup! So that’s doing it with three separate
commands, and I’m down in that which it indicates in my prompt. I’ll also point
out this command pwd• exact path to where you currently are. So, what’s showing up in my prompt is just the last •piece of that, but this shows me the complete path to get there. So that also shows us that •we can write these directory names, like when one directory is nested in another we can separate •them with slashes. It can be more convenient to do it all at once. The way to do that is to •just join the directories together with a slash.
So I would be able to say cd django/media/js• And that’s the forward slash not the back slash, but this won’t work from the current place •because I’m already in to do first is go back up. Do you remember the command to go back up to a parent directory? |
Lopes |
•
Going back up you would do cd .. |
League |
•
Yup! So those together with slashes to get all the way
back up to cd ../..• do the cd django/media/js• just using the up and down arrows, and now that will work just as well. So if you look •at our file system tree, How would we get to the |
Lopes |
•
Combining the dot-dot as well as the cd ../css |
League |
•
Right. So the and now I’m in |
Lopes |
•
On the complete opposite side of our file
system tree we have a file called How do we go about navigating to that file? |
League |
•
So one way is to just go up to the top of the tree and down again. So you can see that it’s – •it looks like three levels up to your home directory. So if we go up three times from here. •Now we’re in home, but I can just continue
from there and do cd ../../../cs101/hello/lib/sys• So you just trace the path up and down the
tree, and I’m over in do that is, you can use that command, or another form of cd -• previously. So now I’m back in templates, and instead of using all of those dots, we’ll •just do cd ~/cs101/hello/lib/sys |
Lopes |
•
So now that we’ve used
|
League |
•
So ls• what if you just have a basic option to
ls -F• in this case, that slash indicates that those are sub-directories and everything else that doesn’t •have the slash is a regular file. So that helps me orient myself a little more in •the tree structure. A more detailed version
of that is detailed listing, and it gives lots of information. The file names are here on the •right side, and then we’ve got some permissions. Later, we’ll go into exactly what those mean, •but for now you see that the number. We’ve got a user and a group name, so that’s the owner of this file. The file size, and then •a time stamp, which is when the file was last modified. |
Lopes |
•
So is there an option with the |
League |
•
Yeah, there are a few ways to change how it gets sorted. So, one that is very useful is to •Sort by modification times. So that’s called
ls -t• that with ls -l -t• separate switches like this with a space, or most commands support having them merge together ls -lt• So that it’s just sorted by the modification time. So the most recently modified is at the top, and I often want •to reverse that. So, if you want to reverse
however it’s being sorted, you can add an or ls -ltr• the bottom. I find that really useful because a lot of times you’ll have more files than fit •on the screen, but then the bottom most file that you see is the most recent. |
Lopes |
•
So I had a question in terms of case sensitivity. Earlier when you went into downloads, you •used a capital the |
League |
•
Right. Yeah a lot of the Unix system is case sensitive. So it matters which way you use •uppercase and lowercase, and that includes for
commands. So you can’t type capital The names. So if I go up here again and I try type
a Mac because the file system on a Mac is not case sensitive. Even though the Unix shell is •case sensitive. So you get some weird artifacts with that. Let me try that again, but this time •I am going to use the Tab key. Tab is a way to complete a file name, so you only have to •type part of it and then you hit Tab. So if
I try to type a lowercase that nothing starts with a lowercase I hit Tab, then it works again. So, the strange thing is that although the Mac cd Downloads/• filesystem is not case sensitive, the shell that’s interpreting your command still is. And •when we switch to Linux next time, Linux has a case sensitive filesystem, so it’s important •to be aware of that distinction. |
Lopes |
•
So it’s pretty simple to access the files once we know the correct capitalization and spelling •of it. What if we have a file such as “Command Line TV” with spaces in it? |
League |
•
Yeah, spaces are a real issue in file names because spaces are used to separate the •different parameters on the command line, and so a lot of people that use the command line •have a hard and fast rule I just never put spaces in file names. I’ll use a dash or maybe •an underscore, but the real world is messy and sometimes you’ve got to deal with spaces in file •names and directory names. So for example here
I want to way to do that is to put quotes. It can be a double quote or a single quote, as long as it •is consistent, and then you type it out with the spaces in it and close the quote. cd 'Command Line TV'• That allows me to descend into that directory. Another way is with a back slash. So instead of •putting the quote you just start to type it. Again I’ll use Tab to do the completion •because the Tab completion helps me out. What it’s going to do is insert these •back slashes before each space, and that tells the shell that this isn’t really a space that •separates the next parameter of the command, but instead it’s a space that’s a part of that •same directory name. So that works fine too. cd Command\ Line\ TV |
Lopes |
•
So today we covered the What do we have in store for episode 2? |
League |
•
So next time we’re going to look at how to view different file types from the command line, •and also how to construct some very simple pipelines in order to view the content of •different things. So see you next time! |
•
[Dark electronic beat] •[Captions by Mario Ceballos] •[End] |