Thursday, August 17, 2017

Linux (process, search, size) command usage and examples

Process


View All Processes Hierarchically

ps -efaux

Shows Running Processes in Tree Format

pstree -p

Find the 20 Largest Processes (5th column)

ps -aux | sort -nk5 | grep -v USER | tail -20


Search



Search Recursively for Contents in a File

find . -type f | xargs grep "mytext"

Search Recursively for Contents in .java Files

find . -type f -name "*.java" | xargs grep "mytext"

Find All World Writable Files

find . -perm -2 ! -type l -ls

Search/Replace



Recursively Replace a String in .xml Files *dangerous*

find . -type f -name "*.xml" -exec sed -i "s%orabpel%orabpel2%" {} \;

Recursively Replace a String, but Exclude .class .jar. .zip Files *dangerous*

find . -type f \( ! -name "*.class" ! -name "*.jar" ! -name "*.zip" \) -exec sed -i "s%orabpel%orabpel2%" {} \;


Size



Directory Sizes

du -sm *

Find the 20 Largest Directories

du -S | sort -n | tail -20

Find Files > 100 MB

find . -size +100000k -exec du -h {} \;




 

No comments: