LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 10-08-2015, 03:21 PM   #1
rosalee
LQ Newbie
 
Registered: Oct 2015
Posts: 1

Rep: Reputation: Disabled
How to output full path file name & first line of text of each file?


What command would you enter to list the first lines of all text files within your directory or within any directory inside there, and the full path filename?

I tried this: find . -type f -exec head -n1 –v {} \;

But the file names come out looking like this:
==> ./.progress <==
mpWjPDUAzdcO6


How can I get output that shows the full path file name on one line, then the first line of the text file on the next line?
 
Old 10-08-2015, 04:00 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
In your find the dot is specifying "this directory" as it is shortcut you see within every directory for the directory itself.

Instead of specifying dot specify the full path you want to search.

e.g.
If the files are all in /home/user and your current working directory (cwd) is /home/user type the dot you did will work but the output will include "./":
find . -type f -exec head -vn1 {} \;

If instead you type:
find /home/user -type f -exec head -vn1 {} \;
The output will show the full path of the files it finds. (You can do this even if you're sitting in /home/user.)

By the way I grouped the -v with the -n1 to be -vn1. That is usually a good idea for shorthand and making sure the flags you're using are going to the command (e.g. head vs find) you expect on a command line.
 
Old 10-08-2015, 04:18 PM   #3
normanlinux
Member
 
Registered: Apr 2013
Location: S.E. England
Distribution: Arch
Posts: 161

Rep: Reputation: Disabled
You could also try head -1 **/*

Although you will also get entries like this:
==> vis/test <==
head: error reading vis/test: Is a directory

caveat: I use zsh which has had **/* for years. but I seem to remember reading somewhere that bash can also do it now
 
  


Reply



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
[SOLVED] Output of full file path eldiener Linux - Software 4 04-06-2013 08:46 PM
Configuring GNOME to have Full File Path Text Fields in File Open Dialog Boxes bgoodr Linux - Desktop 3 11-29-2011 09:07 AM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 12:38 PM
set path with output from text file. jstephens84 Slackware 3 12-04-2006 12:49 PM
how to enumerate first line of text file to standard output? zero79 Linux - General 1 07-07-2004 06:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:43 AM.

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
Open Source Consulting | Domain Registration