Change the display format for ls -l command in AIX

Hi,

I am using AIX 5.3. In my server if I list the file , I got the below result in below format.

*********************************************

-rw-rw--w-   1 letapp1  staff             0 Jun  8 02:53 CC00030710.cntrl

*********************************************

But now I am seeing the one extra space between the "permission tab" and 'number of links" tab.

*********************************************

-rw-rw--w-    1 letapp1  staff             0 Jun  8 02:53 CC00030710.cntrl

*********************************************

Note:One extra space between "-rw-rw--w- " and "1".

Can anyone please let me know if we can able to modify the ls -l display format?

Thanks in advance,
Puni

ls -l | sed 's/ /  /'

Not sure wether it will change something or not, but could you try to add a backslash before your ls and see if you still get different output or not :
On Your AIX 5.3

\ls -l

On your other machine

\ls -l

Are the output still different ?

Has there been any patch upgrade on your OS?
Because the output what you are receiving is the standard output across all AIX 5.3

Hi Vidyadhar,

Yes, Batch upgrade went in our server. And after the upgrade only 'ls -l' command display format got changed. Many of our jobs are using the cut command with 'ls -l' command.

For example in our job we have the below command to get the size of the file.

***************************************************

ls -l test_cntl_file | cut -c30-43
-rw-rw-r--   1 letapp1  staff            28 Jun  4 16:00 test_cntl_file

***************************************************
For this we got the result "28".

But now since we got the one extra space between "-rw-rw-r--" and "1", we are getting the result for the above command as "f28".

To change this I need to identify all the jobs and needs to put a change. This will be a huge manual activity.

That why I am looking if I can able to remove the one extra space in 'ls -l' command result by modifying any server setup or something like that.
Thanks,
Punitha.S

This is poor code, if the size is in the 5th column, you should use

ls -l test_cntl_file | awk '{print $5}'

(this code will not be sensitive to the number of space)

instead of

ls -l test_cntl_file | cut -c30-43

which will be sensitive to the number of space.

Yes, I agreed. But now if we cant modify the 'ls -l' display format, I need to modify all my scripts :wall:... Is there any way that we can change the dispaly format?

Why I am asking is in AIX with the same version itself, I saw in ls -l comand date field dispaly there is two different results in two different servers.

For example

-rw-rw-r--   1 letapp1  staff            60 Jun  9 02:00 passed_date.dat
-rw-rw-r--   1 letapp1  staff            60 Jun 09 02:00 passed_date.dat

So I hope there is some way we could achieve this. Please advice

Thanks,
Puni

It is your choice :

  • Modify a system that works to make it behave as expected with poorly coded scripts
    or
  • Fix your poorly coded scripts to make it behave as expected on a system that works

IMO you should obviously choose that second option .

I am very sorry to tell you that leaving bad code just because there are numerous (i.e. because of lazyness) is a VERY BAD reason ... in my opinion

So the best piece of advice i can give you is : yes, you need to fix ALL the scripts in which you use such a way of getting datas

This is an opportunity to improve your code, too. If there's numerous places this is used, you could get rid of a lot of redundancy by having that done by one thing which everything else calls or sources instead of having that routine duplicated in 17 different scripts.

Hi.

There are 3 work-alike codes for utility ls at the perl power tools page:

http://cpansearch.perl.org/src/CWEST/ppt-0.14/html/commands/ls/index.html

I downloaded and tried them all on & with:

aix 5.1.0.0
perl 5.6.0

One was missing a perl module ( Stat/lsMode.pm ), but all compiled and the other 2 ran, although one had a strange output for option "-l". The one that ran correctly compared favorably with the native ls, but not exactly as regards spacing.

So if you wanted to modify ls output with a project-specific code in perl, you could.

However, I agree with many of the others, and suggest that you clean up your scripts. Counting on specific locations in a line for a datum is a very fragile technique, as you have found.

Good luck with whatever decision you make ... cheers, drl

1 Like

Write your own, ls is just a wrapper for dirent and stat. JAVA or PERL might be nicer than C/C++!

Hi all,

Thank you. Surely I need to modify my code. But I am curious to know if there is a way that we can set the 'ls -l' command dispaly format or it never possible in unix?

Thanks
Punitha.S

Without having to get into re-coding the ls command you could just format it, as per DGPicket's suggestion :

ls -l | sed 's/ /  /'

Either that, or use awk, capture every field, and format them the way you like, adjusting for old files and sym-links.

1 Like

Thank You all

Try using the GNU ls in /opt/freeware/bin (if you have it installed)
If it is fine, make sure /opt/freeware/bin is ahead of /usr/bin in your PATH

Hi,

In this last column, I need to subtract the number 006 ( for which * symbol is showing )
from 0010. i.e., 10 - 6 arithmetic operation. How to subtract the numbers in a column
? Can you please advise ?

                      017E  Not Visible             \(M\)     0   00  005
                       -     AVAILABLE                       0   00  006 \*
                       033F  Not Visible                     0   00  010
                       0340  Not Visible                     0   00  011
                       0341  Not Visible                     0   00  012
                       0342  Not Visible                     0   00  013
                       0343  Not Visible                     0   00  014
                       0344  Not Visible                     0   00  015
                       0345  Not Visible                     0   00  016
                       0346  Not Visible                     0   00  017
                       0347  Not Visible                     0   00  018
                       0348  Not Visible                     0   00  019
                       0349  Not Visible                     0   00  01A
                       034A  Not Visible                     0   00  01B

Hi, prakashrao2011.

Welcome to the forum.

You will probably get more answers if your question is in a new thread rather than being appended to an existing, unrelated thread as it is now.

Best wishes ... cheers, drl

( Edit 2: minor typo )

Yes, outside emergency, new chains are free.

Hi
you can modify the display of ls -l with the help of awk command. please try

thanks