GNU/Linux
From WhyNotWiki
GNU/Linux edit (Category edit) .
This is for miscellaneous GNU/Linux tips, including how to use miscellaneous commands that don't require their own sections.
[edit] [Naming conventions (category)]
When I really want to be technically correct, I will say GNU/Linux. I believe that is the correct name for the operating system. (Linux itself is "just" the kernel -- albeit a very important part of the OS.)
[edit] When it's okay to call it Linux
However, oftentimes it is convenient to have a shorter name by which to refer to this OS. In those times, I think it is okay to just call it "Linux". As long as it's clear from context that you're referring to the whole OS and not just the kernel.
I mean, what else are you going to call it, if you want a short name? There's really no other decent alternative, and this shorthand name is pretty much ubiquitous.
And when talking to someone who is not terribly computer literate (or at least not very literate in matters GNU/Linux), it's not really worth it to correct everyone everywhere and to be pedantic about the "correct name". Maybe some of the time I'll be pedantic about this, but not always...
[edit] The problem of some things being common to all or most unices
Actually, that's not really a "problem" -- it's a good thing, most of the time -- but it just means that we have to settle the issue of how to refer to this class of operating systems that includes not only GNU/Linux, but also *BSD, Unix, and Mac.
Possibilities:
"Unices"
"Unix-like operating systems"
"Unixen"
http://www.google.com/search?q=unices
http://www.linux-foundation.org/en/OpenPrinting/Database/DatabaseIntro.
This database includes basic specifications for printers and details of how to make them go under normal unices that can run Ghostscript and/or filters like pnm2ppa. GNU/Linux, the BSDs and Mac OS X typify this category; users of other commercial unices can usually benefit from this information as well. The information here is not (very) useful for Windows users.
An alternative to Unices: "Unixen": Linus (1996-04-15). Unices are created equal, but ... (http://www.ussg.iu.edu/hypermail/linux/kernel/9604/1414.html).
Personally, I _want_ linux to be faster on everything, but when it comes to real life, I'd say that _any_ of the Free UNIXen are "fast enough".
[edit] Log files
[edit] Important log files/locations
dmesg
http://www.cyberciti.biz/faq/ubuntu-linux-gnome-system-log-viewer/.
/var/log/messages : General log messages
/var/log/boot : System boot log
/var/log/debug : Debugging log messages
/var/log/auth.log : User login and authentication logs
/var/log/daemon.log : Running services such as squid, ntpd and others log message to this file
/var/log/dmesg : Linux kernel ring buffer log
/var/log/dpkg.log : All binary package log includes package installation and other information
/var/log/faillog : User failed login log file
/var/log/kern.log : Kernel log file
/var/log/lpr.log : Printer log file
/var/log/mail.* : All mail server message log files
/var/log/mysql.* : MySQL server log file
/var/log/user.log : All userlevel logs
/var/log/xorg.0.log : X.org log file
/var/log/apache2/* : Apache web server log files directory
/var/log/lighttpd/* : Lighttpd web server log files directory
/var/log/fsck/* : fsck command log
/var/log/apport.log : Application crash report / log file
[edit] System Log Viewer (gnome-system-log)
http://www.cyberciti.biz/faq/ubuntu-linux-gnome-system-log-viewer/.
View log files using GUI tools using the GNOME System Log Viewer
System Log Viewer is a graphical, menu-driven viewer that you can use to view and monitor your system logs. System Log Viewer comes with a few functions that can help you manage your logs, including a calendar, log monitor and log statistics display. System Log Viewer is useful if you are new to system administration because it provides an easier, more user-friendly display of your logs than a text display of the log file. It is also useful for more experienced administrators, as it contains a calendar to help you locate trends and track problems, as well as a monitor to enable you to continuously monitor crucial logs.
You can start System Log Viewer in the following ways:
Click on System menu > Choose Administration > System Log
...
[edit] NTFS
https://help.ubuntu.com/community/MountingWindowsPartitions
Ubuntu can read and write files on your Windows partition. Windows partitions are normally formatted as NTFS [...].
[edit] Inspecting the system configuration
[edit] See what flavor/distribution/version of GNU/Linux you're running
$ uname -r 2.6.7-gentoo-r10
$ uname -r 2.6.16-1.2069_FC4smp [Fedora Core 4 Symmetric MultiProcessor]
# uname --help
Usage: uname [OPTION]...
Print certain system information. With no OPTION, same as -s.
-a, --all print all information, in the following order:
-s, --kernel-name print the kernel name
-n, --nodename print the network node hostname
-r, --kernel-release print the kernel release
-v, --kernel-version print the kernel version
-m, --machine print the machine hardware name
-p, --processor print the processor type
-i, --hardware-platform print the hardware platform
-o, --operating-system print the operating system
--help display this help and exit
--version output version information and exit
/proc/version seems to give you a little more information...
> cat /proc/version Linux version 2.6.16-1.2069_FC4smp (bhcompile@hs20-bc1-7.build.redhat.com) (gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)) #1 SMP Tue Mar 28 12:47:32 EST 2006
CentOS 4 (based on RHEL 4) says this:
> cat /proc/version Linux version 2.6.9-023stab046.2-enterprise (root@rhel4-32) (gcc version 3.4.5 20051201 (Red Hat 3.4.5-2)) #1 SMP Mon Dec 10 15:22:33 MSK 2007
Also this, in the case of Red Hat/Fedora:
> cat /etc/redhat-release Fedora Core release 4 (Stentz)
[edit] dmesg: print out the bootup messages
dmesg
[edit] How do I figure out which process is using a certain port?
Or: I'm getting a "cannot bind; address/port already in use" error and I'm not sure which process to kill because I don't see anything listed by ps that looks like it would be that port...
(Lance showed me this trick...)
sudo netstat -lnp or sudo netstat -pean
Look for the part number that is supposedly already in use; beside it, it show you which process id as well as which program that has tied up / is using that port. And then kill it:
kill -9 21457
[edit] uptime -- "Tell how long the system has been running."
man uptime
uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.This is the same information contained in the header line displayed by w(1).
System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.
[load average (category)]
[edit] System administration
[edit] Monitoring
This is just a little script I put in my crontab to collect stats about load, etc. It could probably be better, but hey, it's better than nothing!
#!/bin/bash
log_dir=/var/...
mkdir -p ${log_dir}
now=`date +%Y%m%dT%H%M`
echo -n "$now: " >> ${log_dir}uptime
uptime >> ${log_dir}uptime
echo "-----------------------------------" >> ${log_dir}ps
echo $now >> ${log_dir}ps
ps aux | grep 'PID\|mongrel\|rails' >> ${log_dir}ps
echo "-----------------------------------" >> ${log_dir}free
echo $now >> ${log_dir}free
free -m -o >> ${log_dir}free
echo "-----------------------------------" >> ${log_dir}top
echo $now >> ${log_dir}top
top -n1 | head -n 17 | sed 's/\[H//g' | sed 's/\[6;1H//g' >> ${log_dir}top
# /\ removes the codes which position the cursor at the top of screen
[edit] Problem: Too many distributions
[edit] Solution: Standardize things
(This description of solutions also implicitly lists some of the problems that can and do result from having many competing choices: fragmentation, incompatibility, lack of interoperability, vendor lock-in, applications that lack portability, ...)
http://www.linux-foundation.org/en/LSB.
The Linux Standard Base delivers interoperability between applications and the Linux operating system. Currently all major distributions comply with the LSB and many major application vendors, like MySQL, RealNetworks and SAP, are certifying. The LSB offers a cost-effective way for application vendors to target multiple Linux distributions while building only one software package. For end-users, the LSB and its mark of interoperability preserves choice by allowing them to select the applications and distributions they want while avoiding vendor lock-in. LSB certification of distributions results in more applications being ported to Linux and ensures that distribution vendors are compatible with those applications. In short, the LSB ensures Linux does not fragment.
If you are an end user looking for Linux distributions that support open standards, please see our list of LSB certified products.
If you are a developer looking to build portable Linux applications that will work on these distributions, please see the Linux Developer Network.
[edit] Which distro should I use?
Ah yes, that question... one of the question that makes me hesitant to seriously consider switching completely to GNU.
So many choices... if only there were an obvious best choice!
Anyway, there isn't -- each one has its share of pros/cons -- so the best I can do is listen to the advice/recommendations of people I trust.
[edit] Recommendations
Ezra recommends Ubuntu for the desktop and Gentoo for the server.
I like Ubuntu.
[edit] nohup: Run a command immune to hangups
`nohup' runs the given COMMAND with hangup signals ignored, so that the
command can continue running in the background after you log out.
Synopsis:
nohup COMMAND [ARG]...
If standard input is a terminal, it is redirected from `/dev/null'
so that terminal sessions do not mistakenly consider the terminal to be
used by the command. This is a GNU extension; programs intended to be
portable to non-GNU hosts should use `nohup COMMAND [ARG]... </dev/null'
instead.
If standard output is a terminal, the command's standard output is
appended to the file `nohup.out'; if that cannot be written to, it is
appended to the file `$HOME/nohup.out'; and if that cannot be written
to, the command is not run. Any `nohup.out' or `$HOME/nohup.out' file
created by `nohup' is made readable and writable only to the user,
regardless of the current umask settings.
If standard error is a terminal, it is redirected to the same file
descriptor as the (possibly-redirected) standard output.
`nohup' does not automatically put the command it runs in the
background; you must do that explicitly, by ending the command line
with an `&'. Also, `nohup' does not alter the niceness of COMMAND; use
`nice' for that, e.g., `nohup nice COMMAND'.
[edit] daemontools
[edit] Dan Berstein's
http://cr.yp.to/daemontools.html
[edit] How I installed daemontools?
[root@studebaker ~]# yum install gcc
Put this script into file [root@studebaker ~]# ./install_daemontools.sh
#!/bin/sh
#
# install daemontools on fedora/redhat linux
#
# Mike Jackson <mj@sci.fi> 5 NOV 2005
#
#
mkdir /package
chmod 1755 /package
cd /package
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
tar xzvf daemontools-0.76.tar.gz
rm -f daemontools-0.76.tar.gz
cd admin/daemontools-0.76/src
wget http://www.qmailrocks.org/downloads/patches/daemontools-0.76.errno.patch
patch < daemontools-0.76.errno.patch
cd ..
package/install
That script downloads, compiles, and installs it.
After that, this process will be forever running, watching over everything: root 5069 0.0 0.0 1564 336 ? S 10:54 0:00 svscan /service
[edit] How do we set up a new service?
Create a file /service/whatever/run: -rwxr--r-- 1 root root 126 Mar 16 11:24 run
That's it! svscan automatically starts the service as soon as it sees that run command.
[edit] How can I verify that it's running?
> ps aux | grep whatever > svstatus /service/whatever/
[edit] freedt: Free Daemontools
http://offog.org/code/freedt.html
- freedt is a reimplementation of Dan Bernstein's daemontools under the GNU GPL, sharing no code with the original implementation.
[edit] init.d
You can write init.d scripts in bash or even [Ruby (category)]...
Peter Cooper. How to create a UNIX /etc/init.d startup script with Ruby (http://www.rubyinside.com/how-to-create-a-unix-etcinitd-startup-script-with-ruby-250.html).
Or see my example here: http://svn.tylerrick.com/public/ruby/init.d
[edit] Miscellaneous
[edit] [Troubleshooting (category)] Can’t write viminfo file $HOME/.viminfo when doing sudo vim on Debian/Ubuntu
I first noticed this on an Ubuntu box on which I was given root. Whenever I would sudo vim something, it would not have syntax highlighting turned on, even though /root/.vimrc had syntax on. In fact, it looked like it wasn't reading/using the .vimrc file at all. And when I would exit vim, I would get this error:
E138: Can’t write viminfo file $HOME/.viminfo!
[Solution (category)]:
Add env_reset to the Defaults line in your /etc/sudoers file. For example:
Defaults whatever,some_thing,env_reset
Credit for solution: http://stateless.geek.nz/2006/01/24/sudo-upgrade-from-debian-security-changes-env-handling/
[edit] What does it need to do to win in the OS desktop market?
Mono developer brings the Ribbon interface to Linux (http://arstechnica.com/journals/linux.ars/2007/08/30/mono-developer-brings-the-ribbon-interface-to-linux).
danchr,August 30, 2007 @ 09:40PM
I can't help but wonder, what were their thoughts prior to copying Microsoft? Do they copy Microsoft uncritically, or do they copy Microsoft because they offer the best solution?
It strikes me as an odd choice if the goal of the Mono developers is to copy Microsoft. Copying will mean that they will always be one step behind whomever they are copying. I wish Linux could offer a serious alternative to Microsoft, and to do so, they would have to offer something clearly superior. Being similar, but better, won't cut it. However, it seems that most Linux developers are so entrenched in our Microsoft world that they don't look elsewhere for inspiration. Maybe the Ribbon is a good idea; maybe it isn't. Did they analyse it prior to copying it? Did they do any usability studies prior to implementing it? Where there any reasons for implementing it other than saying “We're better than Microsoft, and can do whatever they do!” to themselves?
Abolishing the menu bar is a decision which will effect users significantly. Such a decision should not be taken lightly and should only be taken if the replacement is clearly superior. Fundamentally, developers aren't the ones which should be making such a decision; most developers have little experience and knowledge when it comes to usability. Developers should be following the directions of usability experts in an area such as this. Did they do so?
This strikes me as yet another instance of the fundamental problems of the Linux platform: the lack of goal. Or rather, that the apparent goal of being a better Windows than Windows is fundamentally flawed. If you want to create a good user interface, you might want to look elsewhere for inspiration. The products of Microsoft aren't generally renowned for optimum usability. Niche operating systems like Mac OS X might offer suggestions, and even more obscure operating systems might offer alternate approaches which could make Linux diversify itself. For instance, when GNOME chose to promote the spatial metaphor for the file manager, it was a conscientious and bold — but also risky — decision. Such decisions should be applauded.
Personally, I prefer Linux to Microsoft Windows. However, it seems that Linux is positioning itself as a discount operating system. It's not sufficiently superior to the other major systems to be chosen on merit alone, and thus its price (or lack thereof) is its main feature. I find that sad.
Mac OS X is much more expensive to obtain than Linux, yet it has a higher market share. I'm certain that sexy hardware and better marketing aren't the only reasons for this. Please, make me tempted by your OS; I beg you!
(For the record, I use Mac OS X myself.)
August 31, 2007 @ 01:23AM
Why settle for discount? Why settle at all? Why isn't Linux more competitive, and why doesn't it have any bullet points where it blows Windows Vista away?
While there is little innovation in basic UI concepts, there's a lot of innovation in concrete UI. Additionally, some of the old concepts might be worth reconsidering. For instance, Mac OS X has had pervasive drag and drop for a long time; maybe this an area where Linux could improve?
[edit] History
http://liw.iki.fi/liw/texts/linux-anecdotes.html
