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 ...
- 05-18-2008 #1Just 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.
- 05-18-2008 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
ls mydirectory | head -n 2 | tail -n 1
- 05-18-2008 #3Just Joined!
- Join Date
- Apr 2008
- Posts
- 13
Thanks! think it did the trick
- 05-18-2008 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Isn't it just the same than to do "ls dir/filename"?
- 05-18-2008 #5Linux 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


Reply With Quote