LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-11-2003, 08:03 AM   #1
gkettle1983
LQ Newbie
 
Registered: Dec 2003
Posts: 4

Rep: Reputation: 0
newbie trying to help another newbie


I'm trying to help a mate create his own shell script for his version of linux to make it easier for him to work with files, however, i am a newbie myself, and i am having trouble with a few commands. Just wondering if anyone could help me out:

Backing up files in the current directory to another directory, and if that directory doesn't exist, create it:

print "Enter file name:"
read n
if test -d $n
then
cp *.* $n
else
mkdir $n
cp *.* $n
fi;;


Another one i'm having trouble with is listing all files in the current directory which are identical to a file that i enter. I managed to get a hold of a book which describes it, but says that i need to use binary comparison??
 
Old 12-11-2003, 09:07 AM   #2
iainr
Member
 
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Rep: Reputation: 30
Re: newbie trying to help another newbie

Backing up files in the current directory to another directory, and if that directory doesn't exist, create it:

printf "Enter directory to backup to --> "
read n
if test -d $n
then
cp * $n
else
mkdir $n
cp * $n
fi

(haven't tested this so hopefully no stupid mistakes. Note that for the mkdir to work here, the parent directory must exist. For example, for mkdir /tmp/a/b to work, /tmp/a must exist. There is an option on mkdir to get round this if you don't want that behaviour).
 
Old 12-11-2003, 09:13 AM   #3
gkettle1983
LQ Newbie
 
Registered: Dec 2003
Posts: 4

Original Poster
Rep: Reputation: 0
Yeh, that's great!

Any idea about the binary comparison for the listing of identical files?
 
Old 12-11-2003, 10:58 AM   #4
iainr
Member
 
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Rep: Reputation: 30
Quote:
Originally posted by gkettle1983
Any idea about the binary comparison for the listing of identical files?
If the files are text files, look at the diff command. For any files, you could use md5sum which will produce a hash of the file - any change in the file changes the hash.

Try something like this

printf "Enter file to compare against --> "
read OFILE
md5sum $OFILE|read FSUM rest

for FILE in $(ls)
do
md5sum $FILE|read SUM rest
if [ "$SUM" = "$FSUM" ]
then
print "File $FILE is the same as $OFILE"
fi
done
 
Old 12-11-2003, 11:54 AM   #5
gkettle1983
LQ Newbie
 
Registered: Dec 2003
Posts: 4

Original Poster
Rep: Reputation: 0
excellent, cheers!

When i get home i'll give it a try
 
Old 12-11-2003, 02:36 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,568

Rep: Reputation: 164Reputation: 164
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php

gkettle1983, please don't do it again. Now you have two threads, both with answers. I think this one should be kept open (has more replies), so I'll as moderators of the Programming forum to close the second one.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
security newbie, but not Linux newbie. advice on secure delete tools mattie_linux Linux - Security 19 08-15-2005 02:50 AM
Linux semi-newbie and Wine vary newbie geovolt_os1 Linux - Software 4 04-19-2005 12:03 PM
newbie;I am a linux newbie who has installed slackware and have run into a few proble MollyJolly Slackware - Installation 6 06-01-2004 12:21 PM
How To Update To Slackware-Current For a Newbie, By a Newbie :) windsok Slackware 1 09-18-2003 09:53 PM
ipchains newbie. Kernel newbie skeletal29 Linux - Security 3 06-02-2002 04:30 AM


All times are GMT -5. The time now is 06:59 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration