Archive for
October, 2008

Customize the BASH PS1 command prompt

by
Ryan
on
October 19, 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 [...]

Read More
No Comments
bash

Display hostname and IP address in C

by
Ryan
on
October 18, 2008

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 [...]

Read More
3 Comments
C

View dynamic library dependencies with ldd

by
Ryan
on
October 17, 2008

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. [...]

Read More
No Comments
commands

I/O redirection in BASH

by
Ryan
on
October 16, 2008

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 [...]

Read More
No Comments
bash

Single versus double quotes in BASH

by
Ryan
on
October 15, 2008

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 [...]

Read More
1 Comment
bash

Display the first part of a file with head

by
Ryan
on
October 14, 2008

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 [...]

Read More
No Comments
commands

Display the last part of a file with tail

by
Ryan
on
October 14, 2008

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 [...]

Read More
No Comments
commands

Select threading implementation using LD_ASSUME_KERNEL

by
Ryan
on
October 13, 2008

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 [...]

Read More
No Comments
system administration

Update your entire Gentoo Linux system

by
Ryan
on
October 10, 2008

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 [...]

Read More
No Comments
gentoo

Determine file type with the file command

by
Ryan
on
October 8, 2008

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 [...]

Read More
No Comments
commands
Copyright 2008-2010 WiredRevolution.com. All rights reserved.