Unix/Linux OS/echo command
Expert: Suchitra Joshi - 10/27/2009
QuestionQUESTION: Hi! If i want to output information about a file in this format:
-rw------- 1 lczegel users 270 Jan 28 2007 f2.c
how do i do it using echo. i did echo $file and it gives me but in this format:
-rw-------
1
lczegel
users
270
Jan
28
2007
f2.c
so how do i get to give me like the first format?
Thank You
ANSWER: Hi Ryan,
I am not sure what is stored in $file. But you can try one of the following and check whether it works
1) echo "$file"
or
2) echo -n $file
Since I do not have Unix setup, I cannot try from my end. If this doesn't work, give me all the details about what is exactly required to be done.
Hope this helps.
Regards
Suchitra
---------- FOLLOW-UP ----------
QUESTION: what I'm trying to do is write a script that compare the contents of two directories and gives an output in this format:
Files that are in . but not in /home/ryan/folder2
-rw------- 1 lczegel users 270 Jan 28 2007 g2.c
srwx------ 1 lczegel users 0 Jan 28 2007 unix.socket
so How do i write this code?
Thank You
ANSWER: Hi Ryan,
You can use the ls command to display the files in particular directory as follows -
ls -l (This lists files in current directory)
ls -l /home/ryan/folder2 (This lists files in specified directory)
This will display the files with the following fields -
FilePermissions Hardlinks Owner Group Size Date Filename
Hope this solves your problem.
Regards
Suchitra
---------- FOLLOW-UP ----------
QUESTION: Thanks. How would i start writing this script?(compare the contents of two directories)
AnswerHi Ryan,
Sorry for the delay.
You can try creating a script with the following code in it. Let me know if it works or any errors are encountered -
cd .
for file in `ls`
do
if [ ! -f /home/ryan/folder2/$file ]
then
echo "$file"
fi
done
This will give the files in . which are not present in /home/ryan/folder2 directory.
Hope this helps.
Regards
Suchitra