Unix check if a file referenced by any symlinks - unix

How to check if a file is being referenced by any symlinks in the directory - I want to delete all the other files except the symlink and the refernced file. Is there any direct command to check or a work around to do so?

If the symbolic link is in the same directory or in a well known one, that would be easy. Just check if no other file share the same inode ls -d1Li.
Otherwise, there is no direct way to know if a symbolic link exist to any given file. Even exploring all mounted file systems wouldn't be reliable, as the link might exist on a currently unmounted filesystem, or on a remote machine accessing the file remotely (NFS, CIFS and the likes).

Related

How to install tools for everyone to use in unix

I'm a freshman, and I created a server with my roomates in order to practice in maintaining a server.
We installed CentOS7. And I would like to ask how I can install a tool for everyone to use?
More particularly, we want to install Cromwell. But since, they don't have instructions on how to install on Unix, I downloaded Linuxbrew and installed it like this.
The downside is that it's not visible to the other users connected to the servers.
I know this is a noob question, but any response would be appreciated.
A standard unix machine has programs (tools and so on) installed in predefined directories like /bin, /usr/bin, perhaps /usr/local/bin. Which to choose is another matter, probably you want /usr/bin. Also the environ variable PATH plays a role.
Into the chosen directory there should be a file representing the "tool". You can put a copy of the executable file in that directory, and set (or check) its permissions. Execution permission can be granted to all users, or only some, it depends. In other words,
/home/me/.linuxbrew/Cellar/cromwell
is not a good place for a "system" tool or app; you should copy that executable in /usr/bin, set ownership (perhaps to root?) with chown, and set the correct permissions with chmod.
You can make a hard link of your executable into the directory; this saves space, but also means that there is only one copy of the executable. Having two different copies (the "stable" one, and the other one you can fiddle with) can be handy.
After the executable is reachable and executable from the chosen users, maybe it needs some support files. To find them, it can rely on fixed locations, or some environment variable, or some configuration file. But all these things are outside of the scope of the question.
Try this command:
you#machine$ sudo chmod [who][op][permissions] filename
"who" refers to the users that have a particular permission: the user ("u"), the group ("g"), or other users ("o", also known as "world"). "op" determines whether to add ("+"), remove ("-") or explicitly set ("=") the particular permissions. "permissions" are whether the file should be readable ("r"), writable ("w"), or executable ("x"). As an example:
you#machine$ chmod o+x file
will add executable permission for others to file.

Create file on unmounted folder

What happen if we try to create a file on a unmounted folder?
Does the file is created on local system?
I have a mounted folder that could sometimes unmount for reasons
I'm going to schedule a oracle procedure that writes a file inside there, what will happen if somehow the folder is unmounted
Does the file is created on local system?
Yes. Or, better, the file is created into that directory (don't call folder unix directories... :)), wherever that directory is (it could be part of a mounted remote file system, in that case it was not part of the local system).
Writing permissions on the directory play a role, and the mount command can also play with those permissions, but this is another, complicated matter.

Sync the directories

I have a directory on the computer having many files and sometimes I need to sync it with a clone from a device.
I use rsync.
Rsync does not see when a file was renamed or moved in other directory and it is very slow sometimes.
Is there a smart syncing tool that can see when a file was renamed/moved in the main directory and just rename on the clone without physical remove+copy ?

Where is the DB_CONFIG file of Berkeley database located in Unix?

i'm new to Berkeley db, i have installed the version "db-4.8.30.NC.tar.gz" but now i would like to find the configuration
information by using the configuration file.
I've read in the documentations that this file is named DB_CONFIG and it exists in the
database home directory.
In my system, i have uzipped the tar file under /usr/db-4.8.30.NC but i still haven't found
the DB_CONFIG file.
Well, i'm trying to find where the DB_CONFIG file is located in Unix, but i can't find it.
May you please help me?
Thanks, in advance
You (or a system administrator) writes the DB_CONFIG file by hand to modify any of the DB_ENV environment variables that can be over-ridden at runtime.
The DB_CONFIG file is stored in the db_home directory; the docs/programmer_reference/env_naming.html file has full details, but you can either pass an explicit db_home parameter in the DB_ENV->open() call or rely on the DB_HOME environment variable to locate the DB_CONFIG file, if any exists. The environment variable approach might be nice if the system administrator would reasonably want to move the storage around as they wish; the specific path name approach might be nice if you don't want to bother your system administrators with details of managing your storage.

Rsynch and SSH: Only rename folder when renamed from source

I have been reading the rsync documentation for a few hours, but I can't figure out how to convey to rsync how to only rename (and not re-upload folder and it's content) destination folders when they are renamed at the source.
I'm connecting to the destination with SSH, and the local folder is the source -- and the remote server is the destination. If I rename a folder containing files, rsync automatically re-uploads all the content of the source folder. I'm not using the rsync's server part, maybe it will works if were to do that ?
I have encountered the same behavior with lftp, and this tool doesn't seem's to have these options. Even if it is based on the file's date rule, files inside the renamed folder are removed/re-uploaded.
Thanks in advance if someone knows how to manage this :)
I've been looking for something similar.
so far, the best solution I have found is at:
http://serenadetoacuckooo.blogspot.com/2009/07/rsync-and-directory-renaming.html
It basically mentions including a meta-file in each folder that indicates the folder's name.
Essentially, you would want to check that file with the directory name, and rsync only if they are the same (otherwise, issue a remote rename command.)
It depends on the scope of what you're using rsync for, but I hope that this information can help you.
How would rsync or any other program know what constitutes renamed? What if two directories are very similar candidates and somehow rsync guesses maybe either one could be a rename of what went before? It's not possible. I think you're stuck with uploading everything again.
You know about the --delete option, right:
--delete delete files that don't exist on the sending side
Note also the --force option:
--force force deletion of directories even if not empty

Resources