fedora-classroom
LOGS

01:00:13 <nirik> #startmeeting Introduction to the command line
01:00:26 <nirik> Hello everyone. Welcome to the Fedora irc classroom. :)
01:00:45 <ahmed-araby> Hello :)
01:00:54 <nirik> Feel free to chime in with questions or comments any any point... I'll try and answer as best I know.
01:00:58 <tw2113> cli rocks!
01:01:13 <nirik> Tonight we are going to be doing an introduction to the command line.
01:01:42 <nirik> This is a pretty open topic and could go in all kinds of directions, so feel free to ask questions about things you would like to know more on or directions you would like to go.
01:02:29 <nirik> so, lets go ahead and go over the basics and then see where people are interested in taking things.
01:02:37 <nirik> #topic What is the command line?
01:02:44 * LinuxCode isnt here
01:02:55 <LinuxCode> -_-
01:03:12 * Khaytsus kills LinuxCode's tty
01:03:13 <nirik> Many folks that are new to Linux are used to the gui (graphical user interface). You login, you click icons with your mouse pointer, etc.
01:03:19 * sseiersen is trolling...
01:03:51 <nirik> While GUI's are great for some tasks, there is a text mode command line interface underlying that some people may not be aware of.
01:04:17 <nirik> This command line is very powerfull at some tasks. Much more so than the GUI interface.
01:04:38 <nirik> In many cases on servers or the like this is the only interface that is used to manage, update and configure a machine.
01:05:07 <nirik> #topic How do I get to a command line?
01:05:44 <nirik> There are many ways to get to a command line session. If you start your linux install in a text mode, you will get a native command line/text login.
01:05:56 <nirik> You can open up one of the many terminal programs from a gui interface.
01:06:12 <nirik> you can use a tool like ssh to connect to a remote server.
01:06:54 <nirik> So, when you are looking at a command line, what are you really interacting with? It's a program called a shell.
01:07:13 <nirik> As often is the case in the linux world there are many different shells out there that act differently.
01:07:23 <nirik> The default shell is fedora is called "bash".
01:07:39 <nirik> http://www.gnu.org/software/bash/
01:08:00 <nirik> Any high level questions on any of that?
01:08:27 <EvilBob> http://www.google.com/linux?q=bash
01:08:28 <satellit_> key combo to get to it from init5?
01:08:45 <nirik> satellit_: it depends on your desktop env and setup...
01:09:01 <nirik> satellit_: in gnome a terminal is in the menus under administration I think.
01:09:17 <satellit_> k
01:09:23 <EvilBob> Applications->System Tools
01:09:29 <nirik> you can also hit a control-alt-f2 and get to a text console. (then control-alt-f1 to go back to the gui session)
01:09:34 <nirik> thanks EvilBob
01:09:46 <nirik> #topic builtin commands
01:10:07 <nirik> so, once you are at a prompt in a command line session, what can you do?
01:10:35 <nirik> well, all kinds of things. Shells typically have a number of 'builtin' commands... that they can run without calling any other program.
01:10:38 <EvilBob> everything you ever needed to
01:11:08 <nirik> if something is not builtin, the shell will look for the command and run it for you and show any output it has.
01:11:37 <EvilBob> Tab Completion is your friend
01:11:48 <nirik> yep. Will be hitting on that soon. ;)
01:12:23 <nirik> You can see a list of builtin commands for your shell by checking it's man page... 'man bash' for example (it's very long, but has a section on builtins)
01:12:44 <nirik> you can run 'man bash' in a command line and it will show the output of the man command with argument 'bash' for you.
01:12:57 <nirik> #topic basic commands and usage
01:13:11 <EvilBob> http://linux.die.net/man/1/bash
01:13:22 <EvilBob> man bash ^^
01:13:25 <nirik> ok, so lets go over some basic commands that people use in the command line quite a lot.
01:14:29 <nirik> first up is the 'ls' command. This lists files in your current directory. By default you start out in your home directory.
01:14:49 <nirik> it has a ton of options, but just running 'ls' shows the files and directories in your home directory.
01:15:33 <nirik> you can always use the 'pwd' command to list your current directory.
01:15:55 * nirik notes that you can look at what your file manager in a gui shows against what ls shows. Both different views to the exact same data.
01:16:07 <EvilBob> "Present Working Directory"
01:16:27 <nirik> Next one you need is 'cd' (change directory). This changes whatever your present working directory is.
01:16:56 <nirik> so, you could for example do 'cd Documents' and then your working directory is /home/yourusername/Documents
01:17:15 <nirik> an ls command there will show you files or folders (directories) in that directory.
01:17:55 <nirik> Anyone have any questions on ls, pwd or cd? You can find more info on each of them from their man pages... 'man ls' for example.
01:18:17 <satellit_> hidden files w/ ls
01:18:38 <nirik> satellit_: yeah, so filenames that start with a . are called 'hidden files'
01:18:48 <nirik> you can use 'ls -a' to list all those in your current directory.
01:19:00 <satellit_> thanks
01:19:04 <jon_y> does this apply to FAT formated drives?
01:19:26 <nirik> when you want to change the way a command works, you pass it arguments... usually - begins an option list. Most commands have some options.
01:19:38 <scramer> what about the alias command?   are there some switches to the commands you list that would be especially useful?
01:19:48 <nirik> jon_y: it would yes, although I don't know if FAT would allow . in the start of filenames.
01:20:03 <nirik> scramer: yeah, aliases are up in a bit here. ;)
01:20:11 <ahmed-araby> I always use the combination ls -hal , Human readable Sizes , All Files , Listing with extra information
01:20:38 <nirik> somewhat it's a matter of personal preference, and aliases can help you customize things to run the way you want...
01:21:00 <jon_y> nirik: FAT drives files can a have "hidden" attribute
01:21:27 <jon_y> does ls -a list them?
01:21:34 <nirik> jon_y: yeah, thats a different thing than we are talking about here... in linux files that begin with . are just not shown on normal lists... ie, default 'ls' command.
01:21:51 <jon_y> nirik: I see thanks
01:22:01 <nirik> I'm not sure how it reacts there. I don't have a FAT drive handy. ;( I can find out after the class tho.
01:22:13 <jon_y> me neither :)
01:22:52 <nirik> #topic job control
01:23:14 <nirik> So, you can run commands that are geared toward the command line and get their output right to your terminal.
01:23:32 <nirik> But what if you want to run a gui command? Or run a command that will take a long time to finish?
01:23:46 <nirik> Most shells have a way to control processes/jobs.
01:24:29 <nirik> Say you want to run firefox from the command line. You can easily do so by running 'firefox' but since the gui is running your shell will never get back to the next prompt until you quit out of firefox.
01:25:03 <nirik> Job control can help out. :) If you put a "&" at the end of a command, it's run in the background, and your shell continues.
01:25:27 <nirik> note that it's output will still go to your terminal, but you can type more commands while it's running.
01:25:52 <EvilBob> but if you kill that shell you also kill most things started from that  shell
01:26:15 <nirik> EvilBob: yes indeed (unless you take precautions to seperate that process from that shell)
01:26:35 <nirik> while you have background jobs running like that you can use the 'jobs' builtin command to list all of them.
01:27:09 <nirik> You can also start a command (without &) and then use 'control-z' to suspend that job.
01:27:26 <nirik> that job will pause (but not exit) and you will go back to a prompt.
01:28:22 <nirik> From there you can use the 'bg' and 'fg' builtin commands. That allows you to background (bg), just like if you have run the command with &, or foreground (fg) the command, to restart it and wait for it to finish
01:28:22 <Padhu> how can i resume it
01:28:41 <Dp67> How do you execute something with bash and still be allowed to kill the terminal while the process runs in the background. Say for example I want to run yum update but still be able to close the terminal window while yum runs its course uninterrupted.
01:28:56 <nirik> Dp67: good question.
01:29:15 <nirik> Dp67: for this you can use the 'disown' builtin.
01:29:42 <nirik> so you start your command, then control-z, then bg to background it, then run 'disown %1' and it will disown that job...
01:29:59 <nirik> that makes it so the terminal/shell is no longer the parent for that job, and it can continue without it.
01:30:20 <nirik> Padhu: did your question get answered with the bg and fg builtins?
01:31:04 <jon_y> nirik: when you disown a process paused earlier, can it be resumed with fg?
01:31:30 <nirik> jon_y: nope. Once you disown it, it's no longer a job as far as your shell is concened. ;(
01:31:59 <jon_y> so, I shouldn't use CTRL-Z then
01:33:04 <nirik> you should only use control-z if you intend to background the job or resume it later, or don't mind if it is killed when your shell exits.
01:33:32 <Padhu> yeah
01:33:50 <nirik> You can also use the 'kill' command to kill a job.
01:34:02 <nirik> kill %1 to kill the first job for example.
01:34:16 <nirik> jobs are numbered from 1 and you use % to refer to them...
01:34:44 <jon_y> I see
01:35:05 <nirik> any further questions on job control? There are more things involved here, but thats the basics. ;)
01:35:34 <nirik> #topic history
01:35:37 <Padhu> oh :-)
01:36:02 <nirik> I'd like to touch on history a bit. Your shell keeps track of the commands you have used. So, if you need to go back and look up something you typed you can do so.
01:36:27 <nirik> First of all you can use the up and down arrows to go backward and forward in your history.
01:36:49 <nirik> if you use a up arrow key you will go back to the previous command, just as you typed it before.
01:37:23 <EvilBob> going forward in history is scary, too much ai involved...
01:37:24 <Padhu> you must add quick access of command from history
01:37:27 <nirik> you can also use the 'history' built in command to list all the history your shell knows about.
01:38:07 <nirik> also, there are short cuts to get to particular commands. For example you can use 'control-r' to start a search backward in your history for a command containing things you type in.
01:39:05 <nirik> You can also use the ! command to repeat a command... just type '!beginningofcommand' and the shell will search back to whatever command you ran that started with that string and run it again.
01:39:47 <nirik> There are a number of other history commands as well, the bash man page should list them all. ;)
01:40:19 <nirik> ok, anything on history, or shall we move along?
01:40:39 <jrt05> how big is the history?
01:41:11 <nirik> jrt05: it can be configured. I'm not sure what the default is off hand. You can save as much as you like. It's saved to a file on exit, so it's always kept around.
01:41:17 <Padhu> 1000.lines
01:41:22 <jrt05> thanks
01:41:30 <nirik> yeah, just checked... 1000 is default. ;)
01:42:01 <nirik> #topic configuration files
01:42:02 <EvilBob> with multiple shells open, last one out is saved?
01:42:03 <satellit_> where is it stored
01:42:19 <nirik> satellit_: it's stored to ~/.bash_history...
01:42:25 <jon_y> is linking .bash_history to /dev/null a good idea?
01:42:25 <satellit_> k
01:42:30 <nirik> the ~ there is a special shortcut for your home directory.
01:42:48 <nirik> jon_y: depends on what you are trying to do. Not save any history?
01:43:05 <jon_y> yeah, it should clear when I restart the shell right?
01:43:11 <nirik> EvilBob: yes, I think so. I use zsh and it can save all shells to the same file, but I think bash saves the last one to exit.
01:44:10 <nirik> jon_y: well, by default it saves... don't you want to know what you typed last time? :)
01:44:33 <jon_y> not sometimes :)
01:44:40 <nirik> So, I would like to touch a bit on config files. There are a number of ways you can configure your shell. Lots of options and as we will see aliases.
01:45:07 <Padhu> ok
01:45:51 <nirik> first of all there are system wide configs for if you want to change something for all users.
01:46:09 <nirik> these are: /etc/profile /etc/bashrc and /etc/profile.d/
01:46:29 <nirik> the last of those is a directory, where packages can put files that they want to apply to all shells on a system where that package is installed.
01:46:42 <nirik> you should only change any of those if you want a global change for all users.
01:47:06 <nirik> Next each user has ~/.profile ~/.bash_login ~/.bash_logout ~/.bashrc
01:47:39 <nirik> for these you would change the login/logout ones only in the case that it's something that should happen at login time, usually most customization will be in ~/.bashrc
01:47:50 <Padhu> rc.local
01:48:09 <nirik> Padhu: rc.local would be for the entire system booting up.
01:48:20 <nirik> This is for shells/command line only.
01:48:41 <nirik> If you open up your ~/.bashrc in an editor, you can see it's very simple. All it does is read in the /etc/bashrc file.
01:48:44 <Padhu> oh
01:49:09 <nirik> you can add to that file any custom commands you would like. For example as mentioned earlier... aliases.
01:49:36 <jon_y> is .bash_login a shell script that is executed at login?
01:49:36 <nirik> alias is another builtin command. It basically allows the shell to see something you type and run a different command or a command with options.
01:50:20 <nirik> jon_y: it's a bit confusing, but it's run for 'login' shells. So, a text console would be a login shell... a shell in a terminal may or may not be considered that... (most terminal programs will let you choose)
01:50:55 <jon_y> ok, only on initial login but not subsequent shells started under it?
01:51:10 <nirik> jon_y: correct.
01:51:13 <EvilBob> not what he said
01:51:35 <EvilBob> well would not make sense to me
01:51:42 <nirik> well, if you run another bash from inside the first one that wouldn't be a login shell... unless you passed it something to do that.. 'bash -l'
01:51:47 <EvilBob> every shell you start should read it
01:51:51 * nirik may be misunderstanding the question.
01:52:29 <jon_y> EvilBob: can you explain?
01:52:44 <EvilBob> would not be logical to only have the first one in read the file
01:53:16 <EvilBob> I will have at times 20 or more terminals open
01:53:42 <EvilBob> why would only the first read my .bashrc
01:53:57 <nirik> EvilBob: no, we are talking about ~/.bash_login... at least I was.
01:54:22 <nirik> only 'login shell' bashes read that one.
01:54:24 <EvilBob> mistype but still applies
01:54:43 <EvilBob> "initial" in the query is not clear
01:54:51 <jon_y> ok, so .bash_login is only for initial login, .bashrc is for every bash that starts?
01:55:21 <jon_y> by initial, I meant started by /bin/login or similar
01:55:59 <nirik> jon_y: the bash man page says: "A login shell is one whose first character of argument zero is a -, or one  started with the --login option."
01:56:23 <nirik> which may depend on your terminal program as to if it makes you bash sessions login or not. ;)
01:56:40 <nirik> anyhow, we are running low on time here. ;(
01:56:42 <jon_y> I see, not just /bin/login
01:57:41 <nirik> so back to aliases. ;) You can add an alias with something like: alias foo='ls -a'
01:57:56 <nirik> that will tell bash anytime you type 'foo' run the 'ls -a' command.
01:59:05 <nirik> you can put any commands you like in your config files... aliases are particularly good there as you always have them around...
01:59:42 <nirik> shall we go on a bit more? Or shall we try and wrap things up? I can go on a bit more if folks want...
02:00:08 <EvilBob> keep going IMO
02:00:14 <Padhu> we can define variable also
02:00:23 <satellit_> +
02:00:36 <nirik> ok. :)
02:00:47 <nirik> #topic completions and keybindings
02:01:03 <nirik> Padhu: yes, you can... I will get to environment in a few here. ;)
02:01:19 <nirik> so, there are lots of handy things to make using a shell fast and easy.
02:01:46 <nirik> one of those is command line completion. If you are trying to run some command that has a long name, you can use the TAB key to ask the shell to complete it.
02:02:08 <nirik> if you hit tab once and it can complete it it will.
02:02:23 <nirik> if it can't you can hit tab twice and it will give you a list of completions.
02:02:40 <nirik> Very handy if you forget a full command, but know how it starts. or just don't want to type the entire thing out.
02:03:23 <nirik> there is also an optional package called 'bash-completion' that you can install.
02:03:33 <nirik> This package adds completion to lots of other commands.
02:04:12 <nirik> so you can do 'command <TAB>' and bash will look at the command and offer you completions that make sense there... if it's hostnames or packagenames or whatever argument.
02:04:37 <nirik> Along with completions, bash lets you change the keybindings. You can set them to whatever you like.
02:05:07 <nirik> At a high level you can change the history and other commands to be like the 'vi' or 'emacs' editors. ;) 'set -o emacs' for example. or 'set -o vi'
02:05:39 <nirik> but if you wanted say control-q to do what control-z does by default, you can rebind that key to do that.
02:06:19 <nirik> any questions on completion or keybindings?
02:06:45 <nirik> #topic environment
02:07:38 <nirik> So, bash comes with an environment full of variables you can query and set and test for.
02:08:14 <nirik> Most of the bash ones are in capital letters.
02:08:25 <nirik> They affect how bash runs sometimes or options that programs look for.
02:08:35 <wb0tra_f8> What is the command to have bash list out the contents of the environment variables?
02:08:46 <nirik> you can use the 'echo' command to do that...
02:08:56 <nirik> echo $UID
02:09:08 <nirik> env variables are addressed with a $ in front of them.
02:09:10 <wb0tra_f8> That only works if you already know the names.
02:09:25 <wb0tra_f8> Would like to see a list of the names and contents.
02:09:27 <nirik> wb0tra_f8: indeed. If you want to list them all you can use the 'env' builtin command.
02:09:48 <wb0tra_f8> bingo -- that's what I was looking for.
02:10:04 <nirik> you can also use completion on env variables.
02:10:33 <nirik> type 'echo $BAS<TAB><TAB>' and it will list all the ones that start with BAS
02:10:57 <wb0tra_f8> "cd $HOME" works just like "cd ~", right?
02:11:11 <nirik> wb0tra_f8: yep. bash will expand variables on your command line.
02:11:26 <nirik> ~ is easier to type though. ;)
02:12:01 <nirik> you can set variables with 'set foobar=243' and then $foobar will be 243.
02:12:28 <nirik> You can then query, test, reset variables.
02:12:42 <nirik> #resources
02:12:45 <nirik> oops. ;)
02:12:50 <nirik> #topic resources
02:13:09 <nirik> First of all you can use the bash builtin 'help' to get help on builtin commands.
02:13:17 <nirik> so 'help set'
02:13:24 <nirik> will tell you about the 'set' builtin command.
02:13:56 <wb0tra_f8> The "help" output on my neighboring CentOS box doesn't include mention of "env".
02:14:01 <nirik> next, as mentioned, the 'man' command has information about commands. Note that you can use 'q' to exit out of a man page. 'spacebar' to go to the next page.
02:14:37 <nirik> wb0tra_f8: ah, you are correct. 'env' is not a builtin command to bash
02:14:54 <jon_y> wb0tra_f8: you can use "export"
02:15:15 <wb0tra_f8> "which env" gives "/usr/bin/env", so not an internal.
02:15:32 <nirik> Another resource thats very dated these days, but has a ton of good info in it still is rute: http://rute.2038bug.com/index.html.gz
02:15:51 <nirik> wb0tra_f8: yeah.
02:16:10 <nirik> #topic Q&A
02:16:18 <nirik> any other general command line/shell questions?
02:16:35 <scramer> what was that rute thing again?
02:16:39 * nirik didn't get though all of his outline... perhaps a followup class. ;)
02:16:45 <nirik> Another resource thats very dated these days, but has a ton of good info in it still is rute: http://rute.2038bug.com/index.html.gz
02:16:53 <wb0tra_f8> Think you were the one that clued me in on the substring removal feature of bash.  Finally got that put to use at work.
02:17:11 <nirik> scramer: it's a guide written a number of years ago, but it shows you how to use command line tools quite well.
02:17:13 <Padhu> how can i set an opening message to cli
02:17:36 <wb0tra_f8> "google motd" ?
02:17:39 <nirik> Padhu: you mean the prompt? or just something that appears before the first prompt?
02:17:53 <jon_y> nirik: how do I tell if a built-in command is available? bash is very configurable these days
02:18:16 <nirik> jon_y: well, 'help command' will tell you if it's builtin or not. If it's not it will say it has no help for that command.
02:18:49 <jon_y> ok, can you tell if bash is using an external utility or a built in command?
02:18:59 <jon_y> like kill vs /bin/kill
02:19:15 <EvilBob> info pages are replacing or augmenting many man pages
02:19:20 <Padhu> last one
02:20:19 <nirik> jon_y: if you don't specify, I think it uses the builtin if available.
02:20:32 <jon_y> ok, thanks
02:21:58 <nirik> Padhu: you can add a 'echo whatever text you like' to your ~/.bashrc or ~/.bash_login
02:22:24 <nirik> EvilBob: yeah, it's sad. info is much less friendly than even man pages. ;(
02:22:44 <nirik> any other questions from anyone?
02:23:00 <Padhu> for every opening of terminal?
02:23:24 <nirik> Padhu: for that use ~/.bashrc
02:24:10 <Padhu> ok. thank you. very nice class
02:24:21 <satellit_> thankyou
02:24:24 <nirik> happy to teach. ;)
02:24:29 <nirik> thanks for coming everyone!
02:24:35 <wb0tra_f8> I appreciate you taking time to run the class.
02:24:44 <Padhu> good teaching :-)
02:24:55 <nirik> Further questions can be answered over in #fedora as well... usually someone around there. ;)
02:25:00 <Dp67> thanks nirik great class
02:25:20 <nirik> #endmeeting