I'm currently writing a script that searches through a directory and displays files with multiple hard links. The way I have it set up, is that it displays the i-node number and then each of the link names. In addition to this, I need to know if there are any hard links outside of the searched directory and if so, how many. Which I'm not completely sure how to do.
I understand the $4 is the number of hard links, however does that include any links that are found outside of the current directory? If not, then what exactly do I need to do to get a total number of hard links in and out of the current directory?
The second column is the number of disk blocks required to house the file. Generally the value is 512 byte blocks, though some versions of find might default to 1024 byte blocks.
The fourth column is the number of links, but only if the file is a regular file. If it is a directory it is the number of files contained/referenced in the directory.
Because links (old timers call them links as symbolic links were introduced later) cannot span filesystems, I'd approach the problem by executing a find on the whole file system and matching inodes for files that are listed within the target directory. The following is a way to do this and assumes that the target directory is the current working directory.
Thanks for the replies. Just one last question though. In the fourth column above, is that the total number of hard links for that file or just the number of links in that directory?
Thanks for the replies. Just one last question though. In the fourth column above, is that the total number of hard links for that file or just the number of links in that directory?
While basename and dirname are great tools, there are times where we may need to perform more advanced string "chopping" operations than just standard pathname manipulations. When we need more punch, we can take advantage of bash's advanced built-in variable expansion functionality. We've already used the standard kind of variable expansion, which looks like this: ${MYVAR}. But bash can also perform some handy string chopping on its own. Take a look at these examples:
In the first example, we typed ${MYVAR##*fo}. What exactly does this mean? Basically, inside the ${ }, we typed the name of the environment variable, two ##s, and a wildcard ("*fo"). Then, bash took MYVAR, found the longest substring from the beginning of the string "foodforthought.jpg" that matched the wildcard "*fo", and chopped it off the beginning of the string. That's a bit hard to grasp at first, so to get a feel for how this special "##" option works, let's step through how bash completed this expansion. First, it began searching for substrings at the beginning of "foodforthought.jpg" that matched the "*fo" wildcard. Here are the substrings that it checked:
After searching the string for matches, you can see that bash found two. It selects the longest match, removes it from the beginning of the original string, and returns the result.
The second form of variable expansion shown above appears identical to the first, except it uses only one "#" -- and bash performs an almost identical process. It checks the same set of substrings as our first example did, except that bash removes the shortest match from our original string, and returns the result. So, as soon as it checks the "fo" substring, it removes "fo" from our string and returns "odforthought.jpg".
After reading that put it to the test.
bash code:
p=$(df-h .)# free hard disk space in the current directory in a human readable format
Hi team, i am writing a purge script to delete softlinks and hardlinks on linux system which are 3/10/30 days old. To test the script i need to create links with old timestamp, i am able to cange timestamp for files but not for links.
i tried touch -h option but this option is not available on... (1 Reply)
Hi,
I'm trying to create a Makefile that would automate remastering Knoppix distribution.
As a part of the process I am mounting using linux cloop device a compressed filesystem and copy the content out of it to separate dir. However during that process I need to preserve hard links and it... (9 Replies)
Hard links for directories are not permitted by default. But in some flavor of Unix, super user can create hard links for directories by some other way? Is that true? Is it possible in latest version of BSD or other unix? (2 Replies)
From what I understand a symbolic link is alot like a shortcut where it points to another file. if the original file is deleted the symbolic link is rendered useless but a symbolic link can be deleted without any problem.
A hard link is like a copy of the file itself but pointing to the same... (3 Replies)
hi, i am in a directory, have 2 files as below
then do a ls -l gives the below
lrwxrwxrwx 1 root system 23 Mar 08 2001 filea -> /adir/filea
lrwxrwxrwx 1 root system 23 Mar 08 2001 filea -> /adir/fileb
now, when i do a cd /adir, the system said, adir not... (5 Replies)
Hi,
what is link? and soft link? how about hard one and symbolic link.
and inode.
i get confuse about this links. could anyone help me with full explainsion?
thks
Gusla (5 Replies)