map CPU ID to threads to cores to sockets with hyperthreading

The Linux OS uses a predictable method to map hyperthread enabled CPU threads to CPU IDs. Here’s a reminder if you need a quick way to map them:

# egrep 'processor|core id|physical id' /proc/cpuinfo | cut -d : -f 2 | paste - - -  | awk '{print "CPU"$1"\tsocket "$2" core "$3}'
CPU0    socket 0 core 0
CPU1    socket 0 core 1
CPU2    socket 0 core 2
CPU3    socket 0 core 3
CPU4    socket 1 core 0
CPU5    socket 1 core 1
CPU6    socket 1 core 2
CPU7    socket 1 core 3
CPU8    socket 0 core 0
CPU9    socket 0 core 1
CPU10   socket 0 core 2
CPU11   socket 0 core 3
CPU12   socket 1 core 0
CPU13   socket 1 core 1
CPU14   socket 1 core 2
CPU15   socket 1 core 3

This is a dual quad core system with hyperthreading enabled. 2 physical CPUs with 4 cores each and 2 threads per core so the OS sees 16 CPUs. CPU0 and CPU8 are 2 threads on the first core (core 0 ) on the first physical processor (socket 0)

insert characters into string with sed

# echo 20150429 | sed -e 's/\(.\{4\}\)\(.\{2\}\)/\1\/\2\//'
2015/04/29

Start with a single flat directory with thousands of log files…

# ls | head -5
db301.20140216.log.gz
db301.20140217.log.gz
db301.20140218.log.gz
db301.20140219.log.gz
db301.20140220.log.gz

Now move timestamped files into sorted directory by day

# for i in `ls`; do j=$(echo $i| cut -d . -f 2  | sed -e 's/\(.\{4\}\)\(.\{2\}\)/\1\/\2\//'); mkdir -p $j && mv $i $j; done;


check your work

# find . -type f | head -5
./2014/02/16/db301.20140216.log.gz
./2014/02/17/db301.20140217.log.gz
./2014/02/18/db301.20140218.log.gz
./2014/02/19/db301.20140219.log.gz
./2014/02/20/db301.20140220.log.gz

forgot to rename files

# for i in `find . -mindepth 3 -type d `; do pushd $i; for j in `ls`; do k=$(echo $j | sed -e 's/\(\.[0-9]\{8\}\)//' ); mv $j $k;done; popd; done;

check your work

# find . -type f | head -5
./2014/02/16/db301.log.gz
./2014/02/17/db301.log.gz
./2014/02/18/db301.log.gz
./2014/02/19/db301.log.gz
./2014/02/20/db301.log.gz

get list of most recently installed packages with dpkg log

# zcat -f /var/log/dpkg.log*|grep 'status installed'|awk '{print $1" "$5}'|sort -u |less
2015-05-04 ffmpeg
2015-05-04 libavcodec52
2015-05-04 libavdevice52
2015-05-04 libavfilter0
2015-05-04 libavformat52
2015-05-04 libavutil49
2015-05-04 libdc1394-22
2015-05-04 libdirac-encoder0
2015-05-04 libdirectfb-1.2-9
2015-05-04 libfaad2
2015-05-04 libgsm1
2015-05-04 libogg0
2015-05-04 libopenjpeg2
2015-05-04 liborc-0.4-0
2015-05-04 libpostproc51
2015-05-04 libraw1394-11
2015-05-04 libschroedinger-1.0-0
2015-05-04 libsdl1.2debian
2015-05-04 libsdl1.2debian-alsa
2015-05-04 libspeex1
2015-05-04 libsvga1
2015-05-04 libswscale0
2015-05-04 libtheora0
2015-05-04 libusb-1.0-0
2015-05-04 libvorbis0a
2015-05-04 libvorbisenc2
2015-05-04 libx86-1
2015-05-04 man-db