From the 7-Zip Help file:
Adds files to archive.
Examples
7z a archive1.zip subdir\
adds all files and subfolders from folder subdir to archive archive1.zip. The filenames in archive will contain subdir\ prefix.
7z a archive2.zip .\subdir\*
adds all files and subfolders from folder subdir to archive archive2.zip. The filenames in archive will not contain subdir\ prefix.
cd /D c:\dir1\
7z a c:\archive3.zip dir2\dir3\
The filenames in archive c:\archive3.zip will contain dir2\dir3\ prefix, but they will not contain c:\dir1\ prefix.
So the command you'd want would be: 7za.exe a folder1.zip .\folder1\*
Also, pay attention to 7-Zip's handling of wildcards. It doesn't treat *.*
as "all files" -- it means "all files with a period in the filename." Extension-less files will be missed. If you really want all files, just use *
instead.
Finally, the -tzip
parameter isn't needed if the archive filename ends in .zip
. 7-Zip is smart enough to figure out which format you want in those cases. It's only required when you want a custom extension (e.g. 7za.exe a -tzip foo.xpi <files>
for a Mozilla Add-on).
With Larry Wall's rename
/prename
(*) you can easily "flatten" the structure:
cd mainfolder
rename -n 's:/:-:g' */*/*.jpg
This will move subfolder1/0001.jpg
to subfolder1-0001.jpg
(in mainfolder
) because rename
edits the whole input path and then does the equivalent of mv
using source and edited names.
For instance:
Starting with
.
├── sub1
│ ├── subsub1
│ │ ├── 001.jpg
│ │ ├── 002.jpg
│ │ └── 003.jpg
│ └── subsub2
│ ├── 001.jpg
│ ├── 002.jpg
│ └── 003.jpg
└── sub2
├── subsub1
│ ├── 001.jpg
│ ├── 002.jpg
│ └── 003.jpg
└── subsub2
├── 001.jpg
├── 002.jpg
└── 003.jpg
Execute:
rename s:/:-:g */*/*.jpg
This results in:
.
├── sub1
│ ├── subsub1
│ └── subsub2
├── sub1-subsub1-001.jpg
├── sub1-subsub1-002.jpg
├── sub1-subsub1-003.jpg
├── sub1-subsub2-001.jpg
├── sub1-subsub2-002.jpg
├── sub1-subsub2-003.jpg
├── sub2
│ ├── subsub1
│ └── subsub2
├── sub2-subsub1-001.jpg
├── sub2-subsub1-002.jpg
├── sub2-subsub1-003.jpg
├── sub2-subsub2-001.jpg
├── sub2-subsub2-002.jpg
└── sub2-subsub2-003.jpg
And you can get rid of the subdirectories using
rm -r sub*/
(final slash is important! it restricts the match to directories)
So finally:
.
├── sub1-subsub1-001.jpg
├── sub1-subsub1-002.jpg
├── sub1-subsub1-003.jpg
├── sub1-subsub2-001.jpg
├── sub1-subsub2-002.jpg
├── sub1-subsub2-003.jpg
├── sub2-subsub1-001.jpg
├── sub2-subsub1-002.jpg
├── sub2-subsub1-003.jpg
├── sub2-subsub2-001.jpg
├── sub2-subsub2-002.jpg
└── sub2-subsub2-003.jpg
If you have a huge collection of files, you cannot process in one call because the file expansion of **/*.jpg will generate a list which is too long (/bin/sh: 1: rename: Argument list too long`). So you have to split the work, for instance by calling rename once by directory:
shopt -s globstar
for d in **/; do rename s:/:-:g "$d"*.jpg; done
(the /
in '**/' is important, it restricts the expansion to directories)
If you still get the Argument list too long
message then you have a directory with very many files :) You just have to find a way to split the work, for instance:
for f in path/to/hugedir/A*;jpg; do rename s:/:-:g "$d"*.jpg; done
for f in path/to/hugedir/B*;jpg; do rename s:/:-:g "$d"*.jpg; done
[... etc ...]
If this is still too big and or you want to be blunt, you can also call rename once for each file:
shopt -s globstar
for f in **/*.jpg; do rename s:/:-:g "$f"; done
(this will work because here the expansion of "**/*.jpg" is just a variable in your shell, and not the list of arguments to a command).
PS: bash
assumed here, if you are putting this in a script, make sure the "shebang" is /bin/bash
, on some systems sh
is a lightweight shell (dash
) that doesn't support globstar
.
(*) name varies depending on distro, rename
for Debian/Ubuntu and derivatives, and IIRC prename
on RedHat and derivatives.
Best Answer
Open the terminal.
Change directory to the parent directory of folder1 using the
cd
command.Run this command to rename all files with .jpeg extension to .jpg.
The above command uses the Perl
rename
program which is installed by default in Debian-based operating systems. In some other Linux distributions, the same Perl rename program is called prename. prename can be installed by following the instructions from: Get the Perl rename utility instead of the built-in rename.