Bash scripting question
I'm making a bash script that has to (amongst other things I figured out myself) delete the oldest file in a directory. I have an idea how to do it, but there's something I can't translate from common sense into a bash script.
I can list the files sorted by date with 'ls -c /whatever/path' and get the number of files with 'ls /whatever/path | wc -w'. Now all I have to do is set a variable with its value of whatever is the last word 'ls -c' outputs, or word number [number of files]. How exactly can I do that? Thanks in advance, if I made enough sense to get an answer :) |
Using tail:
Code:
ls -tc /whatever/path | \ |
The following code will set the value of f to the name of the oldest file in /whatever/path.
Code:
f=`ls -1c /whatever/path | tail -n1` |
Thank you, that helped a lot.
|
All times are GMT -5. The time now is 11:36 PM. |