2
I have a problem with my "homework" on studies.
I have to list all not empty directories from /var
and /usr
, which do not have subdirectories and their owner is not root user. Also, for each directory I have to show depth in directory tree, i-node number, size, permissions in human-readable and octal formats and absolute path to this directory, and sort it descending by i-node number.
Here is what I've currently done:
find /{us,va}r -type d \! -user root \! -empty -printf "%d %i %k %M %m %u %h/%f\n" | sort -rn
Now I just have to eliminate directories with subdirectories and sort it by i-node number.
So, here comes the questions:
- How can I eliminate directories with subdirectories from this list?
- How can I sort this list by i-node, which is in the second column?
Thanks for help.
Okay, I figured out something like this:
find /{us,va}r -links 2 -type d \! -user root \! -empty -printf "%d %i %k %M %m %u %h/%f\n" | sort -rnk 2
. Can anyone tell me if it's all right? – Sebastian Potasiak – 2013-03-24T23:52:05.377I'm curious; how does the 'links' help with finding directories that don't have subdirs? – tink – 2013-03-25T00:20:36.390
2@tink In case of directories, the number of subdirectories is stored as hard links count. By default, every directory (except /) has two subdirectories: '.' and '..' (current directory and parent directory), so if I check if there's only 2 'links' for specified directory, I'll get only directories without actual subdirectories. – Sebastian Potasiak – 2013-03-25T12:01:12.117
If you solved your problem, please consider answering your question and accepting your answer. – Dennis – 2013-03-28T01:50:03.600