# Lsof command

**URL:** <https://community.unix.com/t/lsof-command/374085>\
**Category:** Shell Programming and Scripting\
**Created:** [November 5, 2018, 1:07pm UTC](https://community.unix.com/t/lsof-command/374085 "2018-11-05T13:07:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryzen7](https://community.unix.com/letter_avatar/ryzen7/32/6_449c533f586939b6e5f246632a46421f.png) [@ryzen7](https://community.unix.com/u/ryzen7)\
**Post date:** [November 5, 2018, 1:07pm UTC](https://community.unix.com/t/lsof-command/374085/1 "2018-11-05T13:07:05Z")

</div>

Hi,

I am trying to find the files in a specific directory that are currently in open state. I need this information to archive the old files that are not active in the directory.

I get the following output when I try the command

```nohighlight
[root@myhadoop tmp]$ lsof +d '/var/tmp/'|awk '{print $9}'|sort -u

```

```nohighlight
NAME
/var/tmp
/var/tmp/abc.txt
/var/tmp/xyz.txt
/var/tmp/123.txt

```

I do not want to see the first 2 lines which are the header info and the directory path where the files are being searched from.

I can use the sed command to get rid of the first 2 lines, but I was wondering if there is any better way to handle this.

Thanks  
-Vicky

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 5, 2018, 4:35pm UTC](https://community.unix.com/t/lsof-command/374085/2 "2018-11-05T16:35:50Z")

</div>

I'm afraid, no. `lsof` doesn't seem to offer what you request by itself. So you'd be dependent on massageing the output afterwards. But, in lieu of appending another pipe into `sed` , `grep` , or another `awk` , you could enhance your existing `awk` let. But, be aware that the directory itself doesn't have to be open although files in it are (try `exec 3>/path/to/somewhere/completely/else` and `lsof +d` that path), so be very sure you really want to exclude it.
