Unzip multiple files into directory with same name - windows

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

Related

Output A tar archive into a specific path in a bash script

I have a part in my script that uses tar to archive some folders. It should output the archived result to a specified folder.
The following tar command outputs the file to the right folder but makes the resulted archive nested with the full path leading to it.
e.g.
Inside my tar file I have the following folders:
full/path/to/file
The folder structure shouldn't look like that it should be relative to the parent folder not the root folder.
Here is the code:
...
local PROJECTS=(~/path/to/folder/*)
...
local PROJECT_PATH="${PROJECTS[$i]}"
local BACKUP_NAME=`date +%d%b%y`.tar.gz
echo Making folder "${PROJECT_PATH}"/backups
tar -czvf $PROJECT_PATH/backups/$BACKUP_NAME $PROJECT_PATH --exclude="${PROJECT_PATH}"/node_modules --exclude="${PROJECT_PATH}"/backups
If you want tar to save paths relative to some directory, use -C to change to that directory and provide relative paths:
tar -czvf "$PROJECT_PATH/backups/$BACKUP_NAME" -C "$PROJECT_PATH" . --exclude=./node_modules --exclude=./backups
-C "$PROJECT_PATH" tells tar to change to the $PROJECT_PATH directory, and the following . tells it to archive its current directory.

Name not matched in creating zip folder with bash

I'm trying to create a zip folder in a bash script that contains the current date (YYYY_MM_DD).
I have this code:
currentArchive=$(date '+%Y_%m_%d')
zip -r ./aktuell ./Archive/${currentArchive}-bkt
But when I run the script I get the following error:
zip warning: name not matched: ./Archive/2017_03_30-bkt
I want the folder "aktuell" as a zip folder named "2017_03_30-bkt.zip" in the folder "Archive". The current folder "aktuell" exists.
What am I doing wrong?
You have the source and destination directories backwards in your zip command. Also, make sure the destination directory exists before executing zip.
currentArchive=$(date '+%Y_%m_%d')
mkdir -p ./Archive/
zip -r ./Archive/${currentArchive}-bkt ./aktuell

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.

How to search a directory in unix and copy it to another Directory

Suppose I have one folder XYZ having some directory and files.I want to search this XYZ folder in the /tmp directory of the linux machine and then copy the entire folder to /tmp/lib/ folder.
Can anyone please tell the unix command to achieve this.
Thanks !!
Use on of these commands:
To copy:
rsync -a /tmp/XYZ/ /tmp/lib/XYZ/
cp -R /tmp/XYZ/ /tmp/lib/
To search for a file with abc in its name:
find /tmp/XYZ -name \*abc\*

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/

Resources