Visit Our UNIX and Linux User Community


File/directory information......


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File/directory information......
# 29  
Old 01-08-2002
Jimbo its definatly something to do with the sed command
sed "s/./& /g"

Says its not recongnised, tr command is workin fine now.

Ne1 know of ne alternatives for converting
e.g. 421000000 to 4 2 1 0 0 0 0 0 0 (need conversion to add spaces)??????

Smilie
# 30  
Old 01-08-2002
What is the output of the following:

uname -a
echo $PATH

Also, do:

find / -type f -name sed 2> /dev/null

If the find command finds a sed, such as /usr/bin/sed, then reference that instead of the unqualified "sed".
Jimbo
# 31  
Old 01-08-2002
I think the best approach is to break the permission string up into an array with each element of the array being a single character. Then a few "if" statements can handle those pesky suid, sgid and sticky bits. Once they are gone, what's left is really a binary number with hyphen being a zero and everything else being a one. We can then convert that binary number to octal. Finally we just add in any of those high bits we found.

Part of the problem may be that the OP has a PATH with some screwy versions of normal system commands. So setting the PATH is probably wise.

Here is a script that displays the numeric mode for a file that is passed as a argument...
Code:
#! /usr/bin/ksh
PATH=/usr/bin

integer -i8 octal

ls -l $1 | read permstring junk
set -A perms -- $(print -- ${permstring#?} | sed 's/./& /g')

extras=0
[[ ${perms[2]} = S ]] && { ((extras=extras+4000)); perms[2]=- ; }
[[ ${perms[2]} = s ]] && { ((extras=extras+4000)); perms[2]=x ; }
[[ ${perms[5]} = S ]] && { ((extras=extras+2000)); perms[4]=- ; }
[[ ${perms[5]} = s ]] && { ((extras=extras+2000)); perms[4]=x ; }
[[ ${perms[8]} = T ]] && { ((extras=extras+1000)); perms[8]=- ; }
[[ ${perms[8]} = t ]] && { ((extras=extras+1000)); perms[8]=x ; }

binary=2#$(print -- ${perms[@]} | sed 's/ //g;s/-/0/g;s/[^0]/1/g')
((octal=binary))
result=$(echo $octal)
result=${result#??}
((result=result+extras))

echo $result

exit 0

Makaveli.2003, does this script work for you? And I too would like to know what "uname -a" and "echo $PATH" give you.
# 32  
Old 01-08-2002
uname -a
SunOS babbage 5.6

echo $PATH
/usr/bin::/usr/bin

find / -type f -name sed 2> /dev/null
/usr/bin/sed
/usr/xpg4/bin/sed
/usr/ucb/sed
# 33  
Old 01-08-2002
I'm sure there's an easier or MUCH cleaner way... but this will give you numeric permissions on a filename:

NUMPERM=`ls -l $name |awk '{print $1}' |sed 's/-rwx/7/g; s/rwx/7/g; s/rw-/6/g; s/r--/4/g; s/r-x/5/g; s/d//g; s/^-//g'`

You could pipe this to the cut command for user/group/all individual permissions, ie.....

USER=`$NUMPERM |cut -c1`
GOURP=`$NUMPERM |cut -c2`
ALL=`$NUMPERM |cut -c3`

Hope this helps.
# 34  
Old 01-08-2002
davidl tried wat u said, but didn't seem to work, don't know why.

Your idea seems a bit complex compared with Jimbo's, its definatly something to do with the sed command
sed "s/./& /g"
Smilie Smilie
# 35  
Old 01-09-2002
Hmm, maybe you could try using the different "sed" binaries... each of:
/usr/bin/sed
/usr/xpg4/bin/sed
/usr/ucb/sed

They may each "behave" differently in how they interpret regular expressions...
 

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create file and file content based existing information?

Hi Gurus, I am SQL developer and new unix user. I need to create some file and file content based on information in two files. I have one file contains basic information below file1 and another exception file file2. the rule is if "zone' and "cd" in file1 exists in file2, then file name is... (13 Replies)
Discussion started by: Torhong
13 Replies

2. UNIX for Dummies Questions & Answers

Grep? - using a file of terms to search another file when the information is on a different line

I have a flat file that looks like this, let's call it Chromosome_9.txt: FT /Gene_Name="Guanyl-Acetylase 9" FT /Gene_Number"36952" FT /Gene_Name="Endoplasmic Luciferase" FT /Gene_Number"36953" FT ... (4 Replies)
Discussion started by: Twinklefingers
4 Replies

3. UNIX for Dummies Questions & Answers

How can I use my code to gather information from a file in a completely different directory?

I need my code to compare two different files that are in two completely different directories, How can I do this? So for example, my code will look at file1 which is in my home directory, and compare the files with those from file2 that is in /abc/adf/adr/afc/adf/file2... does that make sense? (1 Reply)
Discussion started by: castrojc
1 Replies

4. Shell Programming and Scripting

reading a file extracting information writing to a file

Hi I am trying to extract information out of a file but keep getting grep cant open errors the code is below: #bash #extract orders with blank address details # # obtain the current date # set today to the current date ccyymmdd format today=`date +%c%m%d | cut -c24-31` echo... (8 Replies)
Discussion started by: Bruble
8 Replies

5. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

6. Shell Programming and Scripting

Only the required tag information the XML file file

Hi i have a single line xml file having many account no tag, from which i need only the account no from the tag. any one can help on this. below is the xml file: ... (2 Replies)
Discussion started by: Saravanapk
2 Replies

7. Shell Programming and Scripting

Generating an xml having information related to files in the directory

Hi all, Have to generate an xml having information related to files in the directory Suppose i have file file1.xml (datafile) file2.xml (datafile) file3.xml (metafile) Now i need to generate an xml in the format >> <?xml version="1.0" encoding="UTF-8"?> <AuditFile Version="2.0">... (8 Replies)
Discussion started by: abhinav192
8 Replies

8. UNIX for Dummies Questions & Answers

Read directory and fill a file with this information

Hello All, Got a question to make a script what reads a directory and put the file names from that directory in a file with some extra text. ls /tempdir output is: file1.gfh file2.txt file4.zzz these file names (always with an extention) must be placed in a line and written to... (2 Replies)
Discussion started by: ToXiQ
2 Replies

9. UNIX for Dummies Questions & Answers

why does tar sometimes include directory information?

hi, say I have dirA/file1 dirB/file2 and I tar them up, and then do zcat Tar.tar | tar tvf - Sometimes I will see: dirA/ dirA/file1 dirB/ dirB/file2 yet other times I will see (4 Replies)
Discussion started by: JamesByars
4 Replies

10. UNIX for Dummies Questions & Answers

date information of a directory

when i list the content of a directory date informations are also listed (ls -ltr) for included files and directories. for example: i see the date Jun 29 14:43 for one of the included directory, but when i look into the files contained in this directory i cannot see any file with this... (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

Featured Tech Videos