Archive for
October, 2008
The PS1 environment controls the appearance of the BASH command line prompt. There are a variety of default prompts but they usually include username, hostname, and working directory. You can easily customize your prompt to display information important to you as well as add color and style formatting.
Here we can see the default prompt is [...]
Here is a good way to determine the hostname and IP address of the local machine in C.
You first have to grab the hostname with gethostname().
char hostbuf[256];
gethostname(hostbuf,sizeof(hostbuf));
Take the hostname and use it to grab the hostent struct with gethostbyname().
struct hostent *hostentry;
hostentry = gethostbyname(hostbuf);
Finally you have to take the hostent that is returned and pull out [...]
The ldd command allows you to view detailed information about library dependencies of dynamically linked programs and other shared libraries. ldd uses the runtime linker ld.so which reads the ELF formatted executable to generate the output. It is a helpful tool to have at your disposal when debugging broken programs.
Here ldd examines the ‘ls’ executable. [...]
One of the best features of the Linux command line is the ability to efficiently direct input and output to and from files and other programs.
Every program begins with 3 open file streams.
stdin (file descriptor 0) – input from the user, usually keyboard
stdout (file descriptor 1) – standard output that is displayed on the screen
stderr [...]
Understanding the difference between double versus single quotes is important when using BASH. Many times you may have seen them being used interchangeably. The basic difference is that variable names will be expanded within double quotes but not within single ones.
This example shows the normal output with no quotes.
$ echo $USER
ryan
As you can see [...]
Similar to the tail command which shows you the last few lines of a text file, the head command lets you to quickly view the first few lines.
The head command syntax.
head [options] file
By default head will show you the first 10 lines of a text file.
$ head textfile.txt
You can change the number of lines displayed [...]
Similar to the head command which shows you the first few lines of a text file, the tail command lets you to quickly view the last few lines of a text file. It also supports a monitoring mode which displays ongoing changes within the file.
The tail command syntax.
tail [options] file
By default tail will show you [...]
For backwards compatibility, many Linux distributions support both the older LinuxThreads implementation as well as the newer Native POSIX Thread Library (NPTL). By setting the LD_ASSUME_KERNEL environment variable you can tell the dynamic linker to assume that it is running on top of a particular kernel version. This will override the dynamic linker’s default [...]
Gentoo Portage makes it fairly easy to update all the installed packages on your system. The emerge and revdep-rebuild tools are powerful and make the process of recompiling everything much less painful than it sounds.
The emerge and revdep-rebuild commands require root privileges so switch to root or use sudo.
The first step is to synchronize your [...]
The file command identifies the type or format of a file. It is a very handy command that can show you how to approach a file when the format is unknown. There are a variety of tests that it uses to determine its type, these tests include a filesystem test, magic number test, and [...]