Anyone familiar with Unix?

  • We are currently upgrading MFK. thanks! -neo

gordonheimer

Exodon
MFK Member
Mar 30, 2009
30
0
21
CA
I got this silly assignees I have been working on for the past hour and I cant figure it out. anyone got some unix knowledge?





That English paper you were writing on the works of Lewis Carroll is due in a few hours and you have forgeotten the name of the text file in which you has written a number of quotations to use in your paper. Luckily, you know that the file is somewhere in your ~/UnixCourse directory or in some subdirectory directly or indeirently within it. You also know that the file name ended in '.txt'. You are pretty sure that you could recognize the file from just the first line.

You seem to recall having heard that there is a Unix command head that will print the first few lines of any file and suspect that, with the proper parameters, it could be used to print just the first line. (Hint - part of your task in this question is to show that you can use the built-in Unix help facilities.)


But you really don't want to type that command out for every file or even every directory. What command would you give to produce a listing of the names of all the text files in ~/UnixCourse or its subdirectories (possibly nested several layers deep) followed immediately by the first line of text within that file? E.g., to produce a listing looking like this:

/home/yourname/UnixCourse/foo.txt
When in the course of human development
/home/yourname/UnixCourse/Quotations/bar.txt
Curiouser and curiouser!
 
thanks for the help! :D

It still isnt working :( I think it may want me to use a pipeline? It states, invalid number of lines
 
How do I find files in Linux / Unix?

Question:

How do I find files in Linux / Unix?
Additional information:

This document is for users looking for ways to find a file on their Linux computer. If you're looking for information about finding certain text within a file see document CH000757.
Answer:


Linux / Unix and their variants have several different ways of locating files. See each of the below commands for additional information about the command and how they can be used to locate files.
 
Invalid number of lines? Try running the head command on one file to see what syntax you need, you may be using a different version. Run "man head" (that sounds wrong) to see what parameters are available. -n lets you specify number of lines to show, and -v forces it to show the filename as well. Maybe your version of head has different names for these options, or expects them spelled out like "head -n1 -v ". GL
 
Yeah i have this problem too. I attempted the find command listed above, but it seems that we can't have ==> listed. the find command alone doesn't list ==> so it must be something else like the head command causing it. So i guess the question is how to get rid of the ==>?
 
The ==> is added by head. The find command I listed runs head on every file in the results. Its hard to say without knowing what you are studying in class how exactly your professor wants you to do it. The above way is functional, but if you need to remove those characters you can do that easily as well.

head -vn1 `find . -type f -name "*.txt"` | perl -pi -e "s/(==> | <==)//g"
 
MonsterFishKeepers.com