June 17th, 2013, 02:12 PM
Unix help please
Using echo command answer whether the file size displayed by ls command and the character count displayed wc command are the same.
Input to a command can come from a file instead of from the keyboard. This is achieved by input redirection operator <. In the following command, the input is redirected from the file /etc/hosts to the wc command which will display the number of lines, words, and characters in the hosts file.
wc < /etc/hosts
Issue the above command.
June 18th, 2013, 04:35 PM
Beginning to sound very much like home/course-work ...
Look at the man pages for the commands you are being told to use:
For the ls command you will see that you will need the -l (long) option to provide file size information.
For the wc command you will see that you'll need the -c (character) option to have it could characters in the specified file name.
The question does not say how you are supposed to use the echo command to report on the file size comparisons, nor if you are to do this in a script or wholly from the command line. On that basis, and due to the fact that I don't have immediate access to a *nix system and this would all be from memory, I'll just suggest a method you can use.
Assign the results of the commands to a pair of variables, compare those variables and if they do not hold the same number, do the needed echo command. There are, of course, caveats - the ls -l command does not produce JUST the file size information - that appears as 'field' 5 (I think), so you'd need a way to just obtain that bit (hint: man awk, or man cut). Likewise, the wc command is likely not to just produce the number you are after. Try it by hand, see what it does and work out a way of getting just the data you need.
To assign the number to a variable, you'd have something like:
You'd do something similar for the wc command, then to test to see if they are the same you'd have something like:
ls_filesize=$(ls -l myfilename | cut -f5)
if [ $ls_filesize -ne wc_charcount ]
echo Commands produce different sizes
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
June 18th, 2013, 07:20 PM
Originally Posted by SimonJM
Thank you Simon for your kind reply.... you were right it is a course that Im trying to understand. It is an online course and trying my best to understand it as much as I can.
June 19th, 2013, 12:02 PM
Well, we wish you the best!
Originally Posted by nancy1165
Here is a link that summarizes the syntax if some unix commands.