I want to use the find
command on AIX to exclude files ending in .gz
, and it must also exclude the last 2 lines from the list. For example, inside the directory, I have:
shop14_0_Log0002019754.gz
shop14_0_Log0002019755.gz
shop14_0_Log0002019756.gz
shop14_0_Log0002019757
shop14_0_Log0002019758.gz
shop14_0_Log0002019759.gz
shop14_0_Log0002019760.gz
shop14_0_Log0002019761.gz
shop14_0_Log0002019762
I want to get the output shown below by retrieving only the uncompressed files, but excluding the last 2 files from the bottom:
Output command must achieve:
shop14_0_Log0002019757
I am able to exclude the last 2 lines using the ls
command, but how can I do this by excluding files whose names end with .gz
? I am struggling to find a way in AIX/UNIX:
ls -ltr | awk '{print $9} | sed '$d' | sed '$d'
Using find
, I am able to achieve the list of files that are not compressed by excluding .gz
from the list, but it includes the last 2 files, which I do not want:
find . -type f ! -name '*\.gz' -print
The above find
command returns:
./shop14_0_Log0002019757
./shop14_0_Log0002019762
The file shop14_0_Log0002019762
should be excluded from the list and if shop14_0_Log0002019761
was also uncompressed, then it must also be excluded from the list.
The "last 2" entries to be excluded are sorted based on file modification time. My eventual goal is to compress the uncompressed files.
How can I do this?
ls -tr | sed '$d' | sed '$d' | sed '/gz$/d'
? (head
version allowing negative numbers required and no filenames with linebreak allowed)