cancel
Showing results for 
Search instead for 
Did you mean: 
kubeadm
Flight Engineer Flight Engineer
Flight Engineer
  • 16.1K Views

What's your favorite tool/cmd in Linux?

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? 

Tags (2)
49 Replies
RJ
Flight Engineer Flight Engineer
Flight Engineer
  • 5,491 Views

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)

RJ
jessesar
Cadet
Cadet
  • 5,647 Views

 @JamesM I couldn't agree more, I use for loops and and pipes to put together various one-liners hourly.

heatmiser
Flight Engineer Flight Engineer
Flight Engineer
  • 5,629 Views

0 Kudos
shauny
Mission Specialist
Mission Specialist
  • 5,617 Views

@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. 

Martin
Flight Engineer Flight Engineer
Flight Engineer
  • 5,531 Views

Personally i use egrep a lot when search for multiple pattern in a source. lsof and ps are also tools i use every day

0 Kudos
rdekens
Mission Specialist
Mission Specialist
  • 5,499 Views

maybe very old school but still works

init 0

it's like signal to the end of my day.

0 Kudos
Robvd46
Flight Engineer Flight Engineer
Flight Engineer
  • 5,496 Views

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.

0 Kudos
Lisenet
Starfighter Starfighter
Starfighter
  • 5,491 Views

The pipe character as per @JamesM comment, Ctrl+R to do a reverse-i-search as @Robvd46 said, and Crtl+. (note the dot at the end) to use the last word of the previous command.

0 Kudos
itnet7
Flight Engineer
Flight Engineer
  • 5,360 Views

Command recall is by far one of my favorite things to do daily! +1

0 Kudos
George-Hacker
Flight Engineer Flight Engineer
Flight Engineer
  • 5,488 Views

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.

Join the discussion
You must log in to join this conversation.