01:00:13 #startmeeting Introduction to the command line 01:00:26 Hello everyone. Welcome to the Fedora irc classroom. :) 01:00:45 Hello :) 01:00:54 Feel free to chime in with questions or comments any any point... I'll try and answer as best I know. 01:00:58 cli rocks! 01:01:13 Tonight we are going to be doing an introduction to the command line. 01:01:42 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 so, lets go ahead and go over the basics and then see where people are interested in taking things. 01:02:37 #topic What is the command line? 01:02:44 * LinuxCode isnt here 01:02:55 -_- 01:03:12 * Khaytsus kills LinuxCode's tty 01:03:13 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 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 This command line is very powerfull at some tasks. Much more so than the GUI interface. 01:04:38 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 #topic How do I get to a command line? 01:05:44 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 You can open up one of the many terminal programs from a gui interface. 01:06:12 you can use a tool like ssh to connect to a remote server. 01:06:54 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 As often is the case in the linux world there are many different shells out there that act differently. 01:07:23 The default shell is fedora is called "bash". 01:07:39 http://www.gnu.org/software/bash/ 01:08:00 Any high level questions on any of that? 01:08:27 http://www.google.com/linux?q=bash 01:08:28 key combo to get to it from init5? 01:08:45 satellit_: it depends on your desktop env and setup... 01:09:01 satellit_: in gnome a terminal is in the menus under administration I think. 01:09:17 k 01:09:23 Applications->System Tools 01:09:29 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 thanks EvilBob 01:09:46 #topic builtin commands 01:10:07 so, once you are at a prompt in a command line session, what can you do? 01:10:35 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 everything you ever needed to 01:11:08 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 Tab Completion is your friend 01:11:48 yep. Will be hitting on that soon. ;) 01:12:23 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 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 #topic basic commands and usage 01:13:11 http://linux.die.net/man/1/bash 01:13:22 man bash ^^ 01:13:25 ok, so lets go over some basic commands that people use in the command line quite a lot. 01:14:29 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 it has a ton of options, but just running 'ls' shows the files and directories in your home directory. 01:15:33 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 "Present Working Directory" 01:16:27 Next one you need is 'cd' (change directory). This changes whatever your present working directory is. 01:16:56 so, you could for example do 'cd Documents' and then your working directory is /home/yourusername/Documents 01:17:15 an ls command there will show you files or folders (directories) in that directory. 01:17:55 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 hidden files w/ ls 01:18:38 satellit_: yeah, so filenames that start with a . are called 'hidden files' 01:18:48 you can use 'ls -a' to list all those in your current directory. 01:19:00 thanks 01:19:04 does this apply to FAT formated drives? 01:19:26 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 what about the alias command? are there some switches to the commands you list that would be especially useful? 01:19:48 jon_y: it would yes, although I don't know if FAT would allow . in the start of filenames. 01:20:03 scramer: yeah, aliases are up in a bit here. ;) 01:20:11 I always use the combination ls -hal , Human readable Sizes , All Files , Listing with extra information 01:20:38 somewhat it's a matter of personal preference, and aliases can help you customize things to run the way you want... 01:21:00 nirik: FAT drives files can a have "hidden" attribute 01:21:27 does ls -a list them? 01:21:34 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 nirik: I see thanks 01:22:01 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 me neither :) 01:22:52 #topic job control 01:23:14 So, you can run commands that are geared toward the command line and get their output right to your terminal. 01:23:32 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 Most shells have a way to control processes/jobs. 01:24:29 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 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 note that it's output will still go to your terminal, but you can type more commands while it's running. 01:25:52 but if you kill that shell you also kill most things started from that shell 01:26:15 EvilBob: yes indeed (unless you take precautions to seperate that process from that shell) 01:26:35 while you have background jobs running like that you can use the 'jobs' builtin command to list all of them. 01:27:09 You can also start a command (without &) and then use 'control-z' to suspend that job. 01:27:26 that job will pause (but not exit) and you will go back to a prompt. 01:28:22 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 how can i resume it 01:28:41 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 Dp67: good question. 01:29:15 Dp67: for this you can use the 'disown' builtin. 01:29:42 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 that makes it so the terminal/shell is no longer the parent for that job, and it can continue without it. 01:30:20 Padhu: did your question get answered with the bg and fg builtins? 01:31:04 nirik: when you disown a process paused earlier, can it be resumed with fg? 01:31:30 jon_y: nope. Once you disown it, it's no longer a job as far as your shell is concened. ;( 01:31:59 so, I shouldn't use CTRL-Z then 01:33:04 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 yeah 01:33:50 You can also use the 'kill' command to kill a job. 01:34:02 kill %1 to kill the first job for example. 01:34:16 jobs are numbered from 1 and you use % to refer to them... 01:34:44 I see 01:35:05 any further questions on job control? There are more things involved here, but thats the basics. ;) 01:35:34 #topic history 01:35:37 oh :-) 01:36:02 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 First of all you can use the up and down arrows to go backward and forward in your history. 01:36:49 if you use a up arrow key you will go back to the previous command, just as you typed it before. 01:37:23 going forward in history is scary, too much ai involved... 01:37:24 you must add quick access of command from history 01:37:27 you can also use the 'history' built in command to list all the history your shell knows about. 01:38:07 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 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 There are a number of other history commands as well, the bash man page should list them all. ;) 01:40:19 ok, anything on history, or shall we move along? 01:40:39 how big is the history? 01:41:11 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 1000.lines 01:41:22 thanks 01:41:30 yeah, just checked... 1000 is default. ;) 01:42:01 #topic configuration files 01:42:02 with multiple shells open, last one out is saved? 01:42:03 where is it stored 01:42:19 satellit_: it's stored to ~/.bash_history... 01:42:25 is linking .bash_history to /dev/null a good idea? 01:42:25 k 01:42:30 the ~ there is a special shortcut for your home directory. 01:42:48 jon_y: depends on what you are trying to do. Not save any history? 01:43:05 yeah, it should clear when I restart the shell right? 01:43:11 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 jon_y: well, by default it saves... don't you want to know what you typed last time? :) 01:44:33 not sometimes :) 01:44:40 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 ok 01:45:51 first of all there are system wide configs for if you want to change something for all users. 01:46:09 these are: /etc/profile /etc/bashrc and /etc/profile.d/ 01:46:29 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 you should only change any of those if you want a global change for all users. 01:47:06 Next each user has ~/.profile ~/.bash_login ~/.bash_logout ~/.bashrc 01:47:39 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 rc.local 01:48:09 Padhu: rc.local would be for the entire system booting up. 01:48:20 This is for shells/command line only. 01:48:41 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 oh 01:49:09 you can add to that file any custom commands you would like. For example as mentioned earlier... aliases. 01:49:36 is .bash_login a shell script that is executed at login? 01:49:36 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 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 ok, only on initial login but not subsequent shells started under it? 01:51:10 jon_y: correct. 01:51:13 not what he said 01:51:35 well would not make sense to me 01:51:42 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 every shell you start should read it 01:51:51 * nirik may be misunderstanding the question. 01:52:29 EvilBob: can you explain? 01:52:44 would not be logical to only have the first one in read the file 01:53:16 I will have at times 20 or more terminals open 01:53:42 why would only the first read my .bashrc 01:53:57 EvilBob: no, we are talking about ~/.bash_login... at least I was. 01:54:22 only 'login shell' bashes read that one. 01:54:24 mistype but still applies 01:54:43 "initial" in the query is not clear 01:54:51 ok, so .bash_login is only for initial login, .bashrc is for every bash that starts? 01:55:21 by initial, I meant started by /bin/login or similar 01:55:59 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 which may depend on your terminal program as to if it makes you bash sessions login or not. ;) 01:56:40 anyhow, we are running low on time here. ;( 01:56:42 I see, not just /bin/login 01:57:41 so back to aliases. ;) You can add an alias with something like: alias foo='ls -a' 01:57:56 that will tell bash anytime you type 'foo' run the 'ls -a' command. 01:59:05 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 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 keep going IMO 02:00:14 we can define variable also 02:00:23 + 02:00:36 ok. :) 02:00:47 #topic completions and keybindings 02:01:03 Padhu: yes, you can... I will get to environment in a few here. ;) 02:01:19 so, there are lots of handy things to make using a shell fast and easy. 02:01:46 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 if you hit tab once and it can complete it it will. 02:02:23 if it can't you can hit tab twice and it will give you a list of completions. 02:02:40 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 there is also an optional package called 'bash-completion' that you can install. 02:03:33 This package adds completion to lots of other commands. 02:04:12 so you can do 'command ' 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 Along with completions, bash lets you change the keybindings. You can set them to whatever you like. 02:05:07 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 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 any questions on completion or keybindings? 02:06:45 #topic environment 02:07:38 So, bash comes with an environment full of variables you can query and set and test for. 02:08:14 Most of the bash ones are in capital letters. 02:08:25 They affect how bash runs sometimes or options that programs look for. 02:08:35 What is the command to have bash list out the contents of the environment variables? 02:08:46 you can use the 'echo' command to do that... 02:08:56 echo $UID 02:09:08 env variables are addressed with a $ in front of them. 02:09:10 That only works if you already know the names. 02:09:25 Would like to see a list of the names and contents. 02:09:27 wb0tra_f8: indeed. If you want to list them all you can use the 'env' builtin command. 02:09:48 bingo -- that's what I was looking for. 02:10:04 you can also use completion on env variables. 02:10:33 type 'echo $BAS' and it will list all the ones that start with BAS 02:10:57 "cd $HOME" works just like "cd ~", right? 02:11:11 wb0tra_f8: yep. bash will expand variables on your command line. 02:11:26 ~ is easier to type though. ;) 02:12:01 you can set variables with 'set foobar=243' and then $foobar will be 243. 02:12:28 You can then query, test, reset variables. 02:12:42 #resources 02:12:45 oops. ;) 02:12:50 #topic resources 02:13:09 First of all you can use the bash builtin 'help' to get help on builtin commands. 02:13:17 so 'help set' 02:13:24 will tell you about the 'set' builtin command. 02:13:56 The "help" output on my neighboring CentOS box doesn't include mention of "env". 02:14:01 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 wb0tra_f8: ah, you are correct. 'env' is not a builtin command to bash 02:14:54 wb0tra_f8: you can use "export" 02:15:15 "which env" gives "/usr/bin/env", so not an internal. 02:15:32 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 wb0tra_f8: yeah. 02:16:10 #topic Q&A 02:16:18 any other general command line/shell questions? 02:16:35 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 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 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 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 how can i set an opening message to cli 02:17:36 "google motd" ? 02:17:39 Padhu: you mean the prompt? or just something that appears before the first prompt? 02:17:53 nirik: how do I tell if a built-in command is available? bash is very configurable these days 02:18:16 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 ok, can you tell if bash is using an external utility or a built in command? 02:18:59 like kill vs /bin/kill 02:19:15 info pages are replacing or augmenting many man pages 02:19:20 last one 02:20:19 jon_y: if you don't specify, I think it uses the builtin if available. 02:20:32 ok, thanks 02:21:58 Padhu: you can add a 'echo whatever text you like' to your ~/.bashrc or ~/.bash_login 02:22:24 EvilBob: yeah, it's sad. info is much less friendly than even man pages. ;( 02:22:44 any other questions from anyone? 02:23:00 for every opening of terminal? 02:23:24 Padhu: for that use ~/.bashrc 02:24:10 ok. thank you. very nice class 02:24:21 thankyou 02:24:24 happy to teach. ;) 02:24:29 thanks for coming everyone! 02:24:35 I appreciate you taking time to run the class. 02:24:44 good teaching :-) 02:24:55 Further questions can be answered over in #fedora as well... usually someone around there. ;) 02:25:00 thanks nirik great class 02:25:20 #endmeeting