{{{#!IRC [22:04] Logs for this session will be available at http://irclogs.ubuntu.com/2011/01/29/%23ubuntu-classroom.html following the conclusion of the session. [22:05] ok, unfortunately our scheduled instructor is a no-show, but this is a popular session so paultag and I will fill in with a more generic command line Q&A [22:05] When we use the command line we are using a shell. In this context a shell is the most basic way a user can interact with a computer's operating system [22:06] A shell is a piece of software. A unix type system can have many different shells installed. [22:06] by default, Ubuntu uses "bash" for the shell that the user sees (and "dash" for /bin/sh - the shell that the system uses) [22:06] For this session we don't need to be concerned with the differences between dash and bash, but be aware that they exist [22:08] now we won't have a set agenda, so we're just going to open the floor to questions, so open up a terminal and as away! [22:08] s/as/ask [22:08] anyone? bueller? bueller? [22:09] ok, well while we wait for questions I can run through some of the basics I first learned [22:09] There :) [22:09] paultag asked: Why do we use that scary black terminal thing? What use is it? [22:10] Well, the easy answer is that you typically don't have to, these days with Ubuntu there are ways to do many of your common system tasks via the graphical interface [22:10] obengdako asked: without screen and byobu would there be a nicer way of multitasking in shells not including using & and disown [22:10] Humm, what an interesting question [22:10] but it helps when you want to learn more about how your system works, have to do some complicated changes (maybe due to a hardware problem, graphics not working?) or if you need to do debugging (program crashing? launch it from a terminal instead to see if it tells you the problem ) [22:11] the UNIX system was created in the footsteps of the ITS system at MIT. It really was designed to allow processes to stop, pause, and resume without breaking like other systems of the day [22:11] so you can always stop / start apps, using ctrl + z, fg / ctrl + s / q and so forth [22:12] but it was designed to be "under" your bash shell, screen and byobu really are unique because they let you buffer bash through that [22:12] and it lets you really isolate processes in a way that it was not really designed to do, so the short answer is no. If you want to detach, quit, and login elsewhere on the same system, you'll need something like screen [22:12] or know how to redirect stuff in /proc/ to your shell, but that's not basic! [22:12] vigs asked: could you list a few commands of intermediate level (not too simple like cd etc.) which can be used to easily do tasks that people regularly do ? [22:12] this is a good question, and lets us get into the basics a little [22:13] so for those of you who never opened a terminal before (or feel hopelessly lost when you do) the "cd etc" in this question include: [22:13] ls [22:13] when you open a terminal and type "ls" it gives you a directory listing of all your files, by default when you open a terminal this will be in your home directory [22:14] to change directories you use "cd" so to go into folder foo/ you "cd foo" [22:14] to manipulate files you have commands like move "mv" and copy "cp" [22:15] (rename is just a move;) [22:15] to edit a file you can use the command line editor "nano" so: nano filename [22:15] (no need to include .txt in the filename) [22:15] now, intermediate commands [22:15] there are LOTS of them! [22:15] Ddorda asked: even though you said we should be concerned about it, you mentioned dash, and i know there are more few kinds of shells. can you explain the differences? [22:15] paultag: hold up :) [22:16] Shoot, sorry :) [22:16] "history" is a good one, it gives you the full history of commands you've typed [22:16] "df" tells you how much space you have in different partitions (try "df -h" for human readable) [22:17] don't forget stuff like `netstat' and `lsof' [22:17] those can help you see active connections to files or external sockets :) [22:17] "lsmod" is super helpful when debugging hardware problems - it's "ls" (list) plus "mod" which means modules [22:17] so it "lists modules" that you have loaded [22:17] modules are like drivers in windows === Flavio is now known as Guest43676 [22:18] you can also manipulate permissions of files on the command line, using commands like "chmod" "chown" and "chgrp" [22:19] a quick google search for "linux commands" will find lots more :) [22:19] `clicompanion' rocks for this, as well [22:19] and it was written by a member of the beginners team, so it's aimed for new users! [22:19] paultag: ppa? [22:19] Yeah, I'll grab the repo ID [22:20] http://okiebuntu.homelinux.com/okwiki/clicompanion <-- that's the howto :) [22:20] pleia2: mind if I move on to Ddorda's question? [22:20] paultag: please do [22:21] The author of the Bash Cookbook speaks at the Philadelphia LUG I used to run, he did a presentation on bash vs dash a couple years ago, his slides are here: http://princessleia.com/plug/2008-JP_bash_vs_dash.pdf [22:21] Each shell has a different feature set -- just like KDE / Fluxbox / GNOME / Unity have their strong points and weak points, so do the shells. Each has a slightly different dialect of the same language [22:21] shells like zsh have a cult following [22:21] csh trys to be like C, so scripting will be easier to those with C background ( but it ends up just being confusing ) [22:22] 99% of the time bash does what you need it to do -- but there are those "1%-ers" [22:23] gpc asked: Why isn't the .txt needed? [22:23] the full filename on the computer includes ".txt" -- unless of course it does not on the machine ;) -- so to edit a file "foo.txt" you need to use `nano foo.txt', and not `nano foo' [22:24] +if [22:24] because to the GNU userland / filesystem / kernel foo.txt is a totally different file then foo, or FOO.txt [22:24] when in doubt, use tab [22:25] Linux doesn't tend to be as strict about extensions as a system like Windows is, so while Windows may complain that a file has no ".txt" on it, it's pretty common in linux [22:25] +1 [22:25] we use magic numbers at the head of the file [22:25] * pleia2 hasn't used .txt in years :) [22:25] that's why you see "#!--->" at the top of a script [22:25] pleia2: me neither ;) [22:26] 22:25 < mhall119> for more command line fun, run "file foo" and it'll tell you what kind of file "foo" is. [22:26] Yeah, this. That uses the magic number of a file to "ID" it [22:26] great tip :) [22:26] mhall119 asked: Where can I find helpful instructions on how to use all these commands? [22:27] manual pages! [22:27] most commands have "man" pages, so if you wnt to learn more about ls: man ls [22:27] +1 pleia2 :) [22:27] some also have info pages [22:27] info ls [22:27] manual pages are also great for looking at files, as well [22:27] and most also have a --help, so: ls --help [22:28] +1 [22:28] txomon asked: the X enviromenth is executed in a shell, how can it execute more than a windows? doesn't it suspend it? [22:28] Interesting question, txomon [22:28] tritium: the trick here is using subprocesses [22:29] so, when you start X, it uses raw library calls to the video subsystem ( through a networked interface ) to draw your windows [22:29] X it's self is just a server, much like apache2 [22:30] and just like any server, when you connect with a client ( like a web browser for apache ), it handles each client on it's own [22:30] in that way, when you start an X application, it connects ( like a browser ) to it, and "talks" back and forth [22:31] and so each process is isolated and talking over a socket :) [22:31] mhall119 asked: Oh No! "ls --help" is too long and scrolls out of view, how can I display it a page at a time? [22:31] you can pipe the output to a command "less" or "more" [22:31] ls --help | less [22:32] that confines it to your terminal, you just hit the space bar to page down, esc to exit [22:33] Ddorda asked: recently i saw someone climbing up in the shell prompt! was it magic? [22:33] if you hit the up arrow, you can get to the last command you typed [22:33] *super* helpful! [22:33] if you hit the up arrow more, it scrolls through your history one line at a time [22:33] txomon asked: When I press cntl+alt+ I switch to another shell, is there any difference between that and executing a shell in X enviroment? [22:34] Not one bit. You won't be able to start X apps by default ( you'll need to start an X server session and export it ), but you have the exact same shell as an X shell [22:34] but on TTY1, you can run something like `export DISPLAY=":0.0"' to use X apps [22:34] but no, same commands, same system [22:35] 14:35:40 < Ddorda> for ex. if you get a super long answer to "ls", he didn't use |more, but scrolled up [22:36] clarification from previous question [22:36] most terminals allow you to to hold down shift and hit the "page up" key to read the terminal buffer [22:36] mhall119 asked: what if I want to re-run a command I ran like 50 commands back, I remember the start of it, but not the parameters, do I have to hit 'up' 50 times? [22:37] no, there are a couple ways to tackle this [22:38] you can search through the history, so if you know your command starts with "ls" you can: history | grep ls [22:38] !command is usually the most common way ( if it was the last command you ran with that binary ) [22:38] or grepping history, too :) [22:38] you'll see a number next to the list it returns, so in mine I see: [22:38] 499 info ls [22:38] to run that again, I just: !499 [22:39] there are also fancy ways to search bash history, but they aren't consistant between shells [22:39] 14:39:09 < mhall119> paultag: pleia2: with bash, you can also hit ctrl+r and start typing the beginning of the command [22:39] 14:39:15 < mhall119> it'll search ~/.bash_history [22:39] ^^ a good example :) [22:39] +1 there [22:40] UndiFineD asked: I always forget how I executed a command in the past, how can i eassily retrieve that ? , I think it was something like: !command [22:40] 22:39 < UndiFineD> paultag: is it !command:p to show the command before execution ? [22:40] UndiFineD: yes, thanks :) [22:41] txomon asked: When I want to run a X app, I must start a shell, but if I close it, the app closes. Is there any way to let it work without that shell? [22:41] Oh yes, this is a good one [22:41] the trick is when you close a TTY it's like "hanging up" the side of your TTY [22:41] so, there's a fun binary called "nohup", which takes the SIGHUP call and trashes it [22:42] so, to run nm-applet in a x terminal and close it, try running it likeL [22:42] `nohup nm-applet &' [22:42] it will log output for you as well :) [22:43] it's really handy and fun to use [22:43] that or alt+f2 [22:43] then the system'll take care of forking it and pushing it to the background [22:44] vigs asked: When I do a ctrl+r search, it takes me to the last time i used the command. Suppose I want to browse through all the uses of that command, is there a way to do that with Ctrl+r ? [22:45] I don't think so :( [22:45] try patching bash! ;) [22:46] usually tabing would work, but I've not tried it [22:46] nope, tabbing fails. I have no idea [22:46] LeGambitteur asked: is the command history limited ? If so how to increase it ? [22:47] oh [22:47] 14:46:54 < mhall119> pleia2: hit ctrl-r again while it's searching and it'll step through anything that matches the current search [22:47] there we go :) [22:47] the command history is 500 by default [22:47] 22:46 < mhall119> pleia2: hit ctrl-r again while it's searching and it'll step through anything that matches the current search [22:47] to increase it you'll need to edit your .bashrc to add: [22:47] Oh shoot. Sorry for the double post :) [22:47] export HISTSIZE=1000 [22:47] ^^ makes it 1000 rather than 500 [22:48] obengdako asked: nohup is it equivalent to command + & + disown & [22:48] Wooo, I love this question [22:48] YES! and it's actually slightly more "clean" since bash is not even sending a HUP signal [22:48] BUT, that's a "bashism" [22:49] it's not present as a binary in the system, or some sort of global flag, so know that that command will only work for bash [22:49] I'm not sure about dash, but the shell I wrote did not have disown, so I had to use nohup ( and it works globally ) [22:49] so if you are writing for others, use nohup. If you're just playing around, disown is great [22:50] obengdako: is that good? [22:50] or were you looking for something else? [22:51] UndiFineD asked: how to log compilation into one file ? [22:51] UndiFineD asked: how to log compilation into one file ? >1&2 or something [22:51] There are 10 minutes remaining in the current session. [22:51] usually it's 2>&1 [22:52] and that takes stderr and pipes it to stdout, so that you can dump both together [22:52] it's handy for logging errors as well as messages from the application in question [22:52] foo > bar # will push stdout into a file [22:52] I'm not totally clear on the question, pleia2 ? [22:53] that's good :) [22:53] cool :) [22:56] There are 5 minutes remaining in the current session. [22:56] 5 minutes, take your best shot, guys! [22:58] txomon asked: Is there any good guide to learn to use shell? [22:58] tons. The best way is to use it to do casual stuff ( browsing the filesystem, renaming files, and so forth ), but again, the `clicompanion' app is fantastic for this [22:59] it can help teach the basics. Once you have that, a bash scripting guide actually helps day-to-day bash a lot [22:59] and keep in mind that once you're past the basics, you're learning the shell and not the GNU/Linux userland so much :) [22:59] http://tldp.org/LDP/abs/html/ is great (don't be scared off by "advanced" [22:59] (stuff like disown) [22:59] +1 pleia2 [23:00] I learned from that page, and I love it [23:00] 22:58 < _marx_> learning the bash shell oreilly book [23:00] not bad either, a great book for sure }}}