Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm having problems with md5sum check. I cannot get it to work. I download a iso file and save it. I then open a terminal and type:
md5sum "space"
I go to the saved ISO file and right click and go to properties. I then copy the file name and past it into the terminal.
andy1960@debimint-li-3710 ~ $ md5sum linuxmint-15-cinnamon-dvd-32bit.iso
md5sum: linuxmint-15-cinnamon-dvd-32bit.iso: No such file or directory
andy1960@debimint-li-3710 ~ $
Tried it as root, the result was the same.
Where and what am I doing wrong? Many thanks.
Last edited by AndyInMokum; 07-21-2013 at 06:27 AM.
Many thanks, that's done the trick. The file was on my Desktop. I just forgot to change the directory. Now I can enjoy the sun in Westerpark. Thanks again.
A few years ago during a bout of serious scriptwriting practice I created one that makes comparing checksums easier. Perhaps it will be of help to you.
I named it "comparisum", but you can call it whatever you want. Copy it to a file, chmod it to be executable, and run the -h option for a full description of how to use it.
Code:
#!/bin/bash
checktype="sha1sum" #Sets the default checksum used for file comparisons.
#string is the name of the command you want it to use:
#md5sum,sha1sum,sha224sum,sha256sum,sha384sum,sha512sum
EX_HELPOUT=79 #User-defined exit. Successful output of usage information.
EX_USAGE=64 #Standard C exit code for bad arguments. See /usr/include/sysexits.h
EX_RESULT= #Used for the valid comparison result exit code. Will be either 0 or 1
IFS=$'\n' #Set IFS to newline, to deal with names with spaces
#(Not really necessary, but it doesn't hurt)
BCYAN="${BCYAN:-\e[1;36m}" #Define some color codes, for prettified output.
BGREEN="${BGREEN:-\e[1;32m}" #Use environment defaults if they exist.
BRED="${BRED:-\e[1;31m}"
BBLUE="${BBLUE:-\e[1;34m}"
BMAGENTA="${BMAGENTA:-\e[1;35m}"
RESET="${RESET:-\e[0m}"
## function that outputs usage info ##
ShowHelp() {
local -a help
#Use array indexes 0-4 for short help.
help+=( "" )
help+=( "\tUsage: ${BCYAN}${0##*/} [-t <type>] <file1|checksum1> <file2|checksum2>${RESET}" )
help+=( "" )
help+=( "\t\t${BCYAN}${0##*/} -h${RESET} for detailed help" )
help+=( "" )
#Use array indexes 5+ for long help.
help+=( "" )
help+=( "\tUsage:\t${BCYAN}${0##*/} [-t <type>] <file1|checksum1> <file2|checksum2>${RESET}" )
help+=( "\t\t${BCYAN}${0##*/} -h${RESET}" )
help+=( "" )
help+=( "\t${BBLUE}-h${RESET}\t\t: Display this help message and exit." )
help+=( "" )
help+=( "\t${BBLUE}-t <type>${RESET}\t: Use checksum <type> instead of the default." )
help+=( "\t\t\t: Valid types are: md5 sha1 sha224 sha256 sha384 sha512" )
help+=( "" )
help+=( "\tThis script will compare the sha1, sha2, or md5 checksums of two files," )
help+=( "\tone file and a previously-generated checksum, or two checksums." )
help+=( "" )
help+=( "\tIf two filenames are given it will calculate and compare their checksums." )
help+=( "\tIt uses sha1 by default. This can be changed in the script, or you can" )
help+=( "\tspecify a different checksum type with the '-t' option. If multiple types" )
help+=( "\tare given, only the last one will be used." )
help+=( "" )
help+=( "\tThe '-t' option is ignored when comparing a file to an entered checksum." )
help+=( "\tThe script will automatically determine the checksum type based on the" )
help+=( "\tlength of the string supplied to it." )
help+=( "" )
help+=( "\tIf neither argument is a valid file, then it will compare them as" )
help+=( "\tliteral text strings. This may be useful for comparing long checksums." )
help+=( "\tIn this case the strings can have any length or content." )
help+=( "" )
help+=( "\tThe exit code will be 0 if the entries match, and 1 if they don't." )
help+=( "\t( In addition, 64 = improper arguments and 79 = this help option. )" )
help+=( "" )
if [[ "$1" == "short" ]]; then
echo -e "${help[*]:0:5}"
elif [[ "$1" == "long" ]]; then
echo -e "${help[*]:5}"
fi
}
## function that calculates checksums for files ##
Check_Sum() {
sum1=$( "$checktype" "$1" )
echo "${sum1%% *}"
}
## function that compares the checksums of two files ##
Compare2Files() {
# run both files through the Check_Sum function
filesum1=$( Check_Sum "$1" )
filesum2=$( Check_Sum "$2" )
# compare and display the results
filename1="${1##*/}" #strip leading directories
filename2="${2##*/}" # for display purposes
echo
echo -e "Comparing files ${BCYAN}$filename1${RESET} and ${BCYAN}$filename2${RESET}."
echo -e "Using ${BCYAN}$checktype${RESET} for comparison."
echo
echo -e "Sum of $filename1 is:\n${BBLUE}$filesum1${RESET}"
echo -e "Sum of $filename2 is:\n${BBLUE}$filesum2${RESET}"
echo
if [[ "$filesum1" == "$filesum2" ]]; then
echo -e "${BGREEN}The two files match.${RESET}"
EX_RESULT=0
else
echo -e "${BRED}The two files are different.${RESET}"
EX_RESULT=1
fi
}
## function that compares a file checksum to a given string ##
CompareFile2Sum() {
if [[ -f "$1" ]]; then #determine the order of arguments
file="$1"
filename="${1##*/}"
compstring="$2"
else
file="$2"
filename="${2##*/}"
compstring="$1"
fi
#Determine if $compstring is a valid checksum, and which type it is.
#First reject non-hex strings, then test for length.
if [[ "$compstring" =~ [^[:xdigit:]] ]]; then
echo
echo -e "${BMAGENTA}String to compare is not a valid checksum. Exiting.${RESET}" >&2
ShowHelp short >&2
exit "$EX_USAGE"
fi
case "${#compstring}" in
32) checktype=md5sum ;;
40) checktype=sha1sum ;;
56) checktype=sha224sum ;;
64) checktype=sha256sum ;;
96) checktype=sha384sum ;;
128) checktype=sha512sum ;;
*) echo
echo -e "${BMAGENTA}String to compare is not a valid checksum. Exiting.${RESET}" >&2
ShowHelp short >&2
exit "$EX_USAGE" ;;
esac
filesum=$( Check_Sum "$file" )
echo
echo -e "Comparing ${BCYAN}$filename${RESET} to the checksum given."
echo -e "Using ${BCYAN}$checktype${RESET} for comparison."
echo
echo -e "Sum of $filename is:\n${BBLUE}$filesum${RESET}"
echo -e "Sum to compare against is:\n${BBLUE}$compstring${RESET}"
echo
if [[ "$filesum" == "$compstring" ]]; then
echo -e "${BGREEN}The two checksums match.${RESET}"
EX_RESULT=0
else
echo -e "${BRED}The two checksums are different.${RESET}"
EX_RESULT=1
fi
}
## function that compares two strings ##
Compare2Strings() {
echo
echo "Comparing text string one to text string two."
echo
echo -e "Text string one is:\n${BBLUE}$1${RESET}"
echo -e "Text string two is:\n${BBLUE}$2${RESET}"
echo
if [[ "$1" == "$2" ]]; then
echo -e "${BGREEN}The two text strings match.${RESET}"
EX_RESULT=0
else
echo -e "${BRED}The two text strings are different.${RESET}"
EX_RESULT=1
fi
}
###### Start main script operations ######
##########################################
## Process input options ##
while getopts ":ht:" opt; do
case "$opt" in
h) ShowHelp long >&2
exit "$EX_HELPOUT"
;;
t) case "$OPTARG" in
md5|sha1|sha224|sha256|sha384|sha512) checktype="${OPTARG}sum"
;;
*) echo
echo -e "${BMAGENTA}Invalid type \"${BRED}$OPTARG${BMAGENTA}\".${RESET}" >&2
echo -e "${BMAGENTA}Valid types are ${BRED}md5 sha1 sha224 sha256 sha384 sha512${RESET}" >&2
ShowHelp short >&2
exit "$EX_USAGE"
;;
esac
;;
\?) echo -e "${BMAGENTA}Invalid option \"${BRED}-$OPTARG${BMAGENTA}\". Ignoring.${RESET}" >&2
;;
esac
done
shift $(( OPTIND - 1 )) ; OPTIND=1
## Analyze input arguments (after shifting away options) and call the appropriate functions ##
if [[ ! "$2" || "$3" ]]; then #must have exactly two arguments.
echo
echo -e "${BMAGENTA}Invalid number of arguments.${RESET}" >&2
ShowHelp short >&2
exit "$EX_USAGE"
elif [[ -f "$1" && -f "$2" ]]; then # If both are files...
Compare2Files "$1" "$2"
elif [[ ! -f "$1" && ! -f "$2" ]]; then # If neither are files...
Compare2Strings "$1" "$2"
elif [[ ! -f "$1" || ! -f "$2" ]]; then # If only one is a file...
CompareFile2Sum "$1" "$2"
fi
echo
exit "$EX_RESULT"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.