Is there a way to use find command to get the latest file and cp it into a certain dir at the same try.
example find the latest file and cp to a diff dir.
Is there a way to use find command to get the latest file and cp it into a certain dir at the same try.
example find the latest file and cp to a diff dir.
Did you try ls -ltr. The latest file will be at the bottom of the list.
yea but i am trying to list and copy in the same try. I tried piping a cp command with ls ltr but it didnt work.
cp `/bin/ls -t | head -1` some_other_directory
although i don't recommend doing it this way because it
lacks sufficient error checking.
better would be:
/bin/ls -t | head -1 | read file_nm
if [ -f "$file_nm" ]; then
cp $file_nm some_other_directory
fi
Thanks that works.
cp "$( ls -t | { IFS= read -r f; printf "%s" "$f"; } )" "$DEST"