๐งLinux Fundamentals
Find Files
What is the name of the config file that has been created after 2020-03-03 and is smaller than 28k but larger than 25k?
find / -type f -name *.conf -newermt 2020-03-03 -size +25k -size -28k 2>/dev/null
What is the name of the config file that has been created after 2020-03-03 and before 2020-03-05
find / -type f -name *.conf -newermt 2020-03-03 ! -newermt 2020-03-05 2>/dev/null
File Descriptors
A file descriptor (FD) in Unix/Linux operating systems is an indicator of connection maintained by the kernel to perform Input/Output (I/O) operations. In Windows-based operating systems, it is called filehandle. It is the connection (generally to a file) from the Operating system to perform I/O operations (Input/Output of Bytes). By default, the first three file descriptors in Linux are:
Data Stream for Input
STDIN โ 0
Data Stream for Output
STDOUT โ 1
Data Stream for Output that relates to an error occurring.
STDERR โ 2
Example: 2>/dev/null
This way, we redirect the resulting errors to the "null device," which discards all data. We can redirect the valid output to a file with 1>results.txt.
Find How Many logs files are on the system
#!/bin/bash
FILES=$(find / -type f -name *.log 2>/dev/null)
COUNTER=0
for f in $FILES
do
echo $f
let COUNTER++
done
echo $COUNTER
Find How Many packages are on the system
dpkg -l | grep -c '^ii'
Last updated