Quick Linux Tip #27:
Try: history | grep -E 'sed.*i.*g' | tail -10
Info: history outputs numbered past commands. Combining it with grep -E (regex) lets you locate specific command patterns fast. Execute entry 892 with !892.
Examples:
- $ history | grep 'docker run' # Find docker commands
- $ history | awk '{print $2}' | sort | uniq -c | sort -rn | head # Top 10 used commands
- $ Ctrl+R # Interactive reverse search
Note: Ctrl+R is the fastest for interactive search. Set HISTSIZE=10000 in ~/.bashrc to retain a larger command history. Use HISTIGNORE='ls:cd:pwd' to skip logging basic commands.
Follow @LinuxTeck for more #LinuxTips
linuxteck@ubuntu:~$ history | grep -E 'sed.*i.*g' | tail -10
892 sed -i 's/DEBUG=true/DEBUG=false/g' /etc/app.conf
1234 find . -name '*.py' -exec sed -i 's/foo/bar/g' {} +
1567 history | grep sed | awk '{print $2}' | sed -i 's/old/new/g'
2345 cat file | sed -e 's/foo/bar/g' -e 's/baz/qux/g'
2891 sed -i.bak 's/localhost/127.0.0.1/g' /etc/hosts
linuxteck@ubuntu:~$
Leave a Reply