sudo find -L /proc/458/fd -maxdepth 1 -inum 133880 -print -exec readlink {} \;
To get all of them:
while IFS=': ' read x x x x p x x i x; do
sudo find -L "/proc/$p/fd" -maxdepth 1 -inum "$i" -exec readlink {} \; -quit
done < /proc/locks
Sometimes, the process whose pid
is referenced in /proc/lock
will have died. You can change the "/proc/$p/fd"
above to /proc/*/fd
to look for them among all processes fds.
(note that it is an approximation as we're only checking the inode number, not the device number, but chances that we pick the wrong file (same inum on a different fs) are very slim).
The simplest : you could use :
touch -r Referencefile THEFILE
to give THEFILE the same time as Referencefile
so:
rm -f Referencefile
echo > Referencefile #to set the creation time
#...do your captures here, then concatenate into THEFILE ....
echo >> Referencefile #to set the modification time
touch -r Referencefile THEFILE
But if you prefer to have a more flexible way:
To have a "reliable" way to get the time of a file in a "portable" format, not depending on if the file last changed within 6 months, etc:
tar cf - file | tar tvf -
so you could do this to get a time suitable for touch:
gettouchdate () {
tar cf - "$1" | tar tvf - | tr ':' ' ' \
| awk '{mm=sprintf("%02d",(match("JanFebMarAprMayJunJulAugSepOctNovDec",$5)+2)/3) ;
print $10 mm $6 $7 $8 $9 ;}'
}
#firstdate=$(gettouchdate "/path/to/FIRSTFILE")
lastdate=$(gettouchdate "/path/to/LASTFILE")
touch -r /path/to/FIRSTFILE THEFILE
touch -m "$lastdate" THEFILE
Best Answer
A file does not end with an End of File character, as the previous answers correctly state. But I think the answers and comments contain some inaccuracies worth pointing out:
The ASCII character set does not contain an exact EOF character. There are several "end" control characters: End of Text (3), End of Transmission (4), End of Transmission Block (23), End of Medium (25). File Separator (28) maybe comes closest to an EOF character. Code 26 is "Substitute", not EOF.
Ctrl-D is only associated with terminal input. For example the command
cat filea fileb filec > outfile
does not involve Ctrl-D. By the way, you can change the terminal EOF character to something else than Ctrl-D using thestty
command.Strictly speaking, Ctrl-D (or whatever you have changed to) is not an EOF key code. What it does is make the
read
system call return with what input is available, just like pressing return makes the read system call return a line of characters to the caller. By convention a return value of zero from the read system call (i.e. zero characters read) signals an end of file condition. However, the input file is not closed automatically, and, if the input comes from the terminal, it is not put in an "end of file" state. You can write a program that continues reading from the terminal even after an "end of file" and the read call can return non-zero for the next input line.The analogy between the eof and eol characters can be seen if Ctrl-D is pressed when some input has already been written on the line. For example, if you write "abc" and the press Ctrl-D the read call returns, this time with a return value of 3 and with "abc" stored in the buffer passed as argument. Because read does not return 0, this is not interpreted as an EOF condition by the convention above. Similarly, pressing return to makes the read call return with the whole input line (including newline). You can try this out with the
cat
command: write some characters on the line and press Ctrl-D. You'll see the characters echoed back to you andcat
waiting for more input.All the above only applies when the terminal is in the "cooked" mode, as opposed to "raw" mode, in which line input processing is minimized. In raw mode a Ctrl-D character really is delivered to the input buffer.