Monday, August 28, 2017

Useful linux commands

Grep files with specified extension in directory recursively:
grep -R --include \*.h --include \*.cpp "Bar::foo()" ~/repo/

Display size of files/directories in current directory including hidden files and sort them by size increasing:
find . -maxdepth 1 -exec du -sh "{}" \; | sort -h

Update existing symbolic link path:
ln -sfn <directory_or_file> <symbolic_link>

Print only list of files in current directory and sort them by name:
ls -p | grep -v / | sort

Monitor virtual memory usage:
watch -n 5 free -m

Redirect to stderr and stdout to file:
./application  &>file


Run command multiple times:

for i in {1..10}; do command; done
Checkout changed files
 
git diff --name-only HEAD~ | xargs git checkout HEAD~ --

No comments:

Post a Comment