Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4000196
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:45:05+00:00 2026-05-20T07:45:05+00:00

I need to do an exec command that applies to several files, but it’s

  • 0

I need to do an exec command that applies to several files, but it’s not working. I’m going to create an EXAMPLE to show this. Obviously, I don’t need anything of this directory and I do the example with “ls” command, although happens with any other command:

exec("ls -al /etc/security/", $output);
print_r($output);

Array
(
    [0] => total 40
    [1] => drwxr-xr-x  2 root root 4096 Jan 27  2010 .
    [2] => drwxr-xr-x 83 root root 4096 Feb 24 12:38 ..
    [3] => -rw-r--r--  1 root root 4266 Apr  9  2008 access.conf
    [4] => -rw-r--r--  1 root root 3551 Apr  9  2008 group.conf
    [5] => -rw-r--r--  1 root root 1911 Apr  9  2008 limits.conf
    [6] => -rw-r--r--  1 root root 1507 Apr  9  2008 namespace.conf
    [7] => -rwxr-xr-x  1 root root  977 Apr  9  2008 namespace.init
    [8] => -rw-------  1 root root    0 Jan 27  2010 opasswd
    [9] => -rw-r--r--  1 root root 2980 Apr  9  2008 pam_env.conf
    [10] => -rw-r--r--  1 root root 2180 Apr  9  2008 time.conf
)

But trying with more files …

exec("ls -al /etc/security/{access.conf,group.conf}", $output);
print_r($output);

ls: cannot access /etc/security/{access.conf,group.conf}: No such file or directory

Of course this works in console:

$ ls -al /etc/security/{access.conf,group.conf}
-rw-r--r-- 1 root root 4266 2008-04-09 15:25 /etc/security/access.conf
-rw-r--r-- 1 root root 3551 2008-04-09 15:25 /etc/security/group.conf
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:45:06+00:00Added an answer on May 20, 2026 at 7:45 am

    As mentioned in the comments, this is a problem of the shell expanding the {} shorthand, which does not happen in a PHP environment. You’ll have to supply the full paths separately:

    exec('ls -al /etc/security/access.conf /etc/security/group.conf', $output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to run a command in PHP like this: exec('dosomething > saveit.txt'); Except
I'm working on something that requires me to start to subprocess(command prompt) and execute
I need to execute mkdir command (e.g. via PHP's exec command). How do I
My problem is that, i am using Runtime.getruntime.exec() function to run my unix command
I need to issue this command via sudo in php. But sudo needs to
I need a java method that will read command prompt output and store it
I need to make a program, ioloop.c, which takes two command line parameters that
I hava access DB, one of my function(C#.net) need to Exec a SQL more
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.