Makefile is acceptable only for reading - makefile

I created a makefile, made some entries and saved. Then in a while I founded out the file is opened only for reading, in spite of my writing right for it is available. I tried to re-set the rights entering chmod -c u+wrx [file path] and then ls -l [file path] for reviewing and it didn`t use to change anything!

Related

unzip .bin file programatically in ruby

I have a .bin which i am trying to unzip programatically. The directory is a temp directory in which the.bin file is saved.
I have tried to the following
change the permission of bin files by typing.
chmod -c 777 filenam.bin.
now run the bin file by typing
here is a ruby code which i have
%x(gunzip #{label_path})
using above gunzip gives me this error
unknown suffix -- ignored
I shows error as illegal option c.
Can anyone help. Thanks.
gunzip has an option -S to specify a suffix of the file to be unzipped:
gunzip -S .bin filenam.bin
The above will produce file filenam in the same directory.

Cannot run ctags after executing "ln -s /usr/bin/ctags-exuberant"

By mistake I have executed the following command on my redhat office machine and now I cannot run ctags -R * any more.
ln -s /usr/bin/ctags-exuberant
Hope following info helps,
[ypp:~]$ ls /usr/bin/ctags-exuberant
[ypp:~]$ ls: /usr/bin/ctags-exuberant: No such file or directory
[ypp:~]$ unlink /usr/bin/ctags-exuberant
unlink: cannot unlink /usr/bin/ctags-exuberant': No such file or directory
[ypp:~]$ which ctags
alias ctags='/usr/bin/ctags'
/usr/bin/ctags
[ypp:~]$ ln -s /usr/bin/ctags-exuberant /usr/bin/ctags
ln: creating symbolic link '/usr/bin/ctags' to '/usr/bin/ctags-exuberant': File exists
[ypp:~]$ ln -s /usr/local/bin/ctags /usr/bin/ctags-exuberant
ln: creating symbolic link ,/usr/bin/ctags-exuberant' to '/usr/local/bin/ctags': Permission denied
So far I have tried,
[ypp:~]$ rm /usr/bin/ctags-exuberant
/bin/rm: cannot lstat /usr/bin/ctags-exuberant': No such file or directory
[ypp:~]$ rm -i /usr/bin/ctags-exuberant
/bin/rm: cannot lstat /usr/bin/ctags-exuberant': No such file or directory
[ypp:~]$ unlink /usr/bin/ctags
unlink: cannot unlink /usr/bin/ctags': Permission denied
Please tell me how do I get my ctags working back to normal,
I don't have superuser privilege also.
According the manpage, ln creates a link to file TARGET with the name LINKNAME. If LINKNAME is omitted, as was your case, a link to TARGET is created in the current directory, using the name of TARGET as the LINKNAME. As a result, when you executed ln -s /usr/bin/ctags-exuberant a symbolic link (sometimes called soft link) named ctags-exuberant would have been created in your present working directory pointed at /usr/bin/ctags-exuberant.
There seems to be more at play than what you have shared with us here. Simply creating a link to ctags-exuberant in any directory should not have resulted in the changes you are experiencing. Where there other changes made to your path?
If, somehow just creating the link has caused all your troubles, then you need to focus on finding the resulting link and removing it. If you don't know what directory it was created in, you could find it via the following:
find / -type l -name 'ctags-exuberant' 2>/dev/null
Once it is found, remove it and see if that fixes your problems. Let us know what you find.
Else, you might do better to try the wise minds over at https://unix.stackexchange.com/

Error copying directories at command line using cp

Mac OS X Yosemite v.10.10.5.
I am trying to use the cp command to copy one Git directory to another.
This command-line statement:
cp -r /path/to/dir/from/ /path/to/dir/to/
Returns this error:
cp: /path/to/dir/to/.git/objects/00/00ad2afeb304e18870d4509efc89fedcb3f128: Permission denied
This error is returned one time each for (what I believe, but haven't verified, is) every file in the directory.
The first time I ran the command it worked properly, as expected, without error. But, without making any changes to any files, the second (and subsequent) times I ran the command, I got the error.
What's going on? And how can I fix this?
Edit:
In response to a question in the comment:
What does ls -l /path/to/dir/to/.git/objects/00/00ad2afeb304e18870d4509efc89fedcb3f128 show?
The answer is it shows:
-r--r--r-- 1 myusername staff 6151 May 6 00:45 /path/to/dir/to/.git/objects/00/00ad2afeb304e18870d4509efc89fedcb3f128
The reason you are getting Permission Denied is because you are trying to overwrite a file that already exists in the destination directory that has read only permissions set on it. Since it appears you're trying to overwrite it you could just remove the destination directory if it exists before the copy operation. Also you should use -R, not -r ...
Historic versions of the cp utility had a -r option. This
implementation
supports that option; however, its use is strongly discouraged, as it
does not correctly copy special files, symbolic links, or fifo's.
Using a command such as this should resolve your issue:
[[ ! -d dest ]] || rm -rf dest ; cp -R src dest
The above checks if dest exists; if it does recursively remove it, then copy the source to dest,
You may want cp -rp for this operation. -p preserves the user and group IDs associated with the file. Try starting over using -p and see if that solves the issue.
Anther reason you might be seeing this issue is if the permission really is denied. That is, if you're trying to copy into a folder owned by another user without superuser privileges.

Need bash script to watch Directories and perform actions on new files and modified files

I want to watch mydirectory/
I created inot.sh and ran it in the background as # ./inot.sh &
Here's the first version of the script inot.sh that I tried:
#!/bin/bash
inotifywait -m -e create,modify --exclude '\*.swp?$' . |
while read dir ev file; do
cp "$file" inotfiles/"$file"
done
Note: the exclude pattern is supposed to exclude vim swap files but doesn't seem to be working yet.
If any file is created (or changed), I want the whole file copied to a storage folder. For now I'm focusing on create,modify just to see if I can get anything at all to work correctly.
At this point, FTP uploads seem to work correctly. Using the command line to touch a file copies the empty file. But then using vim to edit it results in a bunch of problems.
I edited an existing file in vim and did not change it. When I entered the file, I get:
cp: cannot stat `.zzzzzoo.txt.swx': No such file or directory
~
~
~
~
~
It looks like the first line is part of the file, but it's not. It's inotify interfering with the vim viewer. Upon exit, everything looks normal.
But sometimes I get that same cp error message on exit from vim.
If I edit the file and exit with write to file, I get:
Upon exit from vim, I get:
~
~
~
~
~
~
"zzzzzoo.txt" cp: cannot stat `4913': No such file or directory
"zzzzzoo.txt" 1L, 11C written
[root#server mydirectory]# cp: cannot stat `.zzzzzoo.txt.swp': No such file or direc
tory
1st part with tildes is from vim.
"somefile.txt" cp: cannot stat `4913': No such file or directory
"somefile.txt" 7L, 129C written
EDIT: adding 1 more error I forget to mention
When I open the copied file in vim, I get a notice that vim found a swap file for the same file name.
E325: ATTENTION
Found a swap file by the name "inotfiles/.somefile.txt.swp"
etc, etc.
Swap file "inotfiles/.somefile.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
// End edited section
So I know I might be able to fix this problem by properly excluding vim swap files, but it seems to me that the larger question is "Why are cp errors going to stdout and how to stop them?" I should pipe them somewhere else probably.
Also I need a way to prevent an infinite while loop. Is there any other way to write that section?
Instead of asking inotifywait to watch out for vim's swap files, why not get vim to
put it's temporary files in a better (less intrusive) location:
For example, how about:
mkdir -p ~/tmp/.vim
And then in your .vimrc
set backupdir^=~/tmp/.vim/
set directory^=~/tmp/.vim/
http://vim.wikia.com/wiki/Remove_swap_and_backup_files_from_your_working_directory
Think about it: What if you do get your regexes to exclude swap files - and then an emacs user joins you and wants to use emacs to edit files in the same directory - you'll have a mess of regexes before you know it!

How can I compress a directory, and convert soft to hard links?

I would like to compress a directory.
tar -cvzf mydir.tar.gz mydir
but this retains symlinks so that it is not portable to a new system.
How can I convert symlinks?
I have tried
tar -cvzfh
since man tar says
-h, --dereference
don’t dump symlinks; dump the files they point to
but this results in an error
tar: Error exit delayed from previous errors
and creates a file called "zh"
My files are on a RHEL server.
Your tar.gz file name must follow immediately after the -f flag, merely reordering the flags may work.
tar -cvzhf mydir.tar.gz mydir

Resources