very simple question:execute unix command inside script

Posted on 1998-06-11
Last Modified: 2010-03-05
How can I execute unix commands like "ls" ,"date" inside perl script and print output to a file?

Question by:tian

Author Comment

Comment Utility
Edited text of question

Accepted Solution

martinag earned 50 total points
Comment Utility
# This puts the output from date function in $date.
# Be sure to use backticks!
$date = `date`;

# Print result to output.txt
open (OUTPUT, ">output.txt") or die "can not open file: $!";
print OUTPUT $date;
close OUTPUT;
LVL 84

Expert Comment

Comment Utility
and if you're specifically interested in `ls` and `date`,
it would be faster and more portable to use the built in readdir and localtime functions.

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now