Extracting with subfolders but without parent folders - unzip

I have a zipfile structured like this:
- root
- subfolder
- subsubfolder
- file1
- file2
- file3
- file4
Using 7zip, I would like to extract the archive in such a way, that the resulting structure is:
- subsubfolder
- file1
- file2
- file3
- file4
My problem is, that neither 7z e nor 7z x accomplish this. When I use
7z x archive.zip root/subfolder
the structure doesn't change, as the files retain their full paths, and when I use
7z e archive.zip root/subfolder
the files retain no path at all, leaving me with a flat structure an an empty subsubfolder.
Edit: Unzip or any other kind of zip-tool I can use in Linux would also be fine.

Related

How to move a number of files to a directory only if their name exists in another directory of files, in one line?

Imagine that I have three directories like this:
Directory One: file1 file2 file3 file8
Directory Two (tags): file1 file3
Directory Three: empty
I want to check if the file exists in Directory Two move the file from Directory One to Directory Three, in one line if possible.
Final desired output:
Directory One: file1 file2 file3 file8
Directory Two (tags): file1 file3
Directory Three: file1 file3
Thanks in advance.
for file in directory2/*; do mv directory1/"$(basename "$file")" directory3/; done

How to only display the file difference between two folder recursively in a Unix command?

A have 2 directory : dir1 and dir2. In the dir1 I have some pictures files and in the dir2 I have the same pictures files and more in many subdirectories.
I used :
diff --brief -r dir1/ dir2/
Output :
Only in /Users/Name/Pictures/Bibliothèque Photos.photoslibrary/Masters: 2013
Only in /Users/Name/Pictures/Bibliothèque Photos.photoslibrary/Masters: 2014
Only in /Users/Name/Pictures/Bibliothèque Photos.photoslibrary/Masters: 2015
Only in /Volumes/Data/Photo Compare: IMG_0002.JPG
Only in /Volumes/Data/Photo Compare: IMG_0003.PNG
Only in /Volumes/Data/Photo Compare: IMG_0004.JPG
Only in ...
But this only show me that folders in dir2 are not in dir1 and for dir1 the pictures files in dir1 are not on dir2.
But the only thing I want is the pictures files difference between these folders recursively.
Does anyone knows ?
I didn't find my solution on forums and so on...
I also tried to make my own script but it doesn't work either.

Unzip only limited number of files in linux

I have a zipped file containing 10,000 compressed files. Is there a Linux command/bash script to unzip only 1,000 files ? Note that all compressed files have same extension.
unzip -Z1 test.zip | head -1000 | sed 's| |\\ |g' | xargs unzip test.zip
-Z1 provides a raw list of files
sed expression encodes spaces (works everywhere, including MacOS)
You can use wildcards to select a subset of files. E.g.
Extract all contained files beginning with b:
unzip some.zip b*
Extract all contained files whose name ends with y:
unzip some.zip *y.extension
You can either select a wildcard pattern that is close enough, or examine the output of unzip -l some.zip closely to determine a pattern or set of patterns that will get you exactly the right number.
I did this:
unzip -l zipped_files.zip |head -1000 |cut -b 29-100 >list_of_1000_files_to_unzip.txt
I used cut to get only the filenames, first 3 columns are size etc.
Now loop over the filenames :
for files in `cat list_of_1000_files_to_unzip.txt `; do unzip zipped_files.zip $files;done
Some advices:
Execute zip to only list a files, redirect output to some file
Truncate this file to get only top 1000 rows
Pass the file to zip to extract only specified files

Find a file in directory where i know part of the filename and the extension

I know the file im looking for begins with a data for example 20131111 and I know the file ends in .log, but I don't know the full file name,
what is a unix command that would allow me to see all files beginning with or containing this date and ending with .log.
Like this, for example:
find /certain/path -type f -name "20131111*.log"
-type f - just files.
-name "20131111*.log" files whose name starts with 20131111 and ends with log.

Get a list of files with full path

I would like to get a list of all the files in a directory hierarchy (like I would with ls -R), but such that instead of listing the name of the directory and its files beneath it, it would just output a list of files with their full path. Is this possible?
Use find for this type of thing.
find /home/me/subdir
will list all the files and directories, with full path, that live in /home/me/subdir.
find /home/me/subdir -type f
will only list files. (-type d for directories.)
If you need to match a filename glob, do like this:
find /home/me/subdir -type f -name "abc*"
Or exclude a file name pattern:
find /home/me/subdir -type f ! -name ".*"

Resources