LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-07-2015, 11:42 AM   #1
Nagesh Kampati
LQ Newbie
 
Registered: Sep 2015
Posts: 2

Rep: Reputation: Disabled
File Permission


Hi all

I have some dough regarding permission issue i.e
Firstly creating a file after file creation remove all the permission of that file
that time I can access the file or not.
 
Old 09-07-2015, 12:04 PM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,510

Rep: Reputation: 2491Reputation: 2491Reputation: 2491Reputation: 2491Reputation: 2491Reputation: 2491Reputation: 2491Reputation: 2491Reputation: 2491Reputation: 2491Reputation: 2491
Quote:
Firstly creating a file after file creation remove all the permission of that file
that time I can access the file or not.
No, not as a user. Simple test I did which you can do. In your /home/user directory create a text file: touch testfile. Open it in a text editor and enter some random info. Change permissions: chmod 000 testfile Check the permissions: ls -l testfile, should show all dashes, no permissions. Open it in a text editor, it won't open and you get an error. Open it as root and it opens and can be edited.
 
Old 09-09-2015, 02:22 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually, you can open it in vi(m), but you get a warning. You can also edit it BUT to save changes you'll need to append '!' to the usual 'x' (or 'w').
Also, you can still change the perms back (assuming you own the enclosing dir).

@OP: Best thing to do with a qn like that is to try it
 
Old 09-10-2015, 09:04 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by Nagesh Kampati View Post
Hi all

I have some dough regarding permission issue i.e
Firstly creating a file after file creation remove all the permission of that file
that time I can access the file or not.
What actually happens is that the original file is deleted.

After all you are creating a new file...

Now, most utilities will not create a new file - instead they will truncate the original file, and open the file for writing. But that doesn't create a new file, though the distinction is rather small.
 
Old 09-11-2015, 06:07 AM   #5
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 22.04 LTS
Posts: 240

Rep: Reputation: 67
Quote:
Originally Posted by jpollard View Post
What actually happens is that the original file is deleted.

After all you are creating a new file...
I'm not the OP, but I lost you there...

You're saying if you change permissions to 000 you create a new file?
 
Old 09-11-2015, 09:15 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Depends on how the file gets opened.

Normally, you can't delete the file - and the open fails.

Some of the older editors (at least used to) delete/rename the file (to have a backup), then open a new one. Current editors appear to open with truncate when they write a new file... vi can write the file even if the access mode is 000 and it is the owner writing it (the w! form) without changing the file. nano (with -B) copies the file to create the backup instead of renaming.

The linker (at least when invoked by gcc) will delete the old executable file and create a new one. So even if the old file had 000 on it, it will be replaced. (In my quickie test, it also gets a new inode).

If the file modes were 000 and the file after whatever operation the OP did has a different access mode, then the file likely got deleted and a new one created. Could even get the same inode number, though I would think that would be rather rare.

Files used for locks get strange (preventing race conditions is tricky).

Now the base system call will not delete the file if O_CREAT is used. If not specified (the usual case), then the existing file may be opened with modes determined by default.

Language runtimes can do different things - it depends on the runtime and language definition then.

Last edited by jpollard; 09-11-2015 at 10:18 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ext4 - permission to create/modify a file without 'delete' permission BeachHead Linux - General 4 06-08-2014 07:34 PM
File & Folder Permission and Ownership permission error in Cloud storage. rhcekumaran Linux - Newbie 3 06-14-2013 04:41 AM
[SOLVED] Apache 403 file permission error when accesing a symlink file (CentOS 6.3) mkvakic Linux - Newbie 7 02-13-2013 03:25 AM
Reading ext3 file system on Mac and overriding file permission moravveji Other *NIX 6 09-12-2011 02:25 AM
Any log file for checking file permission change history in RHEL 5.1? bilalcochin Linux - Newbie 3 04-02-2010 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration