Author: Ryan

You can find the IP address of your system at the command line by using the ifconfig command. The ifconfig command will show you information on all your network interfaces. If no arguments are given ifconfig displays the status of the currently active interfaces. You have to run this command as root or use sudo. # ifconfig wlan0 Link encap:Ethernet HWaddr a1:b2:c3:d4:e5:f6 inet addr:192.168.2.11 Bcast:192.168.2.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1492 Metric:1 RX packets:4007 errors:0 dropped:0 overruns:0 frame:0 TX packets:4246 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3292271 (3.1 MiB) TX bytes:994922 (971.6 KiB) Your IP address is displayed in…

Read More

Normally in Gentoo you would want to create an init script via rc-update to start a service at boot. However if there are a few miscellaneous commands you would like to run you can add them to local.start. The local.start init script is similar to rc.local in other distributions. It is the last init script to be run after all other services have been started at the end of the boot process. Add your commands to local.start file located here. /etc/conf.d/local.start You can also make commands run when the system is shutdown. These commands should be placed in local.stop located…

Read More

The ext3 file system forces an fsck once it has been mounted a certain number of times. By default this maximum mount count is usually set between 20-30. On many systems such as laptops which can be rebooted quite often this can quickly become a problem. To turn off this checking you can use the tune2fs command. The tune2fs command utility operates exclusively on ext2/ext3 file systems. To run these commands you must run the command as root or use sudo. You must also make sure that your filesystem is unmounted before making any changes. If you are doing this…

Read More

At some point you may have the need to remove all lines within a text file that match a certain pattern. Accomplishing this is easy with the sed command. Here is the command format. $ sed -i ‘/PATTERN/ d’ file.txt The ‘-i’ option allows you to edit the specified file in place. PATTERN is a regular expression d is a command which instructs sed to delete the line if it matches the PATTERN Here is an example. $ cat file.txt one two three one hundred We want to remove the lines containing the word “one” $ sed -i ‘/one/ d’…

Read More

The lsof command stands for “list open files”. It can show all open files as well as sockets, memory mapped libraries, directories, pipes, and network sockets. It is an incredibly powerful tool which you can use to gather detailed information about what is happening on your system. If you run lsof as a normal user you will be limited to only the the processes owned by that user. To get system wide results you must run the command as root or use sudo. Running the command by itself will show information for all active process on the system. # lsof…

Read More

RPM stands for Red Hat Package Manager. There are a variety of distributions besides Red Hat that use RPM to manage packages including Fedora, Mandriva, SUSE, CentOS, and Yellow Dog Linux among others. RPM uses a database to keep track of what packages have been installed on the system and where they are located. This functionality allows you to easily query, install, upgrade, and remove packages from your system. RPM packages are distributed in the following format “<package>.<version>.<architecture>.rpm” Check the package information. $ rpm -qi mypackage.1.2.3.x86_64.rpm List the files that will be installed. $ rpm -ql mypackage.1.2.3.x86_64.rpm Install an RPM…

Read More

The LD_LIBRARY_PATH environment variable contains a colon separated list of paths that the linker uses to resolve library dependencies of ELF executables at run-time. These paths will be given priority over the standard library paths /lib and /usr/lib. The standard paths will still be searched, but only after the list of paths in LD_LIBRARY_PATH has been exhausted. The best way to use LD_LIBRARY_PATH is to set it on the command line or script immediately before executing the program. This way you can keep the new LD_LIBRARY_PATH isolated from the rest of your system. $ export LD_LIBRARY_PATH=”/list/of/library/paths:/another/path” $ ./program In general…

Read More

The find command allows you to recursively search and locate files on your system based on specific criteria. You can search by name, owner, group, type, permissions, date, as well as many others. The find command uses the following format: find [search_path(s)] [search_criteria] The following is the most basic way to run the find command. It will list every file and directory within your current working directory. $ find This produces the same output but you are specifically listing the current directory as the search path. $ find . To search the entire filesystem, specify root as the search path…

Read More

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 “username@hostname working_directory $”. ryan@workstation ~ $ You can echo the PS1 environment variable and see the character codes which are used to create the output. ryan@workstation ~ $ echo $PS1 \u@\h \w \$ Here is a list of all the special character codes you…

Read More

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 IP address. It is in network byte order, so you have to convert it to a string with inet_ntoa(). char * ipbuf; ipbuf = inet_ntoa(*((struct in_addr *)hostentry->h_addr_list[0])); Put all this together into a working programs. #include <stdio.h>…

Read More