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

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.

Related

Extracting with subfolders but without parent folders

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.

Moving files from current directory to one directory below

I am trying to move 2 files from current directory (/base/level1/level2) to one directory below (/base/level1)
Is there any easier command other than mv file1 /base/level1 ? I'm trying to understand if we have some command that move it to a specific level up or down in the current folder structure.
TIA!
My solution to this one is navigating to the path where I want to move the file and run the following command.
cp ./level2/file1 .
or
cp ./file1 ./level2/file1
Please share other solutions as well
Thanks,
AMK
You could use wildcards if the 2 files have something uniquely in common.
ie. mv file*.ext path/to/new/dest/
This will move all files starting with "file" and ending with the extension ".ext" to the destination. Have a look at this and this which will explain wildcards a bit more
You can always use .. for "one directory up".
And you can give more than 2 arguments to mv, the last always being the destination.
So mv file1 file2 .. would move those 2 files a directory up.
Or mv * .. to move all files.

Unix recursive listing only of complete path of files

I have a set of directories with files and I want to get a clean list of the absolute paths of all the files in these directories, something like this
Having
\home\me\DirA\
fileA
fileB
some_directory_that_i_dont_want_listed
\home\me\DirB\
fileB
fileC
....
\home\me\DirXYZ\
fileOPQ
and get
\home\me\DirA\fileA
\home\me\DirA\fileB
\home\me\DirB\fileB
\home\me\DirXYZ\fileOPQ
Is this possible with a ls command?, I've tried ls with -R but it lists only the filenames.
Try this command:
$ find /home/me/Dir[AB]
Hope this helps! :)
For the case it's of use to anyone, it's simple
find /home/me
lists everything with absolute paths.
If you need to filter a specific extension
find /home/me -name *.someExt

Rename files in different folders removing numbers from file names

I'm trying to remove numbers from file names stored in different folders.
Specifically, I have 100 folders named: my_folder1, my_folder2, my_folder3,..., my_folder100.
In each folder there are files named: my_folder1.txt for my_folder1, my_folder2.txt for my_folder2, my_folder3.txt for my_folder3, ...my_folder100.txt for my_folder100. I need the following output:
my_folder.txt for my_folder1, my_folder.txt for my_folder2, my_folder.txt for my_folder3, ..., my_folder.txt for my_folder100. In other words I need to remove the numbers from file names in each folder. I used the following code:
for file in `find . -name 'my_folder*.txt'`; do
mv $file ${file/+([0-9]).txt/.txt}
done
but the numbers are still there.
Can anyone help me please?
Best
Are you looking for:
for file in */*.txt; do mv $file $(dirname $file)/my_folder.txt; done

Rename many images with names from file

I have a file with a list of names. Let's call it nameFile. For example:
John Doe
John Benjamin
Benjamin Franklin
...
I also have a folder of pictures. The pictures are named like:
pic001.jpg
pic002.jpg
pic003.jpg
...
I want to rename each picture with the corresponding name from the nameFile. Thus, pic001.jpg will become 'John Doe.jpg', pic002.jpg will become 'John Benjamin.jpg', etc.
Is there an easy UNIX command to do this? I know mv can be used to rename, I'm just a bit unsure how to apply it to this situation.
Mostly people do it by writing a simple shell script.
These two links will help you to do it.
Bulk renaming of files in unix
Rename a group of files with one command
The mv is a Unix command that renames one or more files or directories. The original filename or directory name is no longer accessible. Write permission is required on all directories and files being modified.
mv command syntax
You need to use the mv command to rename a file as follows:
mv old-file-name new-file-name
mv file1 file2
mv source target
mv [options] source target

Resources