1833861 Members
2417 Online
110063 Solutions
New Discussion

Regarding unix commands

 
SOLVED
Go to solution
vind123
Regular Advisor

Regarding unix commands

When i do a ls -l acego i am getting the below output
-r-xr-xr-x 2 scc scc 1286492 Aug 12 12:48 acego

1. I am able to see acego has 2 links. I don't know whether it's a soft or hard link. How do i find the link which is pointing for acego.

2. I am unable to see the year value in the listing. Only "Aug 12 12:48" i am able to see. How do i find the year in which the file is created.

3. I tried to create a directory and delete a directory from a different directory location but i am getting an error
mkdir $HOME/test1
rmdir $HOME/test1
rmdir: /home/users/fcc/test1: Cannot remove mountable directory

4. ls -ltr Back*
-rw-r--r-- 1 fcc fcc 1692 Aug 17 05:27 Backout.sh

I want to write a shell script in which i want to check the permission of Backout.sh is 644 and owner is fcc and group is fcc. I tried this one
ls -ltr Backout.sh | grep scc >> /tmp/backouterr.log



11 REPLIES 11
Pupil_1
Trusted Contributor

Re: Regarding unix commands

2. If you don't see the year, then it's the current year in the system.

3. will depend on that's the o/p of $HOME/test1
There is always something new to learn everyday !!
Yarek
Regular Advisor

Re: Regarding unix commands

1. soft link is indicated by "l" letter
Yarek
Regular Advisor

Re: Regarding unix commands

2. if there is no year value, it means it's current year
Steven E. Protter
Exalted Contributor
Solution

Re: Regarding unix commands

Shalom,

1. ll if it spans filesystems its definitely a soft link.
2. If it doesn't show a year, its this year. ie less than a year old.
3. You are in an nfs home directory and trying to remove things you don't have permission for. This may be due to NFS configuration.

PERM-$(ll Backout.sh | awk '{print $1}')
OWNER-$(ll Backout.sh | awk '{print $2}')
GROUP-$(ll Backout.sh | awk '{print $3}')

Make and if statement to let you know when you are not happy with the results from these commands.

ll can be replaced with ls -la with no impact.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Yarek
Regular Advisor

Re: Regarding unix commands

4.

permission=`ll Backout.sh | awk '{print $1}'`

if [ $permission = "-rw-r--r--" ]
then
echo "mask of permission is 644"
else
echo "Wrong permission"
fi
Bill Hassell
Honored Contributor

Re: Regarding unix commands

1. The first character of the permissions list is the file type - in this case, - means that this is an ordinary file. A softlink will start with the letter l. The number 2 indicates that there are 2 inodes pointing to the same file, which is what defines a hard link. A hard link is simple another name for the same file in the same filesystem (mountpoint). A softlink has no limits on what it can point to.

2. As mentioned, the ll command changes format to include the year when the file is more than 6 months old. Use the command: man ll

3. The $HOME directory is probably an NFRS mountpoint and you do not have permission to change that directory. To see if $HOME is an NFS mountpoint, bdf $HOME

4. I'm not sure how your request to check permissions and ownership relates to the example you gave. Converting the symbolic permissions (-rw-r--r--) to a number requires a lot of scripting code but comparing the permission string in its symbolic form is easy. You can extract the 1st, 3rd and 4th fields from ll like this:

ls -ldtr Back* | while read PERM LINK OWN GRP RESTOFLINE
do
echo "perm= $PERM, owner= $OWN group= $GRP $RESTOFLINE"
done

Note the use of -d in the ls command. In case the ls command finds a directory, the -d keeps the listing to jsut the directory and not the contents.


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: Regarding unix commands

Hi:

1. Since you have a link count that is greater than one (1) this is a hard-link. Too, soft (symbolic) links will have an "l" (the letter) as the first character of the first field returned by a 'ls' listing. See the manpages for 'ls(1)'.

2. The output of 'ls' shows the month, day, hour and minute of timestamps *unless* the file is 6-months or more old. In that case, the hours and minutes are replaced with the four-digit year value. Thus, any file timestamp showing hours and minutes belongs to the current calendar year.

Unix does *not* maintain any creation timestamp. The default output for 'ls' is the *modification* time or 'mtime'. When a file is first created, the 'mtime' is equal to the creation time, but thereafter any modifications are tracked using the single timestamp. Read the manpages for 'stat(2)' to understand the three timestamps associated with files.

3. The message "cannot remove mountable directory" means that you have 'cd'ed into the directory that you are trying to remove. You cannot remove a directory into which you have changed. This would be like standing on a ladder and kicking it out from underneath yourself!

4. You can use 'ls filename' and 'cut' or 'awk' to extact the permissions (mode) field along with the owner to compare for what you want. For instance:

# MODES=`ls -l /tmp/me|cut -d" " -f1`;echo ${MODES}

Regards!

...JRF...
Tom Danzig
Honored Contributor

Re: Regarding unix commands

To find the other hard link to file acego:

ls -li acego (inode will be the first field)
find -inum

vind123
Regular Advisor

Re: Regarding unix commands

Thanks a lot for the info. I will try these and will come back .Also i forgot to add one more question to my post.

drwxrwxrwt 2 fcc fcc 1024 Aug 16 23:20 cdd

what this final t in the permission stands for and what is it purpose. I want to create a new directory and set the same permission as of cdd. what permission in the chmod command i need to give for this one.
James R. Ferguson
Acclaimed Contributor

Re: Regarding unix commands

Hi:

You asked what the significance of the "t" is in "drwxrwxrwt".

The "t" indicates that the "sticky bit" is set. If the sticky bit is set for a directory, then the directory's files can only be renamed or removed by the owner of the file, the owner of the directory, or by root.

If the sticky bit is set for an executable file, then the text (code) of the executable remains in memory for subsequent executions. This may make process startup for the executable faster.

In the case of your directory, you would have obtained these modes with:

# chmod 1777 cdd

See the manpages for 'chmod(1)' for more information.

Regards!

...JRF...
vind123
Regular Advisor

Re: Regarding unix commands

Thanks a lot for the info