What do this ldconfig statment into this bash script? - linux

I am pretty new in Linux and I have some doubt related to this operation that I have found into a bash script on which I am working:
ldconfig -v >> /dev/null 2>&1
Reading on the man page of the ldconfig command I can read:
ldconfig creates, updates, and removes the necessary links and
cache
(for use by the run-time linker, ld.so) to the most recent shared
libraries found in the directories specified on the command line, in
the file /etc/ld.so.conf, and in the trusted directories (/usr/lib and
/lib).
What exactly mean? I am using Ubuntu system and in /etc/ld.so.conf I found:
include /etc/ld.so.conf.d/*.conf
So I think that this line redirect me to all the .conf files into /etc/ld.so.conf.d/ directory
But I have some confusion...and many doubts:
1) What are contains into the .conf file?
2) what exactly do the command that is in my bash script?
Tnx
Andrea

ldconfig -v >> /dev/null 2>&1 means redirect stdout (standard output) and stderr (standard error) to a special device /dev/null which means no-where (to discard it).
> /dev/null - is redirecting stdout
2 > &1 is redirecting stderr to wherever stdout is redirected at since 1 is file descriptor of stdout and 2 is file descriptor of stderr
About ldconfig: ldconfig man page
As per manual:
ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line

1) What are contains into the .conf file?
ldconfig uses configuration scripts (which can be stacked using the include directive) to know which directories it should search for libraries.
from man ldconfig:
/etc/ld.so.conf File containing a list of colon, space, tab, newline, or
comma-separated directories in which to search for libraries.
2) what exactly do the command that is in my bash script?
it updates the dynamic linker cache. that is: if you are installing shared libraries it will make the newly installed libraries availabled to your system.
(e.g. when installing libfoo.so.2.1 it will create the necessary symlinks to libfoo.so.2)

Related

Where would I find the kernel .config file in Lubuntu?

I'm running through the "first kernel patch" tutorial on kernel newbies http://kernelnewbies.org/FirstKernelPatch
While running through the tutorial, i've had absolutely no issues what so ever until now, I am at a point where I am setting up my kernel configuration. I've followed the tutorial exactly as shown but the following command:
cp /boot/config-'uname -r'* .config
leaves me with the following error message in the terminal:
cp: cannot stat '/boot/config-uname -r*': No such file or directory
Is there a way I can generate this file without going through the effort of looking for it in the finder? I'd rather not go through the thousands of files there are in a kernel, it could take me forever.
It seems like your tutorial has a quotation error. instead of ' you should be using ` (backtick)
cp /boot/config-`uname -r`* .config
What it does is execute the command uname -r and place the stdout of the command in place of the command. I'd suggest using $(command) instead of `command` since it's more obvious what is going on.
cp /boot/config-$(uname -r)* .config
First things first .. You're using simple quotes which is wrong, the command is meant to use backticks (`) -- they will include the output of the command inside them:
> uname -r
3.16.1-ck1
> echo /boot/config-`uname -r`
/boot/config-3.16.1-ck1
So this could already solve your problem.
If this file isn't present on your system, you have some alternatives:
If you have the source the running kernel is built from, the kernel config is the file .config there.
Although most packaging/installation systems copy the kernel config to /boot/config-`uname -r`, some just copy it to /boot/config (without version suffix)
The kernel can be built to serve it's config in /proc/config.gz (gzip compressed)
If really neither of these succeed, you're out of luck and your only option is get hold of the source package your kernel is built from.

Unable to list all files in $HOME directory

I installed the latest version of cygwin and wanted to list all files in my $HOME direcrory (in paticular .vimrc config file). I type ls -l and see 0 files, but when I try to open the file via vim it's ok. Actually (after 2 TABs):
what's wrong?
In *nix systems, prefixing a name with . causes the item to be hidden.
To include these files when you type ls -l, you will need to include the -a modifier.
You can write this as ls -la for brevity, if you like.
In the future, if you're having trouble with a program, you can type (e.g.) man ls to open the manual pages for (e.g.) ls.

Linux command file for symbolic links

when I try to check the type of an executable file, I always get this:
symbolic link to <another_file>
Then I have to dig further and run file <another_file>. Sometimes this could take 5 or 6 rounds. I'm wondering whether there is a way to let file to recursively go to the original file and tell me the file type.
Specifying -L to file should make it follow symlinks. From the man page:
-L, --dereference
option causes symlinks to be followed, as the like-named option
in ls(1) (on systems that support symbolic links). This is the
default if the environment variable POSIXLY_CORRECT is defined.
use "file -L" to follow symbolic links

Linux: Man command in application installed only for current user

Manual files in Linux are stored in /usr/share/man. Before, my application could only be installed by a root user and it put the manual files in this directory. Now, I want to enable non-root installation; to achieve this, all my data and configuration files will be installed under ~/<appname>/. However, manual files copied to home will no longer be accessible by man command.
What are the usual workarounds to this problem?
I've thought in creating a "man" command in my application that runs man -M /<man_path>/<appname>/ (as this is easier to users than running the command by themselves). Is this a good option?
Thanks in advance.
[spatel#ap4004 appname]$ export MANPATH=/home/spatel/appname/man
[spatel#ap4004 appname]$ manpath
/home/spatel/appname/man/en:/home/spatel/appname/man
Other workaround is command alias
[spatel#ap4004 appname]$ alias man='man -M /home/spatel/appname/man'
[spatel#ap4004 appname]$ alias man
alias man='man -M /home/spatel/appname/man'
You'll need to use manpath command.
man has new behaviour by default (at least on Fedora 14 and on) that it searches in paths corresponding to PATH environment variable, i.e. for PATH=/xyz/bin it searches /xyz/bin/man, /xyz/share/man and other nearby places. Unless MANPATH is set.
You need to unset MANPATH at the end of your .bash_profile, some startup scripts in /etc may set it to spite you.
If you don't specify an explicit path list with -M or MANPATH, man develops its own path list based on the contents of the configuration file /etc/man.config. The MANPATH statements in the configuration file identify particular directories to include in the search path.
Furthermore, the MANPATH_MAP statements add to the search path depending on your command search path (i.e. your PATH environment variable). For each directory that may be in the command search path, a MANPATH_MAP statement specifies a directory that should be added to the search path for manual page files. man looks at the PATH variable and adds the corresponding directories to the manual page file search path. Thus, with the proper use of MANPATH_MAP, when you issue the command man xyz, you get a manual page for the program that would run if you issued the command xyz.
In addition, for each directory in the command search path (we'll call it a "command directory") for which you do not have a MANPATH_MAP statement, man automatically looks for a manual page directory "nearby" namely as a subdirectory in the command directory itself or in the parent directory of the command directory.
You can disable the automatic "nearby" searches by including a NOAUTOPATH statement in /etc/man.config.

How to create my own command in linux

I wrote a simple cpp code by using vi. I want to use cat command inside this program (by using execl and it will take my file as argument). I also have to write my own command. For example it will work like that: $mycommand filename. And cat command which is inside my cpp code will show my cpp file's content. I'm new so I don't know how to do it. Do you have any suggestions?
1) Redirecting output
The output of the cat command should go to the standard output of your program.
For this your program should pass its standard output FD to the exec command. This will be the default case. So you don't have to do anything extra.
2) cat on the source file
Now, the cat thing : "And cat command which is inside my cpp code will show my cpp file's content. " This statement does not explain your need. If you want the cat of the executable you are running, you can do an objdump on your executable. The executable path can be found out from the proc file system with your pid. For a generic case, it does not matter whether the file is a cpp file or not.
3) making command
To make your executable run as a standard command on a terminal, you must add the directory containing the executable to the PATH directories list. You can do so by adding your executable to /usr/local/bin or /usr/bin. (Convention is that it should go in /usr/local/bin since it has been compiled locally). If you don't have administrator privileges on the machine, you must append the source directory to the PATH directory list.

Resources