The command "find" is one of my favorites -
Search for files in /search/path/ which are older than 5 days.
(if you want to search for directories, then use: -type d )
find /search/path/ -type f -mtime +5 -print
find /search/path/ -type d -mtime +5 -print
If you want to do something with those files after you've found them, use: -exec <somecmd> '{}' \;
Example, delete files older than 50 days in the /search/path directory
find /search/path/ -type f -mtime +50 -exec rm '{}' \;
If only there is a 'find' equivalent in the real world ... now, where did I put my keys?
Agree with you James, I constantly push the results of one command to another, and sometimes to inline perl commands.
I'll harvest out the items from some list, and then build an array and pipe it as such:
[some command harvesting out in items in bash] | perl -ne 'print;chomp;system("bash commands go here")'
(see script I made at https://access.redhat.com/discussions/3487481 for more)
Another thing I've found recently is to build "shortcut conditional commands", such as this bit which sets a value using && for pass or || for conditional 'fail':
[ -d /sys/firmware/efi ] && fw="UEFI" || fw="BIOS"
echo -e "$fw"
if [ "$fw" == "UEFI" ] ; then
echo -e "\n\tUEFI detected, this is a ($fw) system.\n\setting \$fw variable to ($fw)..."
mygrub='/boot/efi/EFI/redhat/grub.cfg'
else
echo -e "\n\t($fw) system detected, proceeding...\n"
mygrub='/boot/grub2/grub.cfg'
fi
There's some other sed methods I hadn't seen that I borrowed from Ryan Sawhill such as:
rpm -q prelink >/dev/null && sed -i '/^PRELINKING/s,yes,no,' /etc/sysconfig/prelink
This will onlly flip the value of "PRELINKING' from yes to no if the rpm prelink exists. The use of sed here is a bit lesser known. (hat tip Red Hatter Ryan Sawhill for that one)
@JamesM I couldn't agree more, I use for loops and and pipes to put together various one-liners hourly.
Yes, yes, yes! Thank you, Doug McIlroy!
http://emulator.pdp-11.org.ru/misc/1978.07_-_Bell_System_Technical_Journal.pdf
@jessesar you beat me to it. I was going to say the ability to do for loops straight from the command line has been absolutely invaluable.
I guess our answer is less a command and more tool, bash.
Personally i use egrep a lot when search for multiple pattern in a source. lsof and ps are also tools i use every day
maybe very old school but still works
init 0
it's like signal to the end of my day.
My favorite would be Ctrl+R to do a "reverse-i-search"
Type a letter - like s - and you'll get a match for the most recent command in your history starting with s
Very usefull when I am busy troubleshooting.
Command recall is by far one of my favorite things to do daily! +1
Lightweight tool = cut
Heavyweight tool = awk
When used in pipes these two tools can extract the data that I need from the output of another command. awk is a full-blown C-like interpreter.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.