How to rename a file even when it shows permission Denied in Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to rename a file even when it shows permission Denied in Unix
# 1  
Old 12-06-2010
How to rename a file even when it shows permission Denied in Unix

While executing a script, I am not being able to able to create a file as the file with the same name already exists. That existing file is not getting overwritten as I am not the owner of the file. So, Neither am I able to rename the file nor delete the existing file, so as to get my file created.

How to rename the existing file and create my file from the script...
# 2  
Old 12-06-2010
Are you talking of a temporary file? Not being the owner is that case may be secondary: The permissions on the directory containing the file are more relevant... Temporary files are found normally in /tmp or /var/tmp etc... and are set read/write to all, but in some cases it can hold a sticky bit that is for only owner of the file can remove it...

Can you modify the script?
# 3  
Old 12-06-2010
If this is not a case of a single file then I would suggest to create your own directory and place all the files in it.

Otherwise you can check if file exists then create your file with some extension.
E.g.

Code:
fileName="name.txt"

if [ -e "$fileName" ] ; then
   file="name_new.txt"   # then create file
else
   touch $fileName    # create file with original name
fi

R0H0N
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing bash file with sudo for the second time, leads to permission denied, for some commands

I have a script that checks if the script has been ran with sudo. If the script is not ran as sudo, the current script is being executed with exec sudo bash. You are asked for a password, you type in the password, success. Everything is perfect - the commands inside the script are ran as sudo.... (1 Reply)
Discussion started by: boqsc
1 Replies

2. UNIX for Dummies Questions & Answers

Permission denied

when i run echo "User” > /dev/tty5 why do i get permission denied? :confused: (2 Replies)
Discussion started by: chinababy
2 Replies

3. Linux

Permission denied

I am using korn shell When I type in Telnet on cmd line, I get message "cannot execute" How can I get permission to execute command ? In which dir is telnet located ? I looked in /usr/bin dir. but its not there Thanks (1 Reply)
Discussion started by: paramshamnani
1 Replies

4. UNIX for Dummies Questions & Answers

mailx command - Temporary mail file: permission denied

Hi , I am facing a problem with respect to mailx command in unix . Earlier it was working fine and I am facing this issue only from last week . I used mailx command and I am getting a error message as follows : temporary mail file: Permission denied If I run mailx command from... (2 Replies)
Discussion started by: deepav1985
2 Replies

5. UNIX for Dummies Questions & Answers

Unable to copy file using SCP (Input/output & Permission denied error)

Hi, I am facing issue while using scp. Source & target machines are Linux & HP-UX respectively. On target machine, if I fire the following command, I get error: Now if I try scp on another file, which is on the same source machine, it works fine. All directories and subdirectories... (2 Replies)
Discussion started by: Technext
2 Replies

6. UNIX for Dummies Questions & Answers

Permission Denied creating file under nfs mount

I have two servers, 82 and 70. My exports file on 82 reads / ...70(rw) on 70 I have a mountpoint called mnt_for_82 I execute on 70 mount -t nfs -o rw ...82:/ mnt_for_82 I go to server 70 and indeed can read and travers the mounted subdirectories. However, I try... (0 Replies)
Discussion started by: blaine.miller
0 Replies

7. Red Hat

Permission denied

Hi guys im new to this db i have a small prob while installing websphereportal6.1i think i was installed succesfully but the error im getting is while starting server. check this out # ./serverStatus.sh -all Error loading: /usr/wps61/AppServer/java/jre/bin/classic/libjvm.so: cannot... (1 Reply)
Discussion started by: varma917989
1 Replies

8. UNIX for Dummies Questions & Answers

Why do I keep getting .:Permission denied?

I'll start off by saying that I know very little about Unix - however, I do know that I have a .profile file in my home directory, and that I should be able to invoke it by typing . profile. However, when I do this for ANY .filename, I get ".: Permission denied". I'm pretty sure that there is... (12 Replies)
Discussion started by: bbersani
12 Replies

9. UNIX for Advanced & Expert Users

Permission denied

Hi, I can not execute a .env file $ . /Data/oracle/d03/mydbora/8.0.6/MYDB.env -bash: /Data/oracle/d03/mydbora/8.0.6/MYDB.env: Permission denied Even if : -rwxrwxrwx 1 oracle dba 2903 Mar 5 2007 /Data/oracle/d03/mydbora/8.0.6/MYDB.env Please help. Many thanks. (1 Reply)
Discussion started by: big123456
1 Replies
Login or Register to Ask a Question