[131060620010] |stop pipe() opening stdin [131060620020] |I've currently got code that forks two processes. [131060620030] |The first reads a http streaming radio and pushes the data down a pipe (opened with pipe() ) for the second process to read, decode and output to the sound card using OSS. [131060620040] |I've been trying to debug the decoding part (separate issue) and I've come across a situation where the pipe has a file descriptor of 0 when I print it out. [131060620050] |As far as I can tell this means stdin. [131060620060] |Is this a known problem with pipe, that it can accidentally open one of the standard file descriptors? [131060620070] |If so, how do I get around it? [131060620080] |My pipe/fork code is below. [131060620090] |There is quite a bit of other code, that I hope is irrelevant. [131060620100] |This loop is so that I can go through a list of radio stations. [131060620110] |When 'n' is pressed it sends a command to the two child processes which shut them down cleanly, and then closes all the pipes and loops back around, opening all them up again and forking the two processes again. [131060620120] |The first time it goes through the loop it seems like this works, but on the second time around I get the following output. [131060620130] |So basically I would like to know how to stop pipe from opening up the std file descriptors. [131060630010] |A new file descriptor always occupies the lowest integer not already in use. [131060630020] |The system doesn't care about "standard file descriptors" or anything like that. [131060630030] |If file descriptor 0 is closed, then a new file descriptor will be assigned at 0. [131060630040] |Is there any place in your program or in how you're launching it that may be causing close(0)? [131060640010] |strace can give you a picture of what your executable is doing with file descriptors: [131060650010] |Internet(ADSL) connection doesn't seem to be working on Arch [131060650020] |I've already set up ADSL and used it already for a system update, so I'm sure the set up is ok but pacman suddenly stopped working and when I checked ping wasn't working too. [131060650030] |How can I find out what went wrong and how can I fix it? [131060660010] |

IP Network Troubleshooting

[131060660020] |There are a few standard things you can look for when you are experiencing network connectivity issues. [131060660030] |These are listed here from a top-down, or least fundamental to most fundamental issues. [131060660040] |All the example ip commands shown here use a Linux-specific tool called iproute2. [131060660050] |Many of the tasks can likely be done with ifconfig and route, but the syntax depends on the system. [131060660060] |You can start looking for the correct command for your system on the Rosetta Stone for Unix (thanks @Gilles). [131060660070] |

Is access down to one site and not others?

[131060660080] |If you've just noticed a website or service is down, try others before concluding that you are the one experiencing problems, and not the website you are trying to visit. [131060660090] |

Is DNS not working?

[131060660100] |DNS resolves domain names to ip addresses. [131060660110] |If it isn't working, you may be able to access services by ip address but not domain names. [131060660120] |To test for this, use [131060660130] |8.8.8.8 is the IP address of a Google server on the internet that should always be up; it can be replaced by any IP address known to be on the target network. [131060660140] |This command sends two ICMP echo packet to a specific IP address; it doesn't rely on DNS to work. [131060660150] |If the command works, replace the IP address with a domain name known to be working on the target network, like ping -c 2 yahoo.com; if this doesn't work, the problem is likely to be DNS. [131060660160] |As a quick fix, you can try opening /etc/resolv.conf and adding nameserver 8.8.8.8 after the last line (note, you may need root privileges to edit the file). [131060660170] |That address happens to be a DNS server, and adding it to resolv.conf will tell your system to use it. [131060660180] |If that doesn't work, you should submit another question with more details. [131060660190] |

Is there a route to the network?

[131060660200] |To reach a network, your system has to know how to route to it. [131060660210] |To see the routes your system knows about, we need a couple of commands. [131060660220] |ip rule show [131060660230] |This command lists any routing rules that are setup on your system. [131060660240] |If you see only three entries (lines) and they end in 'local', 'main', and 'default', then you have only the standard rules setup. [131060660250] |If there are any other entries, note them; in particular, the last word of the line - they are names of routing tables. [131060660260] |ip route show [131060660270] |This command shows routes setup on the main table. [131060660280] |There should usually be an entry that directs traffic to the target network. [131060660290] |For internet connections, it is a route that looks like default [via address] dev [dev]... where you may or may not have the 'via' part, and '[dev]' may be something like 'eth0' or 'wlan0' that represents which network interface the network is on. [131060660300] |Previously I said that there should usually be an entry there. [131060660310] |If you had other tables setup and a rule pointing to them to look at the entries in other tables by using the following, replacing '[table name]' with one of the names you noted in the previous (ip rule) step. [131060660320] |If you do not have a route to the target network, you need to add one (or modify your network setup so it automatically adds the correct one for you). [131060660330] |If you don't know how, ask a more specific question here, armed with this knowledge. [131060660340] |

Is the network interface up?

[131060660350] |To be able to use a network interface it has to be up and it should have an address. [131060660360] |You can find if it is up by using: [131060660370] |This lists the network interfaces on your system. [131060660380] |You should see at least two, one called "lo" and another entry for each network interface on your system. [131060660390] |If you have a wired and a wireless interface, you might see 'lo', 'eth0', and 'wlan0' or 'lo', 'eth0', and 'eth1' whatever they are - that first bit after the entry index is the name of the network interface. [131060660400] |For each of the interface entries, you should also see either 'state UP', 'state DOWN', or 'state UNKNOWN'. [131060660410] |If the network interface that is connected to the target network is not present, it can be that the hardware driver isn't loaded or working (for actual network cards) or for PPP connections, that there is no connection established. [131060660420] |If it says the link is down or unknown, the interface needs to be brought up. [131060660430] |This is usually done by your system's networking setup - if it's not up, you can ask a more specific question here with this in mind. [131060660440] |It can be done manually by the following command, replacing '[dev]' with the interface name (you may need root privileges). [131060660450] |

Does the network interface have an address?

[131060660460] |In addition to having the interface up, it needs to have an IP address. [131060660470] |You can find the addresses of your interfaces by running the following command. [131060660480] |You'll see an entry for each of your interfaces with all the addresses it has. [131060660490] |Most entries will have a link address, the important part is the IP address. [131060660500] |There should be a line labeled 'inet' with an address for the network interface connected to the target network. [131060660510] |It should be added automatically by your networking setup; if it wasn't, a dhcp client may not be running, or the ppp daemon may not have added it - you should ask a more specific question here with this in mind. [131060660520] |One can be added manually (but depending on the network may not work) by the following command, replacing '[ip address]' with an ip address appropriate for the network (which may be unknown if the network supplies IP addresses via DHCP or PPP) and replacing '[dev]' with the interface name. [131060670010] |How can I pause/resume rsync [131060670020] |How can I pause an rsync that's running? [131060670030] |First time I did Ctrl+C to kill it and used the -P flag to run again. [131060670040] |Is this prone to corrupt the current file transfer? [131060670050] |Second time I simply put MacOS to sleep (by closing the lid). [131060670060] |Looking at the running process I can see 2 (not sure why) with a status of 'S'. [131060670070] |Tried using [131060670080] |to resume the process, but it has no effect. [131060680010] |Ctrl + Z to suspend, and: [131060680020] |to continue, use [131060680030] |to see suspended jobs; bg [number] to background them; fg [number] to foreground it. [131060680040] |can also be used to suspend; then Ctrl + q to continue it. [131060690010] |You can pause any program by sending it a TSTP (polite) or STOP (forcible) signal. [131060690020] |On the terminal you've run rsync in, pressing Ctrl+Z sends TSTP. [131060690030] |Resume with the fg or bg command in the terminal or a CONT signal. [131060690040] |It is safe to kill an rsync process and run the whole thing again; it will continue where it left off. [131060690050] |It may be a little inefficient, particularly if you haven't passed --partial (included in -P), because rsync will check all files again and process the file it was interrupted on from scratch. [131060690060] |There may be unusual combinations of options that will lead to some files not being synchronized properly, maybe --inplace with something else, but I think no single option will cause this. [131060690070] |If you disconnect your laptop and reconnect it somewhere else, it may get a different IP address. [131060690080] |Then the TCP connection used by rsync would be severed, so you'd have to kill it and start again. [131060690090] |This can also happen if you suspend your laptop and the TCP connection times out. [131060690100] |The timeout will eventually filter out to the application level, but it can take a while. [131060690110] |It's safe to press Ctrl+C and run rsync again. [131060700010] |Run rsync with the --partial flag. [131060700020] |It will then keep partial transfers and resume partial files when started. [131060710010] |suse cannot install software [131060710020] |I just installed suse 11.3, but cannot update the system. [131060710030] |Update Applet says: [131060710040] |PackageKit Error repo-not-available: Failed to download /media.1/media from http://download.opensuse.org/distribution/11.3/repo/oss/ [131060710050] |I filled in my details in yast->proxy, and Firefox works fine with the same details. [131060710060] |My laptop is a Packard Bell with ATI graphics card which I am yet to install. [131060710070] |Could it be the network card? [131060720010] |Do you have a valid network link? [131060720020] |Can you reach other websites? [131060720030] |Is there a firewall? [131060720040] |Can you resolve hostnames, in particular that one? [131060730010] |Try using yast software tool or zypper from the command-line. [131060740010] |I've encountered the same problem yesterday. [131060740020] |Apparently, download.opensuse.org has some stability issues. [131060740030] |Try again to another time, or switch to a mirror. [131060740040] |You can do this over YaST or on the command-line with zypper. [131060740050] |As an example, the following commands will disable the original oss repository, add a new one from a mirror and finally refresh it. [131060740060] |And so forth for other repositories. [131060750010] |If your system time/date has reverted to January 1, 1970 or something ancient like that then your computers entire SSL infrastructure will temporarily be broken. [131060750020] |Connecting to software repositories usually is done over an SSL connection these days to prevent someone from doing a man-in-the-middle intercept attack. [131060750030] |Simply set your system date to be correct and downloading and updating software will magically resume working. [131060760010] |Export from KWD (old KWord/KOffice document format) to anything else [131060760020] |I've got 75 documents in KWD format, from my old days using KDE 3.x. I'd like to convert them to ODT or RTF, so I can edit them with Open Office, Abiword or the newer KWord, but I haven't found a good/quick way to do it. [131060760030] |Opening them in an old version of KWord and exporting them works, but if I have to do it for the 75 of them it'll take me ages. [131060760040] |I've tried using koconverter, a batch converter for KOffice documents included in KDE libs, but neither the one from KOffice 1.6.x nor the one from 2.2.x works. [131060760050] |Any suggestions? [131060760060] |Thanks in advance. [131060770010] |Did you try koconverter ? [131060770020] |This is part of the koffice libs [131060770030] |If it doesn't work there are any other command line tools that can do this, that means you have to do it manually with each document from the last koffice. [131060780010] |Resources to learn linux architecture in detail? [131060780020] |I want to learn the Linux file hierarchy and how the OS works at a deeper level. [131060780030] |Are there any ebooks or webpages to learn that? [131060790010] |The Linux file/directory hierarchy is covered by the File Hierarchy Standard or FHS. [131060790020] |How the OS works at a "deeper" level is a far more complicated topic. [131060790030] |In general the surface level are the user commands ... mostly those in the /bin and /usr/bin directories which are covered in the chapter 1 section of the man pages. [131060790040] |The next level down are the standard library functions and interfaces (on the programming side) which are covered in chapter 3 on most UNIX systems (including Linux). [131060790050] |The system level utilities are found in /sbin and /usr/sbin and covered by man chapter 8, and configuration files are stored in /etc and covered by manual pages in chapter 5. [131060790060] |The next lower level of detail would be the system call interface. [131060790070] |That's covered by man pages in section/chapter two. [131060790080] |System calls are functions in the kernel ... and the details for exactly how to call them are mostly covered by your C programming libraries (libc --- which are provided on must Linux systems in the form of glibc --- GNU lib for C). [131060790090] |The kernel itself is written in C but, as you might expect if you consider the "chicken-and-egg" issue, it is not linked against libc. [131060790100] |So the kernel provides functions that the C libraries depend on. [131060790110] |User space programs, such as the 'ls' command, your shell, any editors, and, in fact, the compilers and linkers used to turn source code into running programs, are all linked to these C libraries. [131060790120] |(Also it's normal for C libraries to "wrap" system calls with their own implementations which have the same names as the system calls but provide some degree of portability, possibly adding some hooks for debugging, tracing, or error handling). [131060790130] |The deepest levels of detail are, of course, the kernel sources themselves. [131060790140] |These document exactly what the kernel implements. [131060790150] |For example if you want to see precisely the list of places and filenames the kernel attempts to find and execute as the "init" process you can see it in init/main.c [131060790160] |I participated briefly and casually in an effort, a few years ago, to organize a series of kernel source study sessions with some guided tours and lectures and create an online study guide for understanding them. [131060790170] |Parts of this were documented on pages at Wikiversity: Reading the Linux Kernel Sources. [131060790180] |There are still some useful discussions for getting the curious and self-motivated reader started. [131060790190] |(However, you still need to be able to read C source code and perhaps understand some inline assembly to really study it). [131060790200] |The real question is just as the announcer will usually intones at those playing the limbo ... [131060790210] |"How can you gooooo?" [131060800010] |Anatomy of the Linux Filesystem [131060810010] |How do I insert a space every four characters in a long line? [131060810020] |I've got a long line that I want to insert a space every 4 characters, on a single lone line of solid text to make it easier to read, what's the simplest way to do this? also I should be able to input the line from a pipe. e.g. [131060810030] |gives [131060820010] |Use sed as follows: [131060830010] |I'm going to answer by only inserting spaces as required so a space appears at least after every 4 characters on a line; not sure which way you want to handle this case. [131060830020] |For example, given input of "aa bbccdd", you'd get output "aa bbcc dd" rather than "aa b bccd d". [131060830030] |I'm using Perl for lookahead, but I'm not very familiar with Perl in general, so there may be tweaks needed: [131060840010] |What tools to use to eliminate metadata in graphics files? [131060840020] |What tools can I use to delete all the EXIF, IPTC, XMP, etc metadata from graphics files? [131060850010] |Try exiftool (which is written in perl): [131060850020] |https://owl.phy.queensu.ca/~phil/exiftool/ [131060850030] |usage: [131060860010] |jhead can be used to delete metadata from JPG files. [131060860020] |The following command line options to jhead are available (quoting the man page for jhead below): [131060870010] |How to control the list of locales which are generated by APT? [131060870020] |Each time I install or operate in other means l10n-related packages, the APT system "rebuilds" a lot of English locales, which takes considerable time. [131060870030] |Look at the APT log: [131060870040] |And this happens for each package. [131060870050] |I don't need all those variants - most of the time I use non-English locale altogether. [131060870060] |For me en_US and en_GB would be sufficient. [131060870070] |So my questions are: [131060870080] |
  • Are all those en_* variants really installed on my machine? [131060870090] |How to check that?
  • [131060870100] |
  • If they are, how to cleanly remove them and prevent APT from generating them?
  • [131060880010] |The extent to which the en_* locales actually take up space on your system really depends on the packages you have installed. [131060880020] |In general, locale data is stored in /usr/lib/locale. [131060880030] |The last time I checked, changing the locales that are generated was a bit Distro specific. [131060880040] |In Debian: [131060880050] |In Ubuntu: [131060880060] |
  • Edit /var/lib/locales/supported.d/en and /var/lib/locales/supported.d/local to only include those locales you want.
  • [131060880070] |
  • Run # dpkg-reconfigure locales
  • [131060880080] |If you want to reclaim the space used by some of those other locales, you can try the localepurge package in Debian or Ubuntu; however, as the man page warns, it can sometimes cause problems. [131060890010] |How can I check the charge of an Apple iPod Shuffle? [131060890020] |I am using Ubuntu and would like to know the answer to this question: [131060890030] |
  • How does one determine whether his/her Apple iPod Shuffle's charge is full in Linux?
  • [131060890040] |In Windows it's easy since iTunes shows the charge. [131060890050] |But in Linux neither Rhytmbox nor gtkpod shows the battery charge. [131060890060] |Any help regarding this. [131060900010] |Just check it on the device itself: iPod shuffle: Checking the battery charge [131060900020] |If you are lucky enough to have a newer model, you can get fairly fine-grained information: [131060910010] |automatically load shell scripts from /usr/bin [131060910020] |Is there a way to have bash automatically load shell scripts I create and place into /usr/bin? [131060910030] |Or is there a different place I should put custom shell scripts so that they are automatically loaded? [131060910040] |For example suppose I create a script called myscript with contents: [131060910050] |and make it executable (chmod a+x), and put it into usr/bin. [131060910060] |I am not able to call e from the commandline (when I try, it says the command wasn't found). [131060910070] |What am I doing wrong? [131060920010] |Such commands should be placed in ~/.bashrc [131060930010] |The alias you have defined will only take effect once the alias command is actually called. [131060930020] |Thus if you were to do this: [131060930030] |It should work. [131060930040] |However, this is clearly not ideal since you want e to be available whenever you start bash. [131060930050] |Luckily, bash provides a number of ways to automatically run commands when the shell is started. [131060930060] |For the full details of how bash starts up, see the manual page. [131060930070] |For our purposes, it is enough to know that ~/.bashrc (that is, a file named ".bashrc" in your home directory) is run as your shell starts up. [131060930080] |One way to make your alias available at startup would be to add this line at the end of ~/.bashrc: [131060930090] |However, if you were to do this for every alias you wanted, your /usr/bin folder would likely become a mess. [131060930100] |And, if you are on a multi-user system, filling /usr/bin/ with scripts like this may cause other users problems as well. [131060930110] |Thus, it is better to place your aliases right inside .bashrc and forgo the separate script all together. [131060930120] |Since you are using Ubuntu, inside your .bashrc file you probably have something that looks like this: [131060930130] |This code looks for a file call .bash_aliases in your home directory and runs anything it finds in that file as well. [131060930140] |If you have this, or if you add this code to your .bashrc, you could also put your alias in ~/.bash_aliases. [131060930150] |This provides an easy way to keep all your aliases in one place and keep your .bashrc file uncluttered. [131060940010] |Share Internet connection from a Debian laptop to a FreeBSD desktop [131060940020] |I have this situation: My Debian laptop is connected to the Internet via its wlan interface through my wireless router. [131060940030] |Recently I decided to install FreeBSD on a very old machine (a celeron 300Mhz) which has only one ethernet interface. [131060940040] |I can't connect this desktop (celeron) to the router (distance and cable concerns), so I was wondering how to make the Debian laptop share its Internet access with the FreeBSD desktop with a little cable. [131060940050] |I've read about network bridging and think I can do that on the Debian side, but I still wonder how to proceed on the FreeBSD celeron desktop. [131060940060] |How can I let this celeron access the Internet so I can upgrade/install stuff on it? [131060950010] |or edit /etc/sysctl.conf and set 1 to the net.ipv4.ip_forward (It should be net.ipv4.ip_forward=1). [131060950020] |This will make that change persistant after a reboot. [131060950030] |(or you can save it in rc.local file) [131060950040] |eth0 - replace with your Dell Wifi port [131060950050] |connect the two machines with crosover LAN cable [131060960010] |Adding kill to a sudoers group [131060960020] |How can I give permissions in sudoers such that each member of a group is able to kill the process owned by another member of the group? [131060960030] |Scenario: I have two users -- bill and dev-cron -- who are members of the group tech. [131060960040] |I'd like bill to be able to kill processes started by dev-cron. [131060970010] |Where you can put a user name in sudoers, you can also put % followed by a group name, + followed by a netgroup name, or an alias for a list of users (defined with the User_Alias keyword. [131060970020] |Though considering your use case, I wonder why you don't just use [131060980010] |How do i bind to Shift+arrow in tmux? [131060980020] |Hi, [131060980030] |I'm looking at tmux from screen, and have hit a bump while configuring the (highly configurable!) tmux key bindings. [131060980040] |Problem is, in my .screenrc i have [131060980050] |and the bindings work (they originally came from rxvt-tabbedex). [131060980060] |But in tmux there's apparently no way to bind commands to shift+arrow combinations. [131060980070] |Please prove me wrong. :) [131060990010] |Setting the window dimensions of a running application [131060990020] |I'm trying to start an application within Ubuntu (xfce or gnome) and via the command line and was wondering if there's a generic way to set the dimensions of a given window of a given app that is currently running? [131061000010] |If the window manager supports Xlib there is. [131061000020] |This uses Python to set the window's size to 500x300: [131061000030] |The hard part is getting the window ID; in the above code it got the ID of the active window. [131061000040] |If you want another ID, you can use something like this to get the title and controlling PID of each window, and choose the right ID based on those: [131061010010] |This is easier to do if you install something like xdotool. [131061010020] |Then you can do: [131061010030] |xdotool search --name "window name" windowsize 300 400 [131061010040] |replace "window name" with a name or reg ex appearing in the window title (you can also search by window class and a variety of other things), and the two numbers appearing after windowsize are the width and height, respectively. [131061010050] |(You can also use percents, etc.) [131061010060] |See man xdotool once it's installed. [131061010070] |If you're on Lucid or earlier, I recommend going to the xdotool website to get a newer version, however. [131061020010] |What are your favorite command line features or tricks? [131061020020] |Share your command line features and tricks for Unix/Linux. [131061020030] |Try to keep it shell/distro agnostic if possible. [131061020040] |Interested in seeing aliases, one-liners, keyboard shortcuts, small shell scripts, etc. [131061030010] |One of my favorites when I forget s: [131061040010] |Not sure if this counts as a "trick", but people seem very unaware of the standard readline hotkeys. [131061040020] |Of particular use in shells: [131061040030] |
  • Ctrl+U - Cut the current line
  • [131061040040] |
  • Ctrl+Y - Paste a line cut with Ctrl+U
  • [131061040050] |
  • Ctrl+L - Clear the screen and redraw the current line
  • [131061040060] |
  • Ctrl+G - Get a new line and abandon the current one
  • [131061050010] |Display a prompt where the hostname is bold. [131061050020] |I tried color prompts for a while, but the color would sometimes look bad depending on the background. [131061050030] |Bold works for me for light background, dark background, blue backgrounds, etc. [131061050040] |This is in my .bashrc : [131061060010] |You can use CDPATH to set up the directory equivalent of PATH; if you try to cd foo and there is no foo in the current directory, the shell will check each of the directories in CDPATH looking for foo in them, and switch to the first one it finds: [131061070010] |For when you don't know where something lives, and you don't care either. [131061080010] |CTRL+R in BASH for searching/activating previously executed commands (the contents of ~/.bash_history). [131061080020] |This is often extremely helpful. [131061080030] |Running this alias will serve the PWD up over HTTP (indexed) on port 8000: [131061080040] |And because I run make all the time, and spaz out and type too quickly, these aliases are probably my most used (seriously): [131061080050] |And probably my most frequently used piece of BASH is a simple script I call upload. [131061080060] |I use it to blit any kind of content to my Linode, and it copies the resulting HTTP URL to my clipboard (middle click). [131061080070] |Very useful for pasting stuff to people in IRC: [131061080080] |Just a couple. [131061080090] |I can post much more later, must get back to work! [131061090010] |This expands somewhat on the !! trick mentioned in this answer. [131061090020] |There are actually a bunch of history-related commands that tend to get forgotten about (people tend to stab Up 100 times instead looking for a command they know they typed). [131061090030] |
  • The history command will show a list of recently run commands with an event designator to the left
  • [131061090040] |
  • !N will substitute the command associated with event designator N
  • [131061090050] |
  • !-N will substitute the N th most recent command; e.g. !-1 will substitute the most recent command, !-2 the second most recent, etc.
  • [131061090060] |
  • As mentioned in the other answer, !! is shorthand for !-1, to quickly substitute the last command
  • [131061090070] |
  • !string will substitute the most recent command that begins with string
  • [131061090080] |
  • !?string? will substitute the most recent command that contains string
  • [131061090090] |Word designators can be added on to a ! history command to modify the results. [131061090100] |A colon separates the event and word designators, e.g. !!:0. [131061090110] |The event designator !! can be abbreviated to just ! when using a word designator, so !!:0 is equivalent to !:0. [131061090120] |
  • !:0 will get the command that was executed
  • [131061090130] |
  • !:1 will get the first argument (and !:2 the second, etc.)
  • [131061090140] |
  • !:2-3 will get the second and third arguments
  • [131061090150] |
  • !:^ is another way to get the first argument. !:$ will get the last
  • [131061090160] |
  • !:* will get all arguments (but not the command)
  • [131061090170] |Modifiers can also be appended to a ! history command, each prefixed by a colon. [131061090180] |Any number can be stacked on (e.g. !:t:r:p). [131061090190] |
  • h -- Line up to the base filename
  • [131061090200] |
  • t -- Only the base filename
  • [131061090210] |
  • r -- Line up to the filename extension
  • [131061090220] |
  • e -- Only the filename extension
  • [131061090230] |
  • s/search/replacement -- Replace the first occurrence of search with replacement
  • [131061090240] |
  • gs/search/replacement -- Replace all occurrences of search with replacement
  • [131061100010] |This is for zsh, not bash, fyi (if you haven't used it, you won't regret trying it out). [131061100020] |This is really useful for quickly typing out long paths for scp transfers. [131061100030] |It works just like using to complete or list available filenames/directories. [131061100040] |Example [131061100050] |will complete the path to /home/webdev/domains/example.com/http.public/longdirname. [131061100060] |I'm bad at examples, but that should give you the idea. [131061100070] |Try it out, it can really save you fingers from typing. [131061110010] |bash -- insert preceding line's final parameter [131061110020] |alt-. the most useful key combination ever, try it and see, for some reason no one knows about this one. [131061110030] |press it again and again to select older last parameters. [131061110040] |great when you want to do something more to the argument/file you used just a moment ago. [131061120010] |If a command takes stdin input, you can read the input from a file with . [131061120020] |This can appear anywhere in the command, so these lines are equivalent: [131061120030] |This is particularly useful for grep, as it allows you to place the expression at the end of the line, so you can quickly modify a grep command it by hitting Up, without needing to scroll left to get past the filename: [131061130010] |Since I'm usually halfway into a command line before wanting to search (CTRL-R in bash) I have the following in my .bashrc [131061130020] |This means that if I type cd then press up/down I can see all the options that I have cd'd to. [131061130030] |Basically I use this for often used dirs. [131061130040] |Like "cd w" and I'm ending up going through all the workspaces I use lots. [131061140010] |Two bash functions which save me many key strokes. [131061140020] |Do automatically an ls after every successfull cd: [131061140030] |Go up n levels: [131061150010] |One thing that saves me a lot of time is the pushd/popd commands. [131061150020] |These guys let you create a stack of directories and reduce typing a lot: [131061160010] |I love chucking as much stuff as I can into my PS1. [131061160020] |Some useful things to remember: [131061160030] |\e[s and \e[u save and unsave the cursor position respectively. [131061160040] |I use this to create an 'info-bar' at the top of the screen, a couple of lines long, which can fit more stuff. [131061160050] |Example: [131061160060] |Combine with alias clear='echo -e "\e[2J\n"'. [131061160070] |Try it out! [131061160080] |Also, the PROMPT_COMMAND variable defines a command to execute before the PS1 every time. [131061160090] |Another one is the bg command. [131061160100] |If you forget to put &at the end of a command, just press ^Z and type bg, and it runs in the background. [131061170010] |Display Git branch and status in the prompt [131061180010] |this is usually in my startup script (.bashrc, .profile, whatever) [131061180020] |shopt goodness, check the comments: [131061180030] |an alias that save keystrokes, mkdir and cd into it: [131061180040] |and last but not least, I've given up on memorizing tar syntax, so: [131061180050] |} [131061190010] |my favorite feature is NO COLORS! =) [131061190020] |TERM=xterm-mono or TERM=linux-m depends on OS... [131061190030] |I really like black and white IRSSI, mc and any other "Text user interface" tool [131061200010] |Execute last command as root: [131061210010] |Another useful ZSH trick: [131061210020] |Treat the output of a command as a file: [131061210030] |This opens an old version of a Mercurial-tracked file in emacs for syntax-highlighted viewing. [131061210040] |Without that, I would have to mess around with hg revert, hg archive, or explicitly send hg cat output to a temporary file. [131061210050] |Of course, this works with any program that opens files, and any program that prints to standard output. [131061220010] |ZSH has global aliases. [131061220020] |It expands the alias anywhere in the command line. [131061220030] |I've found this useful for hostnames: [131061220040] |E.g.: [131061220050] |Then, I can do e.g.: [131061220060] |etc. [131061230010] |diff the output of two commands without creating a temporary file manually (bash): [131061240010] |A ZSH-specific feature is suffix aliases, set by giving alias the -s flag: [131061240020] |If a given extension has a suffix alias, you can execute a file with that extention directly, and ZSH will launch the given program and pass the filename as an argument. [131061240030] |So if the above alias is in effect, these lines are equivalent: [131061250010] |One of my all-time favorite ZSH features is named directories. [131061250020] |You can export a variable with a given name, with a value that points to a certain path: [131061250030] |Now you can use ~foo in a command to refer to /usr/bin: [131061260010] |My favorite is [131061260020] |Simple and so very useful. [131061260030] |Have a look at this website commandlinefu.com. [131061260040] |You can also have a look at these four articles by Peteris Krumins on his blog [131061260050] |
  • Top Ten One-Liners from CommandLineFu Explained
  • [131061260060] |
  • The Next Ten One-Liners from CommandLineFu Explained
  • [131061260070] |
  • Another Ten One-Liners from CommandLineFu Explained
  • [131061260080] |
  • Yet Another Ten One-Liners from CommandLineFu Explained
  • [131061270010] |If you are a fast typist, these come in handy: [131061270020] |This macro helps you compute totals of a column of output: file sizes, bytes, packets, all you have to do is specify the column that you want to add: [131061270030] |You use it like this for example, with no arguments, it adds the total of the first column: [131061270040] |If you provide the argument, it will sum that column, for example, this gives you the total number of bytes used by all the C# files in /tmp: [131061270050] |Sometimes your console gets messed up because you accidentally viewed a binary file (cat /bin/ls for example), you can restore the terminal with this shell function: [131061270060] |I like my ls to use characters to distinguish the class of files, and also to hide the backup files generated by my editor (backup files end with the ~ character): [131061280010] |The ampersand. [131061280020] |It puts your command in the background, so you can continue typing. [131061280030] |Working along, and after a while you see: [131061280040] |And your process is done! [131061280050] |Great for things where you don't need to wait for them to terminate. [131061290010] |The screen command. [131061290020] |It basically saves your command line session for when you come back. [131061290030] |It's sort of a terminal manager, like a window manager. [131061290040] |That way, in a single terminal session, you can have multiple virtual terminals going on. [131061290050] |It's very cool. [131061300010] |Tab completion. [131061300020] |How bad would it suck if you had to type out all the characters of every path? [131061310010] |I have folders named in my home folder as Document, Downloads, Temp, etc with the first letter in uppercase. [131061310020] |When I work on the terminal it's annoying to shift press the first key when you are cd'ing into a directory. [131061310030] |Just key in the following in your terminal and bash would auto-correct the case for you. [131061320010] |My personal favorite is [131061320020] |What the above command does is find a file of name x and then searches said file for whatever pattern you are looking for. [131061320030] |Incredibly useful if you are looking for a particular bit of code in a file that's somewhere in your subdirectories. [131061330010] |If you need to edit a particularly long command line in bash [131061330020] |will open it in the editor ($EDITOR). [131061330030] |In zsh you can get the same behaviour by adding this to .zshrc: [131061340010] |None of the following 'tricks' is technically challenging or impressive, but they have some impact on the other person. [131061340020] |If we can't use our jobs to make our lives happier, then we should think again about some things. [131061340030] |I like alias. [131061340040] |My favorite trick is to edit the ~/.bash_aliases on the computer of my gf as she is missing and add a line like: [131061340050] |or another romantic quotation. [131061340060] |Another "trick" I especially like is: [131061340070] |where 123 is the of the person to whom I would like to wish happy birthday and mails.txt contains the message that I would like to write as the body of the email. [131061340080] |Sleep 1; is sometimes necessary as there is a limit on fork(). [131061340090] |You could also use command line arguments $1 etc... [131061350010] |Pretty basic, but people don't seem to know, returns you to the previous dir: [131061360010] |Umount last mounted device: [131061360020] |!mo expands to the last command that started with mo (at least in bash). [131061360030] |Sometimes one does mv in the middle, so u!m won't work as often. [131061370010] |I can't live without [131061370020] |in my ~/.inputrc. [131061370030] |Activates them in every readline enabled application. [131061370040] |Only activating vi command line editing in the shell works via: [131061370050] |Thus, hitting ESC or CTRL+[ gets you the well known vi-command mode. [131061370060] |And you can use powerful vi commands everywhere! [131061380010] |Sometimes bash settings are such that rm is aliased to rm -i and thus requires confirmation for each file being deleted. [131061380020] |When I work occasionally on such an account, I use \rm to retrieve the original behaviour of rm without changing user configuration. [131061390010] |See this question. [131061390020] |When you run ps ax | grep string: [131061390030] |the last line containing grep is somethings a bit anoying [131061390040] |You can rid yourself of this by running ps ax | grep '[s]tring': [131061390050] |update: or just run pgrep string [131061400010] |sync;sync;sync;reboot [131061400020] |can be really useful sometimes. [131061400030] |Be careful ! [131061410010] |I have this in my .bashrc [131061410020] |And when I have html source code in clipboard and want to find all links I use [131061410030] |And I have all urls in clipboard [131061410040] |I also have this function [131061410050] |which display size (human readable) and filename. [131061410060] |this alias is for show temerature [131061410070] |with this function I can calculate product or sum of arguments. [131061410080] |This is usefull function which split standard input separated by regex and then join the result. [131061410090] |factorial function [131061410100] |This function display wiki text over DNS [131061410110] |I also have three color funcions [131061410120] |This function validate file md5 hash. [131061410130] |this will show error message for a given code [131061410140] |You can print all messages with [131061420010] |Use pgrep foo instead of ps aux | grep foo if you want to find how many instances of foo are running and their pids: [131061420020] |e.g. instead of ps aux | grep firefox, use pgrep firefox [131061430010] |Brace Expansion: [131061430020] |Brace expansion is a mechanism by which arbitrary strings may be generated. [131061430030] |It allows you to replace tedious lines like: [131061430040] |with a shorter instance [131061430050] |some other uses [131061430060] |Arithmetic Expansion: [131061430070] |Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. [131061430080] |The format for arithmetic expansion is: [131061430090] |The expression is treated as if it were within double quotes, but a double quote inside the parentheses is not treated specially. [131061430100] |All tokens in the expression undergo parameter expansion, string expansion, command substitution, and quote removal. [131061430110] |Arithmetic expansions may be nested. [131061440010] |See command output updated every n seconds [131061440020] |Show statistics about network device wlan0 [131061440030] |Show routing table for device eth1 [131061440040] |Display statistics for all routers packet travels through to reach HOST [131061440050] |Consult reverse DNS records for host names on NETWORK [131061440060] |Benchmark a website [131061440070] |Get all links from a web page [131061440080] |Show default gateway [131061440090] |Write standard error to a file [131061440100] |Redirect stderr to stdout [131061440110] |Redirect both stderr and stdout to the same file. [131061450010] |Displays a nice ascii art of the current proccess tree, with the most cpu intensive proccess higlighted. [131061450020] |Kill it with Ctrl + C [131061470010] |dc is a RPN calculator; this function enables me to type the expression as the command arguments: [131061480010] |There is a great site for this at: http://www.commandlinefu.com/commands/browse [131061490010] |Once so often when you've typed a long command and before finishing it you've realized it won't work right away, because you need to run something else before (e.g. entered git commit -m "long commit message here"), you can hit ^A^K to go to the start of the line and kill it (saving into a buffer), next run a command to fix things, and finally ^Y to paste the killed command, and continue. [131061490020] |Saves a lot of re-typing. [131061490030] |All this, of course is when readline is in Emacs mode. [131061490040] |Another time-saver: mkdir -p some/nested/dirs/to/be/created creates all the dirs in a path if they're missing. [131061500010] |I found the following useful when constantly switching between Windows and Unix/Linux: [131061510010] |My favourite command is 'find', I use it everywhere... examples: [131061510020] |Just display heaviest files in ls -l (long) format. [131061510030] |Then, if you need your code with 0640 permissions, just search: [131061510040] |or replace: [131061510050] |Then, do you need a symbol and don't know where is it?? [131061510060] |Newer files than XFILE?? [131061510070] |Yeah, "find" rulez! [131061520010] |Not really a one-liner but I think it's useful. [131061520020] |Convert many files to uppercase, for example file_to_upper *php *c. [131061520030] |There are many similar cases like converting to lower, renaming all files by suffix/prefix, etc. [131061530010] |
  • The do-nothing command : as in [131061530020] |
  • Brace expansion in combination with for loops: [131061530030] |
  • ! operator and short circuiting operators || and && [131061530040] |
  • using sub shells instead of pop/push (comes in handy in scripts) [131061530050] |
  • the kind-of what-is command type [131061530060] |
  • also very nice: here-strings [131061530070] |
  • and my favorite: redirection on a list of commands [131061540010] |What are pros/cons of dselect and apt-get? [131061540020] |I hardly ever hear anyone mention dselect, a deprecated package management front-end for Debian. [131061540030] |Considering that it still exists as part of dpkg source, it must still have its uses. [131061540040] |What are those? [131061540050] |How does it compare with apt-get? [131061550010] |Dselect is an interactive dpkg front-end that resolves dependencies and conflicts. [131061550020] |It lacks most of apt's advanced features: no differenciation between Suggests/Recommends/Depends, less good dependency and conflict resolution, no support for multiple sources of packages, no apt pinning/preferences, no automatically-installed package mark, … [131061550030] |(This is from memory. [131061550040] |Actually dselect can now use apt backends for some functions, at least it can download from apt's sources.list.) [131061550050] |Dselect got a lot of hate simply from having unusual key bindings. [131061550060] |I think your question will bring out unfond memories in some people. [131061550070] |I suppose dselect can still be useful if you want an interactive package selector with smaller memory consumption than apt. [131061560010] |Deselect doesn't have any of the wonderful dependency resolution, but you can kind of think of deselect as a curses based "synaptic". [131061560020] |However, you only want to make selections with deselect; don't actually do the installation. [131061560030] |After making selections run this: [131061560040] |Best of both worlds. [131061570010] |Ploblem making a virtual host with apache [131061570020] |Once i tried to make a virtual host, and the problem was that if i make another file in /etc/apache2/sites-available/ that says [131061570030] |Then save it, restart apache, and appending /etc/hosts like this: [131061570040] |I get the page that corresponds the DocumentRoot from /etc/apache2/sites-available/default [131061570050] |That time i left it unsolved. [131061570060] |Now i want to do it once again and i get the same problem. [131061570070] |Despite the fact that i use different version of linux distro. [131061570080] |I feel like i'm doomed. [131061570090] |Any help would be very appreciated [131061580010] |did you enable the site using the a2ensite command? [131061580020] |The /etc/apache2/sites-available directory lists those that you have setup but it needs to be in /etc/apache2/sites-enabled to be picked up when you next reload the apache2 configuration. [131061590010] |A tool for checking broken web links [131061590020] |Please recommend a tool that checks for broken links on a web site. [131061590030] |not required, but would be nice to have: [131061590040] |
  • checks standards-compliance of the HTML, CSS, Javascript, ...
  • [131061590050] |
  • displays permanent redirects
  • [131061600010] |LinkChecker. [131061600020] |LinkChecker is a free, GPL licensed URL validator. [131061600030] |Features [131061600040] |
  • recursive and multithreaded checking
  • [131061600050] |
  • output in colored or normal text, HTML, SQL, CSV, XML or a sitemap graph in different formats
  • [131061600060] |
  • HTTP/1.1, HTTPS, FTP, mailto:, news:, nntp:, Telnet and local file links support
  • [131061600070] |
  • restriction of link checking with regular expression filters for URLs
  • [131061600080] |
  • proxy support
  • [131061600090] |
  • username/password authorization for HTTP and FTP and Telnet
  • [131061600100] |
  • honors robots.txt exclusion protocol
  • [131061600110] |
  • Cookie support
  • [131061600120] |
  • HTML and CSS syntax check
  • [131061600130] |
  • Antivirus check
  • [131061600140] |
  • Different interfaces: command line, GUI and web interface
  • [131061600150] |It's also in Debian Lenny: aptitude install linkchecker and in the FreeBSD ports: /usr/ports/www/linkchecker [131061610010] |Linux: Interface/control 3.5 mm Headphone or Microphone port? [131061610020] |This might sound crazy, but bear with me ;) [131061610030] |I am making a DIY camera trigger, and I would like to see if I can trigger it remotely by plugging it into my Microphone or Headphone ports. [131061610040] |It's a basic 2.5 mm --> 3.5 mm plug, and all I need to do is short the first and last, first and second, and all three to focus, trigger, and focus and trigger. [131061610050] |It's a bit hard to explain, but is it possible to send electrical signals directly through those ports? [131061610060] |I'm up to some C++ or Python (heh) if I have to... [131061620010] |You can use the audio port to create a time-varied differential voltage signal. [131061620020] |You can't short the contacts together, though. [131061620030] |In fact, you might even damage the dac in your computer if you connected it since doing that would force the dac outputs to whatever voltage level the hotshoe is. [131061620040] |If you really want to do this, you might want to use a USB gpio board (like this one) and make a circuit that shorts your contacts. [131061620050] |The folks at Chiphacker (aka Electronics &Robotics) would be able to help you with any questions about that. [131061630010] |Get the free space available in current directory in Bash. [131061630020] |I know df -h and pwd, but it seems a little complex for the regex matching part. [131061630030] |Any ideas? [131061640010] |The output can be made a bit easier to parse by using the -P option which will ensure that: [131061640020] |
  • The information about each file system is always printed on exactly one line; a mount device is never put on a line by itself. [131061640030] |This means that if the mount device name is more than 20 characters long (e.g., for some network mounts), the columns are misaligned.
  • [131061640040] |This makes it much easier to get just the free space available: [131061640050] |(-h uses megabytes, gigabytes and so on. [131061640060] |If your system doesn't have it, use -k for kilobytes only.) [131061640070] |If we pass df a path, it is only going to return 2 rows: a header row and then the data about the file system that contains the path. [131061640080] |We can use tail to grab just the second row. [131061640090] |We know that the space available is in the 4th column, so we grab that with awk. [131061640100] |This all could be done with awk: [131061640110] |or many other sets of filters. [131061650010] |How about doing df -h .. [131061650020] |This will give you the available free space of the partition your current working directory is in. [131061650030] |A small example: [131061660010] |How to install Python 3.x on Debian? [131061660020] |First of all, I am new to all things Linux. [131061660030] |I chose Debian for my Linode because it seemed stable and secure. [131061660040] |Now I want to write some sysadmin-type scripts in Python to teach myself the language. [131061660050] |Based on this SO question I've decided to go with Python 3. [131061660060] |At very least, I'd like my Linode to have 2.6 or 2.7 because that's what's installed on my home machines. [131061660070] |But the default for Debian is still 2.5. [131061660080] |That's fine, but for the life of me I cannot figure out how to get the python3.1 package!! [131061660090] |It's driving me nuts! [131061660100] |Here's a sample of what I've tried (after running apt-get update to make sure my package index was up to date): [131061660110] |I know that this package is available because I can see it right there on debian.org. [131061660120] |How do I find it and install it? [131061660130] |And after I finally figure out how to install the latest Python, am I still going to have trouble from my package manager when installing things that depend on Python? [131061660140] |Are they going to point to the default python instead of the one I want? [131061660150] |I'd much rather use the native package manager than use easy_install (see the reason I care about packages here). [131061660160] |Oh, and I am looking for a command-line-only answer. [131061670010] |I'm going to assume you've got Debian lenny and have your sourcelist geared towards the stable release which by default only has python2.5 (someone correct me?) [131061670020] |From a brief scan of their package tree, python3.1 exists in the Debian Sid (unstable) and Debian Squeeze (testing) tree. [131061670030] |See Here [131061670040] |You can w-get directly from the links provided, but that's often messy as you'll need to resolve any dependencies yourself through a game of what don't I have? with the CLI. [131061670050] |If you're apt for switching your package tree to squeeze, you can change your /etc/apt/sources.list to match that of the squeeze tree. [131061670060] |From there, you can aptitude update then aptitude install python and you should have python3.1 and all its dependencies in tow. [131061680010] |I wrote elsewhere that if you are mainly interested in stability, Squeeze (soon to be declared stable) is your best bet at the moment. [131061680020] |The easier solution is to do a fresh install of it (download page). [131061680030] |Another option is to upgrade. [131061680040] |If you choose this option: [131061680050] |
  • in "/etc/apt/sources.list", replace all occurences of lenny (sometimes stable) with squeeze
  • [131061680060] |
  • proceed to the usual apt-get update &&apt-get upgrade
  • [131061680070] |
  • monitor what will be installed (to ensure that you wont screw your precious installation)
  • [131061680080] |[note] The default Python version in Squeeze is 2.6, and is planned to be made 2.7 after release. [131061690010] |Colored man pages not working on gentoo [131061690020] |I have a problem using these methods to get colors in my man pages in gentoo. [131061690030] |I've asked already in the gentoo forums but it still doesn't work, and the comments in a bug report (Bug 184604) don't work either. [131061690040] |Can someone help me to get colours in my man pages? [131061690050] |EDIT: Yes, I'm using less as pager and urxvt-unicode as terminal emulator [131061690060] |EDIT2: [131061690070] |I already asked in the gentoo forums but it didn't help, this is the link I couln't post before (because of my reputation) http://forums.gentoo.org/viewtopic-t-819833-start-0.html. [131061700010] |Could be a number of problems. [131061700020] |Seeing as you're using zsh, try putting this in your ~/.zshrc: [131061700030] |Then open a new terminal window and try running [131061700040] |if it's not working, run each of the following to find out where the problem is: [131061700050] |Number 1 [131061700060] |should print [131061700070] |and [131061700080] |should print [131061700090] |if not, you put the export LESS stuff in the wrong file. [131061700100] |Number 2 [131061700110] |should print [131061700120] |in a red color. [131061700130] |If it doesn't there is something wrong with your terminal settings. [131061700140] |Check your terminal settings (e.g. ~/.Xresources) or try running gnome-terminal or xterm and see if that works. [131061700150] |Number 3 [131061700160] |(^H must be entered by pressing Ctrl+V then Ctrl+H) [131061700170] |should print [131061700180] |in red. [131061700190] |If it doesn't, please run these [131061700200] |and paste the output back in your question. [131061700210] |Number 4 [131061700220] |should print [131061700230] |(note the ^H like in step number 3) [131061700240] |if it's printing something like: [131061700250] |instead, you will need to find a way to disable "sgr escape sequences". [131061700260] |The easiest thing to try is adding export GROFF_NO_SGR=1 to .zshrc, but there are other ways of fixing this. [131061700270] |Number 5 [131061700280] |should display the ls man page with colors. [131061700290] |should now be working! [131061710010] |Having read Mikels answer, its very comprehensive, and will hopefully work on all systems, but its probably overkill for myself ( also on a gentoo system. ) [131061710020] |So here is a result for people who are very "Do long, didn't read" with all that shenanigans. [131061710030] |The Bare minimum I could do to get Coloured Man pages is as follows: [131061710040] |This renders text that was previously only in bold, in bold and red. ( The red characterised by the '31' in LESS_TERMCAP_md ) [131061710050] |These 2 rules control the formatting of the current line number display, and coerce it to rendering in Green. [131061710060] |These 2 rules move everything that was previously underlined, to being underlined and yellow. ( 04 is 'underlined', 33 is "yellow" ) [131061720010] |Flash question, big screen [131061720020] |The question is: I have a laptop, and I extend my desktop on external display, so I get a wide desktop (3200px). [131061720030] |When I make the videos on flash fullscreen, don't know why, but the fullscreen appears on my little part of desktop (the laptop display). [131061720040] |Is there any way to tell flash to play fullscreen on my bigger part? [131061730010] |Flash will enter full screen mode on your primary display. [131061730020] |In the configuration for your dual monitor set up there should be the option to set the external as the primary display. [131061740010] |You can change your primary display temporarily with xrandr. [131061740020] |I.e. open a terminal and run: [131061740030] |xrandr --output HDMI1 --primary [131061740040] |Where HDMI1 is the RandR output name for your external display. [131061740050] |You can determine the name by listing all the outputs with xrandr -q. [131061740060] |E.g. in my case, my notebook screen is DP1 and my external LCD (hooked up via DVI) is HDMI1. [131061740070] |Note: If this messes up the relative position of your monitors, you can fix it with something like: [131061740080] |xrandr --output HDMI1 --auto --pos 0x0 --output DP1 --auto --right-of HDMI1 [131061740090] |This puts my notebook screen to the right of my external monitor. [131061740100] |If your notebook is to the left of your external monitor, change --right-of to --left-of. [131061740110] |To make it permanent, you can run xrandr from a script and stick it somewhere that gets launched automatically (e.g. Startup Applications on Ubuntu). [131061750010] |ssh problems only when connecting from remote IP [131061750020] |When I try to connect from a remote computer that is not in the local network via ssh I get into trouble... [131061750030] |When I try to execute a TUI application it hangs and I cant do anything... [131061750040] |I type ./menu and then nothing happens. [131061750050] |However this program runs with no problem when connecting with ssh with a local IP (another computer in the local network). [131061750060] |But this 100% same program is installed also on another computer. [131061750070] |When connecting via ssh to the other computer with a remote IP I get no problem! [131061750080] |SOLUTION I increased the MTU value of my router [131061760010] |Seems like broken PMTUD. [131061760020] |Check MTU an all involved computers and use ping -D to determine which maximum packet size can be transmitted over path to remote host. [131061770010] |Track [sh] <defunct> for debug purposes ? [131061770020] |Hi all, [131061770030] |I have a big application (in C++) which generates time by time defunct process. [131061770040] |I know the application uses intensively linux commands inside. [131061770050] |I would need to know which linux commands were called by those sh defunct process, is it possible to find out. [131061770060] |Or, is it possible to set up linux and get a sort of log when my application calls linux commands? [131061770070] |Thx. [131061770080] |Luke [131061780010] |From Wikipedia: [131061780020] |A defunct process is a process that has completed execution but still has an entry in the process table. [131061780030] |This entry is still needed to allow the process that started the (now zombie) process to read its exit status. [131061780040] |Is your C++ code calling wait()? [131061780050] |If you get the exit status by calling wait() the defunct process should disappear. [131061790010] |This big application is issuing external commands via a shell, using popen or similar library functions. [131061790020] |The intermediate shells remain as zombies (“defunct processes”) because the application isn't calling wait to “reap” its children. [131061790030] |Note that zombie processes are totally harmless (no matter what B-movies might lead you to believe); the only resource they consume is an entry in the process table. [131061790040] |You can trace what commands the application executes by running [131061790050] |This may slow down your program somewhat. [131061790060] |You can switch tracing on and off during the lifetime of a process: to start tracing, run [131061790070] |where 12345 is the process ID you want to trace. [131061790080] |Kill the strace process (e.g. by pressing Ctrl+C) to stop tracing. [131061800010] |Usage of inb, inl, inw to access kernel space from user space [131061800020] |What are some user space examples of using inb, inl, and inw to access kernel space in Linux? [131061810010] |When do you use brace expansion? [131061810020] |I understand what brace expansion is, but I don't know how best to use it. [131061810030] |When do you use it? [131061810040] |Please teach me some convenient and remarkable examples if you have your own tip. [131061820010] |Brace expansion is very useful if you have long path names. [131061820020] |I use it as a quick way to backup a file: [131061820030] |will copy /a/really/long/path/to/some/file.txt to /a/really/long/path/to/some/file.txt.bak [131061820040] |You can also use it in a sequence. [131061820050] |I once did so to download lots of pages from the web: [131061820060] |or [131061830010] |I use it when I want to reduce typing: [131061830020] |Another example: [131061840010] |I use it to compare actual test output to desired test output during development. [131061840020] |If test #41 fails, it's easy to see what the difference between the test output (in file tests.output/041) and the desired output (in file tests.out/041): [131061850010] |Brace expansion is a bashism. [131061850020] |As such it should not be used because it breaks the compatibility model. [131061860010] |Brace expansion comes very handy when creating large directory structures: [131061860020] |This will give you [131061860030] |You could even go one step further and put brace expansion into brace expansion: [131061860040] |This will give you the same directory structure as the example above. [131061870010] |Some frequent cases for me are: [131061870020] |For renaming: [131061870030] |or [131061870040] |or [131061870050] |(Although it's less messy to use version control for the last 2 tasks.) [131061870060] |For comparing (already mentioned): [131061880010] |Isn't less just more? [131061880020] |When I do more filename and less filename, it would seem that the resulting terminals are quite similar. [131061880030] |I can navigate and search through my files identically (j, Space, /pattern, etc.). [131061880040] |I find it hard to believe that less is more and vice versa. [131061880050] |Are there any differences between the two? [131061890010] |The difference is mostly historical at this point, I believe some systems even have "more" and "less" hardlinked to the same binary. [131061890020] |Originally, "more" pretty much only allowed you to move forward in a file, but was pretty decent for buffering output. [131061890030] |"less" was written as an improved "more" that allowed you to scroll around the displayed text [131061890040] |The first line of my "man less" pretty much sums it up: [131061900010] |Ubuntu still has distinct less/more bins. [131061900020] |At least mine does, or the 'more' command is sending different arguments to less. [131061900030] |In any case, to see the difference, find a file that has more rows than you can see at one time in your terminal. [131061900040] |Type 'cat', then the file name. [131061900050] |It will just dump the whole file. [131061900060] |Type 'more', then the file name. [131061900070] |If on ubuntu, or at least my version (9.10), you'll see the first screen, then '--More--(27%)', which means there's more to the file, and you've seen 27% so far. [131061900080] |Press space to see the next page. 'less' allows moving line by line, back and forth, plus searching and a whole bunch of other stuff. [131061900090] |Basically, use less. [131061900100] |You'll probably never need more for anything. [131061900110] |I've used less on huge files and it seems OK. [131061900120] |I don't think it does crazy things like load the whole thing into memory (cough Notepad). [131061900130] |Showing line numbers could take a while, though, with huge files. [131061910010] |There are a couple of things that I do all the time in less, that doesn't work in more (at least the versions on the systems I use. [131061910020] |One is using G to go to the end of the file, and g to go to the beginning. [131061910030] |This is useful for log files, when you are looking for recent entries at the end of the file. [131061910040] |The other is search, where less highlights the match, while more just brings you to the section of the file where the match occurs, but doesn't indicate where it is. [131061920010] |less is a lot more than more, for instance you have a lot more functionality, [131061920020] |And I don't remember more ;-) [131061930010] |In addition to the extra features already mentioned in less, it also has a 'v' command which opens the current file in 'vi' at the same position. [131061930020] |When you exit 'vi', you will be back in less with the (possibly updated) file shown. [131061940010] |Less has a lot more functionality. [131061940020] |You can use v to jump into the current $EDITOR. [131061940030] |You can convert to tail -f mode with f as well as all the other tips others offered. [131061950010] |At least on systems I've used, more exits automatically when you reach the end of the file; less requires you to exit explicitly. [131061960010] |Upstart on Debian? [131061960020] |I created an upstart script in Ubuntu, thinking it would be the same for Debian. [131061960030] |But Debian doesnt have a /etc/init folder that Ubuntu has. [131061960040] |I went to the upstart download page and seeing that they have packages, did a apt-get install upstart, but it asks to remove sysvinit, which I know will/might screw up my system. [131061960050] |So how do I make my Ubuntu script work on Debian? [131061960060] |Thanks. [131061970010] |The reason it's going to remove sysvinit is because these two are conflicts (IE: incompatible). [131061970020] |Also, note that sysvinit in considered essential (IE: not to be removed, unless you know what you are doing). [131061970030] |Part of the output from 'aptitude show upstart`: [131061970040] |Assuming you can afford to hose your system (IE: this is a personal machine, and you have a proper backup), go ahead and install it. [131061980010] |It's not directly about Debian vs Ubuntu, it's about SysVinit vs Upstart. [131061980020] |Debian defaults to SysVinit; you can install Upstart, but you need to know what you're doing, and you should be familiar with it before you even think of installing it on a production server. [131061980030] |Although it's theoretically possible to install both, with only one of them running as process number 1, Debian doesn't support this out the box. [131061980040] |Upstart is younger than SysVinit and has more capabilities, which explains why you can't just take an Upstart service description and feed it to SysVinit. [131061980050] |You'll have to write a script for /etc/init.d. [131061980060] |Basically that script needs to look at its first argument ($1) and start, stop or restart the service as directed. [131061980070] |If you were using Upstart events to determine when to start the script, you'll have to use some other methods. [131061980080] |Upstart gathers events from many different sources; you can get the trigger from wherever Upstart gets it, Upstart in this respect is just a convenient way of not having to look for triggers in many different places and protocols. [131061990010] |What distro for an old HP (Celeron/384MB). [131061990020] |An old HP desktop just came my way for service. [131061990030] |Was running XP, but the install is trashed. [131061990040] |User would like to switch to Linux, but the box it's only a 950mhz Celeron with 384MB RAM. [131061990050] |It does have a decent sized hard drive though (40GB), so something should fit. [131061990060] |I tried OpenSuSE 11.3, but it just goes to a black screen part way through the installer. [131061990070] |What's the fullest featured distro I can squeeze onto this box? [131062000010] |I'd have a look at Archlinux for 686, you could install enlightenment 16 or 17, fluxbox or LXDE as a lightweight windows manager and it should run OK on that configuration. [131062000020] |If you can squeeze some more RAM in it it will help greatly, 1Go would be great IMHO. [131062010010] |I'd try Slackware. [131062010020] |I've put Slackware 13.1 on a very used laptop and had it work pretty well, but I've also backed off to Slackware 11.0 on a circa 2002 Compaq "EVO". [131062010030] |The "EVO" has that ugly, ill-supported "Brookdale" graphics chipset, and the latest and greatest X11 doesn't do Brookdale hardly at all. [131062020010] |Your question reminded me of a distro chooser mentioned in chat a few weeks back. [131062020020] |Seems accurate enough, based on a small and completely unscientific trial I ran with friends. [131062020030] |Anyways, according to that widget, you might want to take another crack at OpenSuSE. [131062020040] |Of course, I had to guess on some of the questions; your results may differ. [131062030010] |you can also try Ubuntu LTS 10.04 for this box :) [131062030020] |I have heard about the Fedora 14 LXDE/xfce Spins they are good for low power cpu's [131062040010] |I would say that something with XFCE will probably be your best bet. [131062040020] |I had great success with a custom Debian install running XFCE instead of Gnome on a Pentium3 500MHz with 512MB ram; nowadays I would probably use Arch though. [131062050010] |The Debian installer is text-based and is included in the *Ubuntu distriubtion as the "Alternate" CD. [131062050020] |There are many lightweight distributions available, such as Puppy Linux, Damn Small Linux and Tiny Core. [131062050030] |More mainstream distributions such as Debian, Ubuntu, Linux Mint and Fedora have lightweight "spins" available, which include either XFCE, LXDE or Fluxbox. [131062050040] |Coincidentally I was testing out Lubuntu today (an "unofficial" Ubuntu variant which uses LXDE) and Linux Mint Fluxbox. [131062050050] |It is also worth remembering that the applications which are installed with the distribution or which you install should also be lightweight if possible. [131062050060] |It would be counter-productive to install a lightweight distribution on your hardware and then expect it to run Firefox with two dozen tabs open as well as OpenOffice. [131062060010] |Well, unfortunately, I ended up giving up. [131062060020] |I did some testing under VirtualBox on my machine and had no problem installing and working with several distros with 256-384MB of RAM, yet I was unable to get any to install on that Celeron. [131062060030] |It's heading out for recycling. [131062060040] |The newer Linux kernels really don't seem to be tolerant of older hardware. [131062060050] |I had to recycle a couple of my own boxes recently as they just wouldn't take newer Linux versions (despite older ones working fine, and having plenty of hardware). [131062060060] |I guess the kernel team must have had to start dumping support for older hardware in order to move forward. :-( [131062070010] |Where can I find a log file that logs ports error messages in FreeBSD? [131062070020] |I looked in /var/log/ but there isn't any log files that records ports log, and I just found this person asking the same thing in other forum and get an answer which stating there is no such file. [131062070030] |If that's the case how should I read error messages? with more? [131062080010] |There's script(1) command which makes typescript of terminal session: [131062080020] |Then you can read the log: [131062080030] |If you omit the argument file, then script saves all dialogue in the file typescript. [131062080040] |Hope that helps. [131062090010] |Is it possible to stop a shutdown command? [131062090020] |Assuming you've just entered the command shutdown -h now (or something equivalent), is there realistically anything you can do (if you're quick enough) to prevent the machine shutting down? [131062100010] |You can run shutdown -c to cancel an already running shutdown. [131062110010] |If you are fast enough you can issue an init 2 (or whatever runlevel you want) and that will likely stop the shutdown. [131062110020] |Anything involving killing the shutdown command will fail as the command runs too quickly [131062110030] |I tried this with the script below and and even it's not fast enough to stop the shutdown [131062110040] |Where as interactively [131062110050] |the system stays up. [131062120010] |Rsync protocol name full path,not a module [131062120020] |Is it possible to name the full path to source directory in rsync command instead of the name of the module. [131062120030] |For example: [131062120040] |instead of : [131062120050] |(ftp is a module from /etc/rstncd.conf) [131062120060] |When trying the first version I get '@ERROR: Unknown module 'home'' [131062130010] |No, you can't do that using the rsync protocol ; it relies on modules to define access rights. [131062130020] |You could do it through SSH though : [131062140010] |How can I turn the behavior of `gedit sOmEtHiNg & disown` into the default behavior when calling gedit from the command line? [131062140020] |When I gedit files from the command line, it's always locking the terminal, and I'm tired of explicitly commanding a detached process for it. [131062140030] |I tried to alias gedit as something like gedit $* &disown, but either that's not the right syntax or you're not allowed to overload executable binary commands with aliases (tried using that in a .bash_aliases function, [131062140040] |), but it doesn't take. [131062140050] |So how do I make the command gedit test.txt not lock the originating terminal window? [131062150010] |Make sure, that the function editorz() is defined before the alias. [131062150020] |I've tried your approach and it worked without a problem. [131062160010] |That should work: are you sure your .bash_aliases is read? [131062160020] |(It's not a standard file, but it might be sourced by your ~/.bashrc. [131062160030] |If you're confused about .bashrc and .bash_profile, see Difference between .bashrc and .bash_profile.) [131062160040] |There's a bug in your function: it should be [131062160050] |Your version doesn't work on file names containing spaces or shell wildcards. [131062160060] |The function keyword is optional. [131062160070] |You can call the function gedit (and dispense with the alias altogether), but then you need to tell the shell that the call inside the function is to the command and not to the function: [131062160080] |Note that if you've accidentally started gedit in the foreground (i.e. locking your terminal), you can put it in the background by pressing Ctrl+Z in the terminal, and entering the command bg. [131062170010] |GNU Screen: new window name change [131062170020] |I can change the name of a window with Ctrl-a Shift-a. [131062170030] |Instead of editing several window names by hand, is there a way to have them automatically named after the current directory? [131062180010] |Make your shell change the window title every time it changes directory, or every time it displays a prompt. [131062180020] |For your ~/.bashrc: [131062180030] |Or for your ~/.zshrc (for zsh users): [131062180040] |For more information, look up under Dynamic titles in the Screen manual, or under “Titles (naming windows)” in the man page. [131062190010] |Selecting files that start with $LETTER, or a letter later than $LETTER in the alphabet [131062190020] |Suppose a directory contains the following files: [131062190030] |
  • afile1
  • [131062190040] |
  • afile2
  • [131062190050] |
  • bfile
  • [131062190060] |
  • cfile
  • [131062190070] |
  • ffile
  • [131062190080] |
  • ffile2
  • [131062190090] |
  • qfile
  • [131062190100] |
  • zfile
  • [131062190110] |I am looking for an easy way of selecting all the files which start with $LETTER, or start with a letter later than $LETTER in the alphabet. [131062190120] |A solution that could be easily modified to find files that start with $LETTER or files which start with a letter earlier than $LETTER in the alphabet would be useful. [131062190130] |E.g. [131062190140] |In the above list, with LETTER=c, I want to select "cfile, ffile, ffile2, qfile, zfile" [131062190150] |The above is a simplified example. [131062190160] |In the real world the directory will contain several thousand files. [131062190170] |In the end I used ls | tail -n${FUDGE_FACTOR}, where fudge factor was discovered manually, but am looking for a way to do this automatically. [131062190180] |I'm looking for a shell based solution to this (I use BASH, but solutions in other shells are welcome). [131062190190] |I'm aware that shell scripts probably aren't the best tool for this task, but am asking purely out of interest (to learn more about shell scripts), so please don't reply with answers in python/perl/lua/$FAVE_SCRIPTING_LANGUAGE [131062190200] |General comments on the limitations of shell scripts for this kind of task, and the best way to work around these limitations in reality (i.e. without my "must be a shell based solution" stipulation), would be most welcome. [131062190210] |Thanks [131062200010] |You could use a script like this: [131062200020] |this would select all files that start with c through q. [131062200030] |sample output: [131062200040] |it could also be expanded to limit the grep, in just about any way you can adjust a regex to do. [131062210010] |How about using the shell's built in globbing? [131062210020] |That worked in bash and ksh for me. [131062220010] |It's actually very simple: [131062220020] |If you want case-sensitivity: [131062220030] |This works because the shell performs parameter expansion before pathname expansion (i.e. globbing). [131062230010] |Is it possible to find out what program or script created a given file? [131062230020] |Three files have suddenly appeared in my home directory, called "client_state.xml", "lockfile", and "time_stats_log". [131062230030] |The last two are empty. [131062230040] |I'm wondering how they got there. [131062230050] |It's not the first time it has happened, but the last time was weeks ago; I deleted the files and nothing broke or complained. [131062230060] |I haven't been able to think of what I was doing at the time reported by stat $filename. [131062230070] |Is there any way I can find out where they came from? [131062230080] |Alternatively, is there a way to monitor the home directory (but not sub-directories) for the creation of files? [131062240010] |I don't believe there is a way to determine which program created a file once it exists. [131062240020] |You can watch for the file to be recreated, though, using inotify. inotifywait is a command-line interface for the inotify subsystem; you can tell it to look for create events in your home directory: [131062240030] |You probably want to run it with -m (monitor), which tells it not to exit after it sees the first event [131062250010] |You haven't got inotify so you can write a script that checks for the file in a loop: [131062260010] |You can watch everything that happens on a filesystem by accessing it over LoggedFS. [131062260020] |This is a stacked filesystem that logs every access in a directory tree. [131062260030] |Logging your whole home directory might slow your system down though. [131062260040] |You'll at least want to write a configuration file with stringent filters. [131062270010] |Good distro for a VM? [131062270020] |I want a lightweight Linux VM that I can run with VirtualBox on Windows so I can test how to deploy PHP apps, Mono apps, etc. [131062270030] |I don't need the UI and was thinking of going with the Ubuntu server ISO. [131062270040] |Is that a good choice? [131062270050] |I know I can also download a ready-made VM and it's tempting. [131062270060] |What does the community think? [131062280010] |Highly recommend ubuntu server. [131062280020] |The server mode will not put much that you don't really need, if anything. [131062280030] |I run ubuntu on several servers and have always been happy with it. [131062280040] |You'll also find tons of online support that is relevant to your distro. [131062280050] |Linux advice generally translates from one distro to the next, but directory paths are often different. [131062280060] |Ubuntu has a huge user base, which generally means an easier time figuring out what's wrong. [131062290010] |Go to the SuseGallery and do a quick search for Mono and you will find JEOS Mono ASP.net which is already setup for most of what you want. [131062290020] |It is already a VM, just download and go. [131062290030] |It is what I have just started using for some ASP.net migration trials on Windows with VirtualBox. [131062290040] |You will need to start Apache. [131062290050] |You will want to set up port forwarding, I used the following commands to open SSH and HTTP traffic: [131062300010] |I'd recommend using VMWare server and any distro (I happen to use CentOS). [131062300020] |The reason is that there are hundreds of pre-built VM images available on the VMware appliances website. [131062300030] |VMware's a good virtualisation platform and is free. [131062300040] |for example: Ubuntu LAMP stacks in various flavours. [131062310010] |Automatically mount encrypted home folder on login [131062310020] |I'm looking into encrypting my home folder with Truecrypt, and mounting it after I've logged in, which should be pretty straightforward. [131062310030] |However, it occurred to me that it should be theoretically possible to mount it as I'm logging in, as long as my account password is the same as my Truecrypt password. [131062310040] |Is there a way to get PAM to run a command on login and pass the command my password as an argument? [131062310050] |Or is there some other way to accomplish the same effect, without me needing to provide the password multiple times? [131062320010] |Here is a tutorial for PAM and truecrypt combination: http://blog.littleimpact.de/index.php/2008/08/19/automatic-encryption-of-home-directories-using-truecrypt-60a/ [131062330010] |Simple terminal emulator that supports cut/paste with other programs? [131062330020] |Coming from Mac OS X, I've enjoyed being able to cut/copy/paste text to and from its built in Terminal application. [131062330030] |Now, I am planning to migrate to a tiling window manager like scrotwm, xmonad, etc., but all I've got right now is xTerm. [131062330040] |I can't get it to accept cut/paste. [131062330050] |Is there another terminal emulator that accepts cut and paste from other programs' windows? [131062330060] |(by the way, I hope the encoding will support UTF-8) [131062340010] |Xfce Terminal Emulator, Konsole, and Gnome Terminal are good terminal emulators, and all are going to have tabs and keyboard shortcuts. [131062340020] |The decision is mainly going to come down to which toolkit you like and which dependencies you can live with. [131062340030] |Xfce Terminal is a personal favorite of mine. [131062340040] |It's simpler then the other two, but it's mainly missing profiles, which the other two have, which I don't use. [131062340050] |It uses the GTK+ widget toolkit, and it has some dependencies to Xfce. [131062340060] |Konsole is from the KDE project, and like all things KDE, it has tons of knobs to tweak. [131062340070] |At one time it had the distinction of being the fastest terminal emulator due to some intelligence code which cut down on the amount of text written to the screen while scrolling. [131062340080] |It relies on the QT widget toolkit, and has dependencies to KDE. [131062340090] |Gnome Terminal served as the basis for Xfce Terminal, so the preferences look the similar to Xfce Terminal. [131062340100] |The biggest difference is the inclusion of profiles. [131062340110] |I'm not sure what difference they would make, since I don't use them. [131062340120] |It's based on GTK+, and it has dependencies to Gnome. [131062340130] |I'm sure there are more term emulators out there that are lighter weight, but these are just the ones I'm most familiar with and the ones most Terminal.app like. [131062350010] |How do idiomatic Unix programs detect what prefix they are installed under? [131062350020] |If I install a binary with non-standard prefix, e.g. /opt/bin/foo, which needs some static files from /opt/share/foo, how does it find them? [131062350030] |Using back references relative to the executable (../share/foo)? [131062350040] |Hardcoded at compile time? [131062350050] |What's the idiomatic way for an application to handle variable installation prefix? [131062350060] |Should all directories be prefixed? (what about /var?) [131062360010] |Unded Unix, there is no portable way to detect from which location the binary was started, i.e. a variable installation prefix is compiled in. [131062370010] |I would say that the most common is detecting path provided by --prefix. [131062370020] |Different paths can be provided by different prefixes and there are separate for system config ("/etc"), library directory ("/usr/lib") etc. in autotools [131062380010] |It's common to hard-code such references at compile time, and perhaps provide a command line option or environment variable to override the compile-time default. [131062380020] |Often the program just remembers the location of one configuration file (typically under /etc) where any compile-time defaults can be overridden. [131062380030] |This approach makes most sense for open source software that is compiled by the same people that make the operating system, as part of a Linux distribution or BSD ports. [131062380040] |For applications distributed in a binary form, the usual approach is to locate the application binary from its zeroth argument. [131062380050] |By convention, the zeroth argument to execve (i.e. argv[0]) is the path to the binary (it's up to the caller, often a shell, to respect the convention). [131062380060] |If argv[0] doesn't contain any /, the application should perform $PATH lookup on it. [131062390010] |Tools used to compile the program such as GNU Autotools can take the value of the --prefix option given and put it into a header file as a define. [131062390020] |And in your code you'd just use PREFIX as part of your path names. [131062400010] |How to combine bash command grouping and pipe status [131062400020] |How do I combine bash command grouping and pipe status? [131062400030] |This is an example command group: [131062400040] |This is an example pipe status readout to go with the above: [131062400050] |In this example, the command group keeps mail spool free of warnings about "Removing leading /" from tar, being delivered via cron because they land on stderr (Unices lack a stdwarn and tar lacks a quiet option), while letting real errors pass through. [131062400060] |The pipe status readout makes sure that corrupt backup files are immediately removed, to prevent a later cleanup using a standard FIFO algorithm from removing older valid files. [131062400070] |But this example does not work. [131062400080] |In the above, the pipe status contains [1 0], that is, the exit code of grep and gzip, but not tar. [131062400090] |One attempt I tried was this: [131062400100] |But GROUPSTATUS is empty upon leaving the group. [131062400110] |(Note that by setting GROUPSTATUS to anything other than the pipe's status, eg. a literal of some sort, it can be verified that the variable does in fact escape the command grouping scope under normal circumstances.) [131062400120] |I've also tried if return from within the group can deliver the first pipe component's exit code to the outside, but return inside a command group just yields an error message from bash. [131062410010] |A simple way is to bypass the problem, is to put my_folder in a shell variable and remove the leading slash from it: [131062410020] |Otherwise, you can check ${PIPESTATUS[0]} inside the block and use false if it is not zero to signal the error to the outer process: [131062420010] |When you execute a pipeline, each pipe-separated element is executed in its own process. [131062420020] |Variable assignments only take effect in their own process. [131062420030] |Under ksh and zsh, the last element of the pipeline is executed in the original shell; under other shells such as bash, each pipeline element is executed in its own subshell and the original shell just waits for them all to end. [131062420040] |In your case, since you only care about all the commands succeeding, you can make the status code flow up. [131062420050] |If you want to get more than 8 bits of information out of the left side of a pipe, you can write to yet another file descriptor. [131062420060] |Here's a proof-of-principle example: [131062420070] |Once you get data on standard output, you can feed it into a shell variable using command substitution, i.e. $(…). [131062420080] |Command substitution reads from the command's standard output, so if you also meant to print things to script's standard output, they need to temporarily go through another file descriptor. [131062420090] |The following snippet uses fd 3 for things that eventually go to the script's stdout and fd 4 for things that are captured into $statuses. [131062420100] |If you need to capture the output from different commands into different variables, I think there is no direct way even in “advanced” shells such as bash, ksh or zsh. [131062420110] |Here are some workarounds: [131062420120] |
  • Use temporary files.
  • [131062420130] |
  • Use a single output stream, with e.g. a prefix on each line to indicate its origin, and filter at the top level.
  • [131062420140] |
  • Use a more advanced language such as Perl or Python.