Find the answer to your Linux question:
Results 1 to 5 of 5
how do you output a certain file name in a directory, for example: a directory has the files named: 1, 2, 3, 4 i tried a ls command and pipeing ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    13

    Outputing a certain name of a file in a directory

    how do you output a certain file name in a directory, for example:

    a directory has the files named: 1, 2, 3, 4

    i tried a ls command and pipeing it to a head command:

    ls mydirectory | head -n 2

    but this will output the first 2 file names - 1 and 2. i would like to only display the second file name.

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    ls mydirectory | head -n 2 | tail -n 1

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    13
    Thanks! think it did the trick

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Isn't it just the same than to do "ls dir/filename"?

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Yeah. Another alternative (TAMTOWTDI!) to print just a known line number is with sed:
    Code:
    ls mydirectory | sed -n 2p

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...