Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a directory structure in my system (linux) as shown below
Can any one please help me for this
Thank you
linux_kv
Help you with WHAT? You haven't asked a question.
If you mean you want a SCRIPT to do this, yes, we can HELP you with it...but we're not going to write it for you. Post what you've written, and where you're stuck, and we can help you. Otherwise, check Google...there are thousands of scripting tutorials that you can easily find.
Will provide the output in long list format and lists subdirectories recursively- including permissions, group and ownership - not exactly in the same order you listed - output to a "text.file" -
Please find my script. recursive function is not working correctly(ending). If I don't use recursively it is working fine.
Please correct my mistake. [..]
Ok, that seems a little complicated. Try this one instead:
Code:
#!/bin/bash
if [ "${#}" -eq 1 -a -d "${1}" ]; then
for f in $(find ${1} -type f) ; do
stat --format='%n:%U:%G:%a:' ${f}
done
else
printf "Usage: ${0##*/} [directory]\n"
fi
The above assumes you only want to have files listed in your output and not directories (remove "-type f" from find if you want to include directories). Also, it's probably better to use octal modes (permissions) when scripting. Keep in mind that you really don't need use separate fields for $ownerpermission1:$grouppermission1 because an octal value like the one in the above script already contains both (a file with mode 644 equals user=r+w,group=r,world=r).
Last edited by overlook; 12-06-2010 at 11:08 AM.
Reason: grammar, and some additional notes
Take a look at the -printf predicate of find, e.g. [..]
Very useful, thanks! Didn't realize find had this feature. So the solution to his problem is reduced to a single command, awesome .. and the final script would be (with line-feed and octal modes):
Code:
#!/bin/bash
if [ "${#}" -eq 1 -a -d "${1}" ]; then
find ${1} -type f -printf "%p:%u:%g:%m\n"
else
printf "Usage: ${0##*/} [directory]\n"
fi
Thanks for the replies I will try your suggestions however I fixed my script
I made a mistake fdirinfo "filename1" instead of fdirinfo "$filename1"
here is my script
dirName="."
function fdirinfo()
{
if !(test -d "$1") #check the parameter is directory
then echo $1; return;
fi
cd "$1" #change to directory
for filename1 in * #loop trhough all the files
do
if test -d "$filename1" #if directory
then
#this command give output in a specific format (dir with fullpath : owner:groupwnerpermissions:grouppermissions and redirects to a file
#find command gets all the directories (non hidden) and printf prints path user group and permssions
#grep command ignores lost+found directory
#sed replaces third : as |
#awk prints anything before | and substring of remaining portion
#sed replace any -
#and replaces if last char is : this is required because sometimes replace all the - will leave :
#awk prints all the output and also : at the end
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.