C language development
Friday 27 January 2012 at 09:10 am. Used tags: unix
Development commands
cc This will run whatever C compiler is installed on the system. On most Linux installations, this will run the GNU C compiler (GCC), which can also be run by typing gcc.
lint Syntax: lint filename.c lint is a C code checker, meaning it scans C code for coding problems. These do not necessarily have to be errors; It also scans for inefficient or non-portable coding techniques. XWindows commands xf86config This runs the configuration utility for XFree86. You want to do this before you run XFree86, so you can set it up (particularly the parts relating to your monitor). xf86config modifies a file called XF86Config, which is the actual X configuration file. (Note that the filename differs from the command only by the capital X, F, and C.)
xf86config is the standard Linux command for configuring XWindows. It's text-based and it asks a lot of questions, but it is the tool that's supposed to be available on every Linux installation. Depending on your distribution, there may be other tools available. In particular, Red Hat has a menu-based XWindows configuration utility called Xconfigurator, which can be run directly from the command line, and is also available as an option from Red Hat's own setup utility. Other distributions may have their own special X configuration programs. xorgconfig Same as xf86config, except this command applies if you're using the X.Org version of X instead of XFree86. xorgconfig configures your /etc/X11/xorg.conf file.
SuperProbe SuperProbe is an uncharacteristically boastful Linux command which simply probes for your video hardware. This is important since XWindows tends to be so dependant on knowing the details of your particular model of video card and monitor. SuperProbe will tell you (or attempt to tell you) the manufacturer of your video card, what kind of video chipset it has, and how much RAM it has. This information is certainly helpful if you don't know it, and it tends to be useful when you are setting up XWindows. xwmconfig Short for X window manager configuration, this command lets you select your window manager for XWindows. XWin comes with Tab Window Manager (TWM), a rather basic WM. Another popular WM is Sawfish.
xwmconfig creates a file in the /etc/X11/xinit directory called xinitrc. This file is actually just a link to another file, and that other file is the X Windows initialization script. For example, the rc file for TWM is xinitrc.twm, and if you choose TWM with xwmconfig, then you will find that the xinitrc file is a link to xinitrc.twm. switchdesk switchdesk lets you select your desktop for XWindows. This is, for example, how you switch from GNOME to KDE, or vice-versa. Do not confuse this with your window manager; twm and Sawfish are examples of window managers. GNOME and KDE are desktops; they are NOT window managers. startx This starts X. (startx is actually just a shell script that calls xinit, the real X initializer. However, startx passes a couple of variables to xinit, so you should use startx instead of typing "xinit" directly.) xhost xhost is the security access control utility for XWindows. It simply sets what clients are allowed to connect to your X system, and which are not. If you don't care about security too much and just want to allow everybody access to your X system, simply type the following command to allow all access: xhost + Text editors ed This is the "basic" text editor which comes with Linux by default. It's a line-based editor, like the old edlin which used to come with MS-DOS before Microsoft realized everybody wanted a full-screen editor. Hardly anybody who does much text editing with Linux uses ed. vi Short for "visual", this is a full-screen editor which is fairly simple to use, and does exactly what you want it to do without any frills. Most people like vi the best.
Note that in Linux, vi is usually implemented as elvis, a new-age text editor that works like the classical Unix vi but is intended to replace it. However, the "vi" command is usually linked to elvis, meaning that typing either "vi" or "elvis" in Linux should work. emacs A big program, EMACS (short for Editing MACroS) is famous for being a highly feature-laden text editor. It has more features than any program needs, and indeed, most people find EMACS too sophisticated for their tastes. EMACS doesn't usually come with a basic Linux installation and must be installed as a separate package. (For some quick info on EMACS keystrokes, check "EMACS Keystrokes", below.) pico pico is a relatively new text editor. Obviously it is not as well-known as vi or emacs, but it has become quite popular in its own right. It's supposed to be easier to use. It uses several basic keystrokes which are displayed on-screen (instead of requiring you to remember them). Newbies may want to try pico first (and last). Debian-specific commands (Debian is a distro of Linux, in case you wondered.) dpkg dpkg is Debian's package manager. It'll unpack Debian binary files (which have a .deb extension.) dselect dselect is Debian's user-friendly package manager. It has a full-screen interface, unlike dpkg, which is a command-line utility.
Directories and files of interest /home/username Every user on a Linux system has a "home directory", their own directory where they're supposed to keep their stuff. This directory is normally in /home/username. For example, if your username is JimmyTheHand, your home directory would probably be /home/JimmyTheHand. (Before somebody asks, the reference to "Jimmy The Hand" is from Betrayal At Krondor. It just came to me as I was trying to think of a random name.) /etc/motd This is the MOTD, or "Message Of The Day". This is the message which users see immediately after they log into the system. (From the name, apparently this is supposed to change daily, but it usually doesn't.) /etc/issue This file gets shown immediately before a login prompt. This is different from motd in that motd gets shown right after anyone logs in, while issue gets shown just before. /etc/inetd.conf This file lists all servers running on the system (that is, all ports which it will receive connections on, and what it will do on them). By default, for example, FTP (port 21) and Telnet (port 23) servers are set up, so people can log in through those. /etc/fstab is your file system table. It lists all the default installed file systems, and the partitions and directories they're on. /etc/inittab stores information on the different runlevels available. /etc/hosts is your system's host table. It stores the names of computers on the LAN. This works sort of like DNS, except that instead of running a dedicated name server, it's just a table of addresses and corresponding names stored in one file. Once you put a system and its address in here, you can use that system's name in place of its address. For example, if you named a computer joe, you could just type "ping joe" or "telnet joe". /var/log is generally where log files go. Yes, all of them. /var/spool/mail This is the directory where everyone's mail on the system gets stored. The person's mail is stored as a file with their username. For example, someone with a username of DogDoo would have his/her mail in a file called DogDoo in this directory. .profile This file, if you have it, exists in your home directory, and is basically equivalent to DOS' autoexec.bat file.
Anything in .profile will be executed when you log in. Each user has their own commands which they might want to run automatically when they log in, so everybody gets to set up their own .profile file. (See also rc.S under "rc.d files", below.) /etc/lilo.conf This file, as you might guess, is your LILO (LInux LOader) configuration. LILO is the program which runs when you boot up your computer and lets you choose between booting into Linux or Windows. (Apparently, however, even if Linux is your *ONLY* operating system, you still need to install LILO to load it. Or so I've heard.) lilo.conf specifies what partitions exist and what operating systems are installed on them, as well as what message to display on bootup and how long to wait for an answer before defaulting to one OS. /etc/isapnp.conf This is the isapnp configuration file. /vmlinuz This file is your kernel. The kernel is the heart of the operating system, the main part of it which loads before anything else. /lib/modules stores your system's modules. /etc/ppp This directory holds your PPP configuration info, including the file pppscript, which is the script used when connecting to your ISP. /etc/resolv.conf lists the IP addresses of the DNS servers to use when resolving hostnames while a PPP connection is active.
/etc/HOSTNAME contains your system's hostname. See the hostname command for more info. /usr/src/linux/Documentation/Configure.help You'll only have this file if you've installed the Linux kernel source code. It lists all the options available during kernel configuration, along with explanations. I *highly* recommend reading this file and using it as a reference if you're re-compiling your kernel, because the re-compilation process asks you a *lot* of questions about what you do and don't want included in the kernel, and most people probably aren't sure about what half of the options mean. /etc/XF86Config contains XWindows configuration information (including what frequencies/resolutions your video hardware can support), assuming you have X installed, of course. /etc/passwd is where all the system's user accounts are stored, along with their (encrypted) passwords. /etc/shadow is usually where the system's "shadowed" passwords are kept. (Shadowed passwords are those stored separately from the main /etc/passwd file for security.) /etc/localtime is not actually a file, but a link to a TZif (Time Zone info) file in the /usr/share/zoneinfo directory, which configures what time zone you're in. /etc/syslog.conf controls what kind of logging is done by the system, and where the log files are kept. /etc/mail/sendmail.cf is your Sendmail configuration file. /etc/group contains a list of all the user groups on this system, along with their identifying numbers. /etc/httpd/conf/httpd.conf is the configuration file for the HTTP daemon (a.k.a. the web server). rc.d files The directory /etc/rc.d contains several scripts which do stuff. The functions of a few of them are listed here. rc.S This is the System Initialization Script. It's run every time you boot up Linux. Like .profile, then, it's akin to DOS' AUTOEXEC.BAT. (NOTE: Don't fool around with this if you don't know what you're doing. Basically, stay away from it entirely, because it runs before any login prompt is displayed, and many programs won't like trying to run without someone logging in first. If you want to make a program run automatically after you log in, it's much safer to use .profile.) rc.modules This lets you specify what modules are loaded on bootup. (Modules might be device drivers or other things which you want to load automatically.) rc.font This lets you choose what font is used for your console. rc.gpm This is the gpm initialization script. gpm (General Purpose Mouse) is the mouse driver for Linux. ~/. files
The ~ symbol represents your home directory in Linux. Thus, these are files which go in your home directory, and which have filenames that begin with a period. (In Linux/Unix, a filename which begins with a period is supposed to be a "hidden" file, which is not meant to show up in normal directory listings and which you are not supposed to mess around with.) .bashrc This is the rc (resource configuration) file for the bash shell. Commands in this file will be automatically run when bash starts. .cshrc This file works just like .bashrc, except it's for csh (the C shell). .login Regardless of what shell you are using, the commands in this file execute when you log in. .rhosts (Again, I wish to remind you that this file goes into your home directory). This lists accounts which you own on other computers. It lets you log into the account (on the machine which stores the .rhosts file) without using a password. It is to be used for your accounts only; Since it is in your home directory, each user has his or her own .rhosts file. This file works with the "r" commands, like rlogin and rsh. Device files Linux refers to all the system devices as file-like pointers in the /dev directory. Here are some of the more important ones: /dev/ttyS0 = COM1 serial port /dev/ttyS1 = COM2 serial port /dev/ttyS2 = COM3 serial port /dev/ttyS3 = COM4 serial port /dev/console = currently selected console /dev/ttyx = virtual console (where x = number of console) /dev/null = data sink (anything sent to here disappears) /dev/fd0 = first floppy drive /dev/fd1 = second floppy drive /dev/hda = first IDE drive /dev/hdb = second IDE drive /dev/hda1 = first IDE hard drive, first partition /dev/hda2 = first IDE hard drive, second partition /dev/hdb1 = second IDE hard drive, first partition /dev/hdb2 = second IDE hard drive, second partition /dev/sda = first SCSI drive /dev/sdb = second SCSI drive /dev/sda1 = first SCSI hard drive, first partition /dev/sda2 = first SCSI hard drive, second partition /dev/sdb1 = second SCSI hard drive, first partition /dev/sdb2 = second SCSI hard drive, second partition /dev/st0 = first rewinding SCSI tape drive /dev/st1 = second rewinding SCSI tape drive /dev/nst0 = first non-rewinding SCSI tape drive /dev/nst1 = second non-rewinding SCSI tape drive /dev/ht0 = first rewinding IDE tape drive /dev/ht1 = second rewinding IDE tape drive /dev/nht0 = first non-rewinding IDE tape drive /dev/nht1 = second non-rewinding IDE tape drive /dev/mouse = mouse /dev/audio = sound card /dev/eth0 = first Ethernet device (usually a NIC) /dev/eth1 = second Ethernet device /dev/tr0 = first Token Ring device /dev/tr1 = second Token Ring device /dev/fddi0 = first FDDI device /dev/fddi1 = second FDDI device /dev/loop1 (and so on) are "loop devices" (see the losetup command) A note on hard drives and IDE devices: The /dev/hd devices are actually IDE devices, not specifically hard drives. If you have an IDE CD-ROM drive, it'll also have an "hd" device name. In this case, don't use a number on the end for a partition (since CDs don't have partitions). Instead, the drive will just use the letter.
For example, usually your first CD-ROM drive is /dev/hdc and you second one (if you have one) is /dev/hdd. Actually, here's a little note on how Linux numbers hard disk partitions... The *partitions* will be numbered from hda1 to hda4 (on hda), while logical drives within the *extended* partition will be numbered from hda5 onward. For example, on my hard disk, my first primary partition is FAT16, the second is my primary Linux partition, and the third is my Linux swap partition. These partitions are labels hda1, hda3, and hda4, respectively, in Linux. What's hda2, then? It's my extended DOS partition. The extended DOS partition has two logical FAT16 drives in it. These drives are hda5 and hda6 in Linux. Confusing? Yes. Also, here's an explanation of the /dev/random and /dev/urandom devices. (The following text was ripped from the comments in the Linux kernel source.) This routine gathers environmental noise from device drivers, etc., and returns good random numbers, suitable for cryptographic use. Besides the obvious cryptographic uses, these numbers are also good for seeding TCP sequence numbers, and other places where it is desirable to have numbers which are not only random, but hard to predict by an attacker. /dev/random is suitable for use when very high quality randomness is desired (for example, for key generation or one-time pads), as it will only return a maximum of the number of bits of randomness (as estimated by the random number generator) contained in the entropy pool. The /dev/urandom device does not have this limit, and will return as many bytes as are requested. As more and more random bytes are requested without giving time for the entropy pool to recharge, this will result in random numbers that are merely cryptographically strong. For many applications, however, this is acceptable. A brief tutorial on using ipchains
The first ipchains command you should know is ipchains -L. This will list all the current rules. (Yes, the L has to be capitalized.) Next, experiment with ipchains -N. This is the command to make a new user-defined chain. For example, typing ipchains -N newchain will make a chain called newchain. After typing it, use ipchains -L to confirm it and see your new chain in the list. ipchains -X is the opposite of -N. Type ipchains -X newchain to delete newchain. Now it's time to do some rule editing. First of all, type ipfwadm. This appears to be some kind of command built into Linux which sets you up with a basic ruleset. After you type it, use ipchains -L once again and notice that your ruleset has gone from three lines to about a screenful. Take a look at the rules that you have; Most of them probably look like gibberish right now, but you'll learn what everything means later. Now let's try learning how to change those rules. The command syntax for changing a rule with ipchains is: ipchains -R chainname rulenum Where chainname is the chain name, and rulenum is the number of the rule you want to change. Note that this command, on its own, does absolutely nothing; It specifies what rule you want to modify, but does not mention what modifications you want to make to it. For now, let's try turning logging on for some rules, so you can see logs of some IP traffic. (Logging is what ipchains is probably used most for anyway.) To turn on logging for a rule, you need to specify the -l switch to ipchains (that's a hyphen and a lowercase letter L, as in log).
Now, you should know that ipchains doesn't actually provide you with a way to modify a rule; Technically, you replace rules, you don't change them. (The R in -R stands for replace.) This means that when you change a rule, you have to specify the *entire* rule's information, or anything that's already there will be lost. You can't just add one part to a rule. Check out the first rule in your ipchains -L output. It should look like this: ACCEPT all ---f-- anywhere anywhere n/a The leftmost column is the rule's target; As you can see, the target in this case is ACCEPT. So, let's suppose you want to turn on logging for this rule. You would use the -R command to replace it with a new one, you'd use the -l flag to turn on logging for it, and you'd also need to specify the target name again, or else it would just be set to nothing. To specify a target name, use the -j flag. So, the complete command that you'd use to turn on logging for this rule is: ipchains -R input 1 -l -j ACCEPT Did you get all that? The -R tells ipchains to replace the rule, "input" is the name of the chain, 1 is the rule number (the first rule in the input chain), -l switches logging on, and the -j ACCEPT part makes sure the target remains as ACCEPT. ipchains logs to /var/log/messages. If you want to check the data it logs, look there. There's more to ipchains than this, but that's the basics; If you want more you can always check the manpage for ipchains (by typing man ipchains of course). Have fun. ipchains' successor, iptables, seems to be remarkably switch-compatible with ipchains. The -L, -N, -X, and -R commands work almost in an identical fashion. Use the -A switch to add new rules to existing chains. (For example, type iptables -A newchain to add a new rule to the chain called "newchain".) The only significant difference, as far as this brief introduction goes, is that iptables does not support the -l switch to turn on kernel logging; Instead, you must specify a targetname of LOG. So to turn on logging in the first rule of the INPUT chain, you'd type: iptables -R INPUT 1 -j LOG Of course, you can type man iptables to get more info on iptables. Again, have fun.
Installing programs in Linux When you get a Linux program, it's usually in a .tar.gz (or .tgz) file, which is a TAR archive that has been further made into a GZIP archive. Before anything else, you must uncompress these archives, just like you need to uncompress a ZIP in DOS before you can use the files in it. The usual way of handling .tar.gz files in Linux is with this command: gzip -cd filename | tar xfv - (Where filename is the filename of the .tar.gz file.) The x option tells tar to extract the archive (it must be the first option). The v option tells tar to be verbose (so it provides more info). Note that newer versions of tar have a "z" option which lets you filter the file through GZIP first, which allows you to just use a plain tar command instead of having to pipe gzip output through tar. So, the new method for extracting .tar.gz files in Linux is with this command: tar xfvz filename Much simpler, isn't it? Again, filename is the filename of the .tar.gz file. Because of all the varieties of different Linux kernels and configurations, rarely do you just download a program and run it, as you would do with DOS. Rather, Linux programs, once you unzip them into some directory, are usually installed using three commands. In the order you should run them, they are: ./configure make make install The "configure" command configures the program to your system in preparation for building it. It creates makefiles in preparation for the make command, and custom-creates those makefiles for your system. Although the configure command can potentially take several parameters (depending on what program you're configuring), you can usually run it with no parameters. The most common parameter used with configure is --prefix, which allows you to specify a directory into which the program should be installed. For example, if you wanted to install the program into /usr/bin, you would type: ./configure --prefix=/usr/bin Often, you might want to install a program into your home directory, and you can simply use the tilde for a --prefix parameter to indicate this: ./configure --prefix=~ The "make" command builds the program, compiling the source code into binary executables. Finally, "make install" actually installs those executables. This is the standard procedure for installing any Linux program which comes in source code form. A final, fourth command is optional: "make clean". This command usually removes any temporary files created during the previous three commands. This is not necessary for the program to function, but it gets rid of the files you don't need anymore and saves some disk space, so it's good practice to run it when you're done.