bash function for rpm whatprovides
Sometimes some simple one-liner function can save you a lot of time, like-
wps () { rpm -q --whatprovides $(which $1 ) } # ---------- end of function wps ----------
Sometimes some simple one-liner function can save you a lot of time, like-
wps () { rpm -q --whatprovides $(which $1 ) } # ---------- end of function wps ----------
Lot of times, I want to find the directories with maximum number of files and so I wrote this quick function to do exactly the same
function count_lines () { oldIFS=$IFS count=0 IFS=$'\n' dir=${1:-.} cd $dir find . -type d |while read line do echo -n "$(find $line -type f |wc -l) $line" echo printf "Directories :: %8d\r" $count >&2 ((count++)) done|sort -n IFS=$oldIFS } # ---------- end of function count_lines ----------
When moving large files/directories, I would like to see the progress.
Idea for this is to use rsync with progress and remove source files. But that option does not remove the empty directories left behind so find command to delete that.
So, here is function for that:
mv-progress () { rsync -ah --progress --remove-source-files "$1" "$2"; find "$1" -empty -delete }
Trying to find the total usage for each of the file types by extension, then here is a quick bash function for you :
disk_usage_type () { find . -name '*'$1 -ls | awk ' BEGIN{ a[0]="Bytes"; a[1]="KB"; a[2]="MB"; a[3]="GB"; } {sum+=$7; files++;} END{ print "Total sum is ::\t" sum; print "Total files ::\t" files; while (sum > 1024) { sum=sum/1024; count++; }; print sum" "a[count]; }' }
Just define the function in one of your bash startup files. After that to use the function pass in the extension for which you would like to find the total size. Output should be something like below:
Continue readingHere is a nice little handy function that I use very regurlarly.
You can use this function with parameter to just grep for that or just type psa to see all the running processes.
Just put this in your .bashrc file.
You might find it useful:
psa () { if [[ $1 == "" ]]; then ps -eaf; else ps -eaf | grep --color=auto -i $1; fi }