Author: Ryan

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. The output displays the dependencies as well as how they will be resolved if run with the current environment. $ ldd /bin/ls linux-vdso.so.1 => (0x00007fffe0dfe000) librt.so.1 => /lib/librt.so.1 (0x00002b4eca08e000) libacl.so.1 => /lib/libacl.so.1 (0x00002b4eca297000) libc.so.6 => /lib/libc.so.6 (0x00002b4eca49f000) libpthread.so.0 => /lib/libpthread.so.0 (0x00002b4eca7df000) /lib64/ld-linux-x86-64.so.2 (0x00002b4ec9e72000) libattr.so.1…

Read More

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 (file descriptor 2) – standard error output, also displayed on the screen We can redirect the stdout from a command to a file. The file is created if it doesn’t exist and is truncated if it does. $ command > outfile…

Read More

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 the shell will expand the variable. In this example we will surround the variable with double quotes. $ echo “$USER” ryan We see the same result as before. This time with single quotes. $ echo ‘$USER’ $USER The variable name is not…

Read More

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 by adding ‘-n’ option and adding the number of lines. $ head -n 3 textfile.txt This will show the first 3 lines in the file.

Read More

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 the last 10 lines of a text file. $ tail textfile.txt You can change the number of lines displayed by adding ‘-n’ option and adding the number of lines. $ tail -n 3 textfile.txt This will show the last 3 lines in…

Read More

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 choice of threading implementation (usually NPTL) and force the use of the older LinuxThreads implementation at run-time. Many 32-bit systems have 3 separate glibc versions which have support for a minimum OS Application Binary Interface (ABI), designated by a kernel version and offer support for a…

Read More

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 Portage tree with the latest mirror. This command will get you information on the latest packages that are currently available. # emerge –sync Perform an “pretend” emerge to see what packages will be updated and installed on your system. # emerge -uDNvp world…

Read More

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 language tests. The first successful test is the one that is printed to the user. The magic number tests are used to check for files with data in particular fixed formats. To determine the format of a file in this manner, either a magic number identifier…

Read More

TAR is the GNU Tape ARchive utility. It is used to pack the contents of multiple files or directories in an archive file called a tarball. Tar can preserve directory organization including file ownership, permissions, links, as well as directory structure. To save space you can optionally enable compression with gzip, bzip2, or another external program. For these examples I’m going to be using this sample directory which contains a few files. /mydir /mydir/script.sh /mydir/picture.jpg /mydir/document.txt Lets create a tarball from this directory. Run the following command. $ tar -cvf mydir.tar mydir Lets go over these options. -c create tarball…

Read More

Watch runs a program at regular interval and continuously displays the output. This allows you keep track of the changes that are occurring in the program over time. Run watch in the following way. watch [options] command By default watch updates the command output every 2 seconds. To change this interval us the ‘-n seconds’ option. This will keep an eye on the changes occurring in your home directory. This will update the command output every second. $ watch -n 1 ls -l ~/ If you use the ‘-d’ option, watch will highlight the differences between the current and previous…

Read More