Поиск файлов по дате, содержащейся в их именах
Если вы имеете в виду действительно для фильтрации по дате в именах файлов, вы можете сделать это:
#!/bin/bash
read -p "Enter year (YYYY): " Y
read -p "Enter start month number: " SM
read -p "Enter start day number: " SD
read -p "Enter end month number: " EM
read -p "Enter end day number: " ED
read -p "Enter copy destination directory (with absolute path): " new_directory
# Do some rule-based checking here. I.e. input variables above
# should conform to expected formats...
# pad month and day numbers with zero to make the string 2 character long
SD="$(printf '%02d' $SD)"
SM="$(printf '%02d' $SM)"
ED="$(printf '%02d' $ED)"
EM="$(printf '%02d' $EM)"
# Make sure that the new directory exists
mkdir -p "$new_directory"
# Place the result of your filtered `find` in an array,
# but, before, make sure you set:
IFS=$'\n' # in case some file name stored in the array contains a space
sdate="$Y$SM$SD"
edate="$Y$EM$ED"
array=(
$(find /directory/log -name "filename-*.gz" -execdir bash -c '
filedate="$(basename ${0#./filename-}.gz)";
if (("${filedate:-0}" >= "${1:-0}")) &&
(("${filedate:-0}" <= "${2:-0}")); then
echo "$0"
fi' {} "$sdate" "$edate" \;)
)
# loop over array, to copy selected files to destination directory
#for i in "${array[@]}"; do
# # ensure that destination directory has full path
# cp "$i" "$new_directory"
#done
#... or much cheaper than a loop, if you only need to copy...
cp "${array[@]}" "$new_directory"
Чтобы быстро найти каталоги и файлы, которые lsusb
читает, просто проследите команду и найдите open()
системные вызовы:
strace lsusb 2>&1 | grep ^open
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libusb-1.0.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libudev.so.1", O_RDONLY|O_CLOEXEC) = 3
...
openat(AT_FDCWD, "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-6/uevent", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/sys/bus/usb/devices/1-6/busnum", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/sys/bus/usb/devices/1-6/devnum", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/sys/bus/usb/devices/1-6/speed", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/sys/bus/usb/devices/1-6/descriptors", O_RDONLY|O_CLOEXEC) = 7
...
Не обращайте внимания на строки, оканчивающиеся на ENOENT
, так как это означает, что файл, который пытались открыть, не существует. Также вы заметите, что есть несколько вариантов.
Прочтите страницу руководства, если вы хотите понять, что такое аргументы для openat()
, используйте раздел 2 для системных вызовов:
$ man 2 open
OPEN(2) Linux Programmer's Manual OPEN(2)
NAME
open, openat, creat - open and possibly create a file
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
Для получения информации о /proc
попробуйте $ man 5 proc
, но могу поспорить, что сейчас вас больше интересует/sys
:
$ mount | grep '/sys '
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
^^^^^
$ apropos sysfs
sysfs (2) - get filesystem type information
sysfs (5) - a filesystem for exporting kernel objects <== you want this one
$ man 5 sysfs
SYSFS(5) Linux Programmer's Manual SYSFS(5)
NAME
sysfs - a filesystem for exporting kernel objects
DESCRIPTION
The sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data struc‐
tures. (More precisely, the files and directories in sysfs provide a view of the kobject
structures defined internally within the kernel.) The files under sysfs provide information
about devices, kernel modules, filesystems, and other kernel components.
Если вы просто ищете файлы устройств для доступа к USB-устройствам, попробуйте эту команду:
$ find /dev -ls | grep usb
find: ‘/dev/vboxusb’: Permission denied
2421522 0 drwxr-xr-x 2 root root 60 Oct 21 17:47 /dev/usb
2421523 0 crw------- 1 root root 180, 0 Oct 21 17:47 /dev/usb/hiddev0
29281 0 lrwxrwxrwx 1 root root 12 Oct 20 14:33 /dev/v4l/by-path/pci-0000:00:14.0-usb-0:5:1.0-video-index0 ->../../video0
25532 0 lrwxrwxrwx 1 root root 12 Oct 20 14:33 /dev/v4l/by-path/pci-0000:00:14.0-usb-0:5:1.0-video-index1 ->../../video1