How to compare two same name files in different directories using meld (without giving their path)? - linux

I know commands:
To find path of file:
find . -name filename
To compare two files:
meld path_of_file_in_one_dir path_of_file_in_second_dir
I have to compare so many files in different sub directories of a directory, every time I have to first search the path of that file and then use this path with meld, and this I have to for each file.
It would be very easy if i only give names and root directory of that files to meld.
How can I combine meld and find commands so that I can apply it on each file?

If your directory structure is like this say
test_folder
test1
file_to_cmp
test2
file_to_cmp
test3
file_to_cmp
then you can run the following
meld find . -name "file*" or
meld find . -name "file_to_cmp"
This will compare the 3 files for sure.
About more than three file comparing, I doubt meld can do it.

Related

How do I get list of paths that exclude certain subdirectories

I want to copy all my projects to google drive using rclone, but I don't want to copy files in directories like node_modules,
Example:
root: project
subdirecotry: myBlog/node_modules/, myBlog/backend/node_modules.
I am an beginner in Linux so I don't know how to achieve it using find, grep, etc.
You are asking two questions.
How to list paths that exclude certain subdirectories
How to exclude certain subdirectories when using rclone
Listing
Use the find command. Here is an example directory with three subdirectories:
ls
one two three
To output a listing of only one and two, omitting three, use find like this:
find . -type d -not -path ./two
.
./one
./three
rclone
Use the --exclude switch, to exclude the contents of specific subdirectories - in this example, the subdirectory two (underneath stackoverflow), would be ommitted in the sync to destination:
rclone sync stackoverflow/ destination/ --exclude='two/**'
See the rclone documentation for further details.

copy/move same name multiple files in different folder

I have multiple files in different folders with the same name and extension. For example: There are 460 folders and each folder has one file with the name of snps.vcf. I want to copy/move these files to one folder and later on, I will do some analysis that I need to do.
I have tried:
find -type f -name "*.vcf" -exec cp {} /home/AWAN/try';'
but this code overwrites the files and only one file remains there in the end.
I have tried rename but I don't know how to select multiple files by find command then rename. Even with the mmv I couldn't find the possible solution.
You need to write an external script and pass it to -exec.
Your script may use mktemp to generate a random file name. Example:
mktemp /your/directory/try-XXX
The XXX part will be replaced by mktemp with a different value for each call.

Copying files from multiple directories to another directory using linux command line

I have a bunch of files in separate folders, and all of the folders are in one directory.
/var/www/folder1/file1.txt
/var/www/folder1/file2.txt
/var/www/folder1/file3.txt
/var/www/folder2/file4.jpg
/var/www/folder2/file5.jpg
/var/www/folder2/file6.jpg
/var/www/folder3/file7.pdf
/var/www/folder3/file8.doc
/var/www/folder3/file9.gif
I need everything inside of the folders that are inside of /var/www/ to be copied to another directory (say, /var/my-directory/), but not the actual folders. Based on the example above, I need /var/my-directory/` to look as follows:
/var/my-directory/file1.txt
/var/my-directory/file2.txt
/var/my-directory/file3.txt
/var/my-directory/file4.jpg
/var/my-directory/file5.jpg
/var/my-directory/file6.jpg
/var/my-directory/file7.pdf
/var/my-directory/file8.doc
/var/my-directory/file9.gif
I can't seem to figure out the command to do this. I've tried the following:
sudo cp -R /var/www/./. /var/my-directory/
But, that still copies all of the folders.
Is there any way to do what I'm trying to do?
Use find.
find /var/www/ -type f -exec cp '{}' /var/my-directory/ \;
The trick is -type f that only selects file.

use ls command to find some *.app files on macos

There are some .app files in the folder, such as
folder_A/1.app
/2.app
/subF/3.app
/3.txt
Then i want to use ls command to check if there are any .app files under folder_A, i can use ls -R folder_A to list all the files under "folder_A" and sub folder "subF", but on Macos, the app file is also considered as an directory that ls will list all the files contained in 1.app,2.app and so on.
For example, 1.app contains some .png,.txt; then ls -R folder_A will return all the png and txt files, not the 1.app itself. But i want to list all the app files under folder_A and its sub folder without list all the files included in .app.
The trick is to use the right tool for the job.
find folder_A -name '*.app'
The find command is better suited for traversing a directory hierarchy.
find folder_A -name '*.app'
Find can be easily used to search on specific files
find folder_name -name "*.app" -print
folder_name can be an absolute path or a relative path.

Move all files in specified folder up one directory

I have a program that extracted files to a series of sub-folders each with a "header" sub-folder. For example:
/share/Videos/Godfather.Part.1
/share/Videos/Godfather.Part.1/<packagename>
/share/Videos/Godfather.Part.1/<packagename>/Godfather.avi
/share/Videos/Godfather.Part.2
/share/Videos/Godfather.Part.2/<packagename>
/share/Videos/Godfather.Part.2/<packagename>/Godfather2.avi
I'd like to take the files in the specified folder <packagename> and move them up one directory so that the file structure looks like this:
/share/Videos/Godfather.Part.1
/share/Videos/Godfather.Part.1/Godfather.avi
/share/Videos/Godfather.Part.2
/share/Videos/Godfather.Part.2/Godfather2.avi
How can I accomplish this task in bash command line? Mind you this is an example using 2 folders, I have 100's like this.
Share and enjoy.
for i in `find . -name "*avi"`
do
dest=`dirname $i`
mv $i $dest/..
done

Resources