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

  • Home
  • SEARCH
  • 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 9009677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:15:54+00:00 2026-06-16T02:15:54+00:00

Possible Duplicate: Equivalent of Backticks in Python I am looking for the best way

  • 0

Possible Duplicate:
Equivalent of Backticks in Python

I am looking for the best way to run a terminal command (ls -l) within Python. I have read about subprocess but I do not understand it fully, if someone could try and make me understand what is happening I would be grateful. I need to use the ls -l command to retrieve a hard link number which is != 1 and then save this number to match it against a directory number elsewhere. For now I would just like to know how to grab the hard link number and save it to a variable using subprocess (or a better method if there is one).

Here is the code I have used so far:
#!/usr/bin/python

#tool that resolves time machine directories 

import os

#create output file 
os.chdir("/home/sean/Desktop")
hard_link_number = open('hardLinkNumber.log', 'w')

#move into mounted backup (figure out how to remove xe2 etc)
os.chdir("/mnt/Backups.backupdb/stuart dent\xe2\x80\x99s MacBook Pro/2010-08-10-160859/MAc")

#find hard link data 
print>>hard_link_number, os.system("ls -la")
hard_link_number.close()

os.system(“ls -la”) outputs the information I require but it will not save it to the file I have created. I read elsewhere that os.system will not output data.

  • 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-06-16T02:15:55+00:00Added an answer on June 16, 2026 at 2:15 am

    You want os.stat (specifically the st_nlink attribute).

    Edit: To paraphrase jwz: Some people, when confronted with a problem, think “I know, I’ll parse the output of ls -l.” Now they have two problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Set undefined javascript property before read Is there an equivalent of Python's
Possible Duplicate: Python Ternary Operator Does Python have an equivalent of the ternary operator?:
Possible Duplicate: Python equivalent to perl -pe? Is there a way to process each
Possible Duplicate: Does JavaScript have a range() equivalent? Is there a way to declare
Possible Duplicate: remove_if equivalent for std::map I have a set of strings: set <wstring>
Possible Duplicate: Qt equivalent of PathAppend? Short story: does Qt 4 have an analog
Possible Duplicate: Looking for C# equivalent of scanf I am trying to convert a
Possible Duplicate: Does SQL Server 2005 have an equivalent to MySql’s ENUM data type?
Possible Duplicate: Equivalent to R in iOS I'm looking for something similar to the
Possible Duplicate: Objective C Equivalent of PHP’s Variable Variables I have created a method

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.