unzip .bin file programatically in ruby - 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.

Related

Can't create file in Bash on MinGW64

Having an executable file in a directory, let's say named hello.exe:
$ ls
hello.exe*
The file name is colored green and an asterisk is appended.
Listing the file explicitly by giving its name but without extension, it is listed without extension:
$ ls hello
hello*
Until here it looks just like a funny feature for Win freaks that like to omit the .exe extension.
But now, when you try to create a file without any extension, Bash complains:
$ echo hello > hello
bash: hello: Permission denied
The same problem arises when you try to copy a folder structure recursively which contains a folder hello/ and an executable hello.exe in the same folder:
It cannot be copied using cp -r when (by accident) the file hello.exe is copied first and the folder hello/ is copied second; the creation of the folder is denied in this case:
cp: cannot overwrite non-directory './hello' with directory './hello'
Now my question is:
Is this a bug or a feature? If it is a feature, how can I disable it?
The system I'm using is a MINGW64 Bash on Windows 10.

Unzip multiple files into directory with same name

I have a zip archive and I want to extract only files that start with 'word' and put them into a directory 'dest_dir' under the same file name (wordxxxx.csv)
I have tried the following command:
unzip -p archive.zip dir1/dir2/word*.csv -d dest_dir
But I get this error even though I have full control permissions over dest_dir
Access denied
Should I create a loop or something?
The -p option was the actual problem. I resolved it with:
unzip archive.zip dir1/dir2/word*.csv -d dest_dir

What happens when you try to move a file to a non-existant location MAC?

On executing the following lines via the terminal on a MAC,
mv terraform2 ~/bin
cd ~/bin
I get the error that '/Users/myname/bin: Not a directory`. However, I can't see the file terraform2 in its original location. Where did it go?
Given
mv terraform2 ~/bin
If ~/bin doesn't exist before you run that command, your file terraform2 will be renamed to a file called ~/bin.
Thus, when you try
cd ~/bin
you get
/Users/myname/bin: Not a directory
because it's a file - your original terraform2 file.
The command
mv terraform2 ~/bin/.
is much better when you're trying to mv a file into a directory.

Copying from mount share drive to local folder through script

This is my first time trying to work with Linux Scripts so this may be something obvious.
Here is what I am trying to do:
Remove all contents from local folder - rm /home/user/Documents/Exercise/
Copy files from a shared windows network drive - cp smb://server/arc/Exercise%20Files/Word/
So from my understanding my command should look like this
rm /home/user/Documents/Exercise/
cp smb://server/arc/Exercise%20Files/Word/ /home/user/Documents/Exercise/
But anytime I try and run either of the above commands I get the following error:
"rm: cannot remove `/home/user/Documents/Exercise/': Is a directory"
"cp: cannot stat `smb://server/arc/Exercise%20Files/Word/': No such file or directory"
What am I doing wrong?
Kind Regards,
M
Based on your request and your test, let me point what is not written properly:
Remove all contents from local folder
rm /home/user/Documents/Exercise/
Error says rm: cannot remove /home/user/Documents/Exercise/': Is a directory
You should
rm /home/user/Documents/Exercise/*
which will delete everything inside the directory, but not the directory.
Copy files from a shared windows network drive
cp smb://server/arc/Exercise%20Files/Word/ /home/user/Documents/Exercise/
Error says cp: cannot stat smb://server/arc/Exercise%20Files/Word/': No such file or directory
You should check if route smb://server/arc/Exercise%20Files/Word/ is correct. Then, use the following:
cp smb://server/arc/Exercise%20Files/Word/* /home/user/Documents/Exercise/
You can't delete a directory if it has content within it.
To delete the content and the directory at the same time, use the following command:
rm -r /home/user/Documents/Exercise/
This recursively deletes the directory and any content within it.
To copy the file, I believe you have to mount the directory beforehand, like so:
mount -t cifs //server/share /mnt/mount_directory -o user=username
Can you confirm if that works?
Remove / Delete Command:
rm -rfv /home/user/Documents/Exercise/*
Copy Command:
cp -rfv /home/user/Documents/ExerciseShare/ExerciseFiles/Word/ /home/user/Documents/Exercise/

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