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 7913229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:47:36+00:00 2026-06-03T13:47:36+00:00

My C program (on Linux) needs to delete a file, say, /home/me/myfile, here is

  • 0

My C program (on Linux) needs to delete a file, say, /home/me/myfile, here is how I do it in my program

...
system ("rm -f /home/me/myfile");
...

When running this program, I got a message saying permission denied. BTW, ls -al /home/me/myfile returns -rw-r--r--

However, under the same user account and in the same shell I execute the C program, I can simple delete the file by typing rm -f /home/me/myfile

What did I miss here?

Thanks,

Update: Using remove(/home/me/myfile) or unlink(/home/me/myfile), the file can be deleted in my program.

  • 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-03T13:47:37+00:00Added an answer on June 3, 2026 at 1:47 pm

    For a start, it’s the permissions on the directory that control whether you can delete a file.

    But, having said that, there are numerous things that could be different between the two situations. Your program might be running as a different user (such as with the SETUID bit), the path may be different, leading to a different rm being run, the program may set up a chroot jail so that it can no longer even see the file (though that may manifest as a different error), and so forth. The possibilities are rather large.

    However, C provides a call to delete files, called unlink – you should use that in preference and then check errno.

    I would suggest checking the output of which rm in both cases, along with the full details of the file and executable, owner and permissions.

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

Sidebar

Related Questions

Subject says it all: the program, running under Linux, needs to know how it
i got a program that needs to check if a chunk of a file
Question: Is it possible to compile a program on linux using a .dll file?
I'm writing (under linux or windows+cygwin) a java program that needs to run a
I'm trying to use this function in a C program that needs to be
I have a java program running on a linux server. I need to send
I'm working on a system that was developed for linux and that needs the
I wrote a Linux program based on a buggy open source library. This library
I am writing a C++ program which needs to create a temporary file for
So I'm running PPP under linux with a cellular modem. The program I'm writing

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.