LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-19-2012, 03:15 AM   #1
somebodynonbody
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Rep: Reputation: Disabled
How find same files by name and size


Welcome.
Just like the topic I need to write a script that will be located in a specific location files and subfolders that will have the same names and sizes.

what I could think of and find on the internet.

Quote:
#!/bin/bash
fullList=$(find . -type f | awk -F '/' '{print $NF,$0}' | sort +0 -1) #utworzen$
fileNames=$(find . -type f | awk -F '/' '{print $NF}' | sort | uniq -d) #utworz$
fileSize=$(find . -type f -printf "%f %p %s\n" | sort -nr -k3 | uniq -D -f2) #
#-printf "%p - %s\n"
# find . -type f -printf "%p - %s\n" | sort -nr -k3 | uniq -D -f1 SAME ROZMIAR
# find . -type f -ls | awk '{print $NF,$7}' | sort +0 -1 DO FILESIZE
# find . -type f -ls | awk '{print $7}' | sort | uniq -d DO SIZENAME

for EACH in $fileNames; do #dopasowywanie plikow z jednej listy do drugiej
echo "$fullList" | grep -wE "^$EACH "
done

for EACH in $sizeNames; do
echo "$fileSize" #| grep -wE "^$EACH "
done
echo "$fileSize"
exit 0
I do not know how to connect to check the names and sizes.
 
Old 04-19-2012, 03:19 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
do you want to compare two directories?
 
Old 04-19-2012, 03:33 AM   #3
somebodynonbody
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Yes, directory where script is runing and subdirectories.
 
Old 04-19-2012, 03:41 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
have you checked dircmp?
 
Old 04-19-2012, 03:51 AM   #5
somebodynonbody
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
No, but it need to find same files in current directory and "n" subdirectories
 
Old 04-19-2012, 10:45 AM   #6
somebodynonbody
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Ok now is ok . Code is
Quote:
#!/bin/bash
lista=$(find . -type f | awk -F '/' '{print $NF,$0}' | sort +0 -1) #utworzenie listy wszystkich plików
nazwy=$(find . -type f | awk -F '/' '{print $NF}' | sort | uniq -d) #utworzenie listy z plikami powtarzajacymi się
rozmiary=$(find . -type f -printf "%f %p %s\n" | sort -nr -k3 | uniq -D -f2) #utowrzenie listy z plikami o
#tych samych rozmiarach

#-printf "%p - %s\n"
# find . -type f -printf "%p - %s\n" | sort -nr -k3 | uniq -D -f1 SAME ROZMIAR
# find . -type f -ls | awk '{print $NF,$7}' | sort +0 -1 DO DO LISTY PLIKOW ROZM
# find . -type f -ls | awk '{print $7}' | sort | uniq -d DO POJEDYNCZYCH PLIKOW ROZM

echo "Pliki o indetycznych nazwach:"
for EACH in $nazwy; do #dopasowywanie plikow z jednej listy do drugiej
echo "$lista" | grep -wE "^$EACH "
done
echo ""
echo "Pliki o identycznych nazwach i rozmiarach:"

for EACH in $nazwy; do
echo "$rozmiary" | grep -wE "^$EACH "
done
exit 0
 
Old 04-19-2012, 12:49 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.

You have a pretty good start, but there are a couple of things you should beware of.

Code:
nazwy=$(find . -type f | awk -F '/' '{print $NF}' | sort | uniq -d)
1)
Don't read lines with for. Filenames can contain any character (except '/' and null), including newlines. If this command ran across one, it would break. At the very least use find's -print0 option, and the related -z option to sort and uniq, to delimit filenames by null terminators instead.

2) Don't store lists of files inside a single variable. That's what arrays are for.

How can I use array variables?
http://mywiki.wooledge.org/BashFAQ/005
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] find size of the files linuxandtsm Linux - Newbie 9 06-08-2011 10:18 AM
How to recursively find files over a certain size beckettisdogg Linux - Newbie 1 04-15-2010 04:56 PM
how to show size of files in FIND command packets Linux - General 5 04-17-2007 10:49 PM
How to find files within certain size boundaries? kornerr Linux - General 2 06-18-2006 12:14 AM
what command can i use to find files of a certain size? abutzki Linux - Newbie 2 01-31-2006 07:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration