473,221 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

formatting output of `ls -l` shell command

Hello.
As in the topic, I use www to execute shell command, in this case 'ls -l'
and i get output like:

total 8
drwx------ 11 lecichy staff 4096 Oct 15 18:18 Maildir
drwx---r-x 3 lecichy staff 4096 Oct 13 19:28 public_html

etc.
but what If i would want to print to www only some columns. e.g. only
filename and size like;

dir contains
Maildir size: 4096
public_html size 4096

or any other combinations, the point is if anyone has
any ideas how to split the output of this command to variables on witch i
can easily operate?

And maybe its possible to achieve it in the other way. What I mean is
selecting filenames and so on as a regular strings from a specific line of
text
?

Thanks


Jul 17 '05 #1
5 9726
lecichy wrote on Wednesday 15 October 2003 14:02:
Hello.
As in the topic, I use www to execute shell command, in this case 'ls -l'
and i get output like:

total 8
drwx------ 11 lecichy staff 4096 Oct 15 18:18 Maildir
drwx---r-x 3 lecichy staff 4096 Oct 13 19:28 public_html

etc.
but what If i would want to print to www only some columns.


ls -l is a system specific command. If you wanted to parse the output, you
could probably use the space as a separator between data and also taking
into account formatting options on the system.

What you should be using instead are the directory and filesystem functions
in PHP:
http://www.php.net/manual/en/ref.dir.php
http://www.php.net/manual/en/ref.filesystem.php
i.e., iterate through the directory and display data for each entry.

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 17 '05 #2
lecichy wrote:
'ls -l' and i get output like:

total 8
drwx------ 11 lecichy staff 4096 Oct 15 18:18 Maildir
drwx---r-x 3 lecichy staff 4096 Oct 13 19:28 public_html

etc.
but what If i would want to print to www only some columns. e.g. only
filename and size like;


instead of ls -l try

ls -l | awk '{ print($9 " size: " $5) }'
or, if you don't want that, grab the result and preg_split it twice:

the first time with "\n" (newline) for each line

and the second time (once for every line found the first time)
with "\s" (whitespace) for each column

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #3
instead of ls -l try

ls -l | awk '{ print($9 " size: " $5) }'
or, if you don't want that, grab the result and preg_split it twice:

the first time with "\n" (newline) for each line

and the second time (once for every line found the first time)
with "\s" (whitespace) for each column


heh! Thanks! Now it seems so obvious and so "doable by me". So many ideas!
Guess i have to lern thinking creatively, not only technics :)
But since we are here to lern something more so could you Pedro explain this
" ls -l | awk '{ print($9 " size: " $5) }' " you suggested?. Its possible
to add PHP variables inside the shell command ( this ` ` backticks or
whatever its called ) in the script ?

Jul 17 '05 #4
lecichy wrote:
heh! Thanks! Now it seems so obvious and so "doable by me". So many ideas!
Guess i have to lern thinking creatively, not only technics :)
you really, really, *really* should follow Zurab's suggestion of using
the filesystem functions.

But since we are here to lern something more so could you Pedro explain this
" ls -l | awk '{ print($9 " size: " $5) }' " you suggested?.
from a shell prompt execute

le*****@host.com$ man awk

"awk" is simply a system command, just like "ls"

Its possible to add PHP variables inside the shell command
( this ` ` backticks or whatever its called ) in the script ?


Yes, but that is not what I meant. I typed the command just like the
system would see it. And I didn't use backticks.

Try it at the shell prompt:

le*****@host.com$ ls -l | awk '{ print($9 " size: " $5) }'

Check the execution chapter of the PHP Manual

http://www.php.net/manual/en/ref.exec.php


But I repeat, it's better to follow Zurab's suggestion!
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #5
On Wed, 15 Oct 2003 21:20:29 +0000, Zurab Davitiani wrote:
ls -l is a system specific command. If you wanted to parse the output, you
could probably use the space as a separator between data and also taking
into account formatting options on the system.


NOT safe. With many file systems (including all the commong Linux
filesystems), spaces are valid in filenames. Some other systems (but NOT
linux) may even allow spaces in user/group names. (Not at all in
disagreement re: using built-in functions vs ls, but want to point out
thhe flaw in your suggested scheme)

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jerry | last post by:
I've found a problem with exec, passthru, shell_exec & system. I'm trying to run the following exec("sort -r -n -k2,2 r1.txt > r2.txt") with r1.txt being a numeric file. The file looks like...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
16
by: Zenon | last post by:
I have an application where I create a Plink process to communicate with an HP Unix box. The problem I am having is that while reading the redirected output, it seems to try to continue past the...
5
by: Juergen Huber | last post by:
hello, one more question i will have! now i have written a little programm, which delivers me an output on the shell! here is the print command, which delivers me the following output...
9
by: Clodoaldo Pinto Neto | last post by:
Output from the shell: $ set | grep IFS IFS=$' \t\n' Output from subprocess.Popen(): "IFS=' \t\n" Both outputs for comparison:
1
by: Anthony Irwin | last post by:
Hi All, I would like to run the command below and have each line from the output stored as an element in a list. find /some/path/ -maxdepth 1 -type f -size +100000k -exec ls -1 '{}' \ The...
2
by: yogeshbhandare | last post by:
Hi Friends I have an issue with shell_exec. I am trying evoke a command from browser. The command get executed properly without any issue however it deos not return all the output which is...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.