4

We appear to have two files in the /var/spool/lp/logs folder named "requests". One is owned by lp, the other by root.

We need to remove the requests file owned by root - how do we reference it?

Here's the output from ls -l command:

-rw-r--r--   1 root     sys            0 Jan 30  2014 lp                 
-rw-rw----   1 root     lp          6584 Nov  4 06:10 lpsched            
-rw-rw----   1 lp       lp          3365 Dec 14 10:56 requests           
-rw-r--r--   1 root     sys      1668416 Dec 14 10:41 requests           
drwxr-xr-x   2 root     sys         1024 Sep 30  2013 requests.archives  
1
  • What's the output of ls -l | LC_ALL=C sed -n l? Dec 14 '16 at 22:46
11

If you have GNU ls, you can run ls -lQ to see a quoted version of the filename:

$ ls -lQ
total 0
-rw-r--r--. 1 user group 0 Dec 14 14:32 "requests"
-rw-r--r--. 1 user group 0 Dec 14 14:32 "requests "

To remove a specific file, first find its inode number with ls -li:

$ touch 'requests' 'requests '
$ ls -li
total 0
440 -rw-r--r--. 1 user group 0 Dec 14 14:32 requests
441 -rw-r--r--. 1 user group 0 Dec 14 14:32 requests

Here we have two similar files, one has inode 440, the other 441 (left-hand column).

For your case, find the file owned by root and grab that inode number. The -xdev (or -mount) option to find says to stay on the same filesystem, just in case you have a filesystem mounted underneath the current directory, to avoid catching any files matching in that child filesystem.

Then:

$ find . -inum 441 -xdev -user root -ls
441    0 -rw-r--r--   1 user group 0 Dec 14 14:32 ./requests\

Notice that find quoted the space character at the end.

and to delete:

$ find . -inum 441 -xdev -user root -delete  # GNU find

or

$ find . -inum 441 -xdev -user root -exec rm {} \;  # otherwise
2
  • 1
    Does SCO Unix have any GNU utilities?
    – roaima
    Dec 14 '16 at 21:39
  • Don't know what it comes with but maybe an admin added them.
    – Jeff Schaller
    Dec 14 '16 at 21:57
6

You can't have two files with the same name in the same folder. It's likely that one has an invisible character in it (such as a trailing space).

My suggestion would be to rename requests to requests.real and then run an interactive delete. You can choose to delete the one you don't want, and then (if necessary) rename the other using a wildcard to the correct name

mv requests requests.real             # STOP if this fails
mv requests.archives KEEP.archives    # Temporary
rm -i req*                            # Interactive delete: "y" to delete, "n" to skip
mv req* requests                      # Rename whatever's left that begins "req"
mv KEEP.archives requests.archives    # Put this one back again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.