Useful Linux Commands

Delete all files with given extension recursively:

find . -name "*.dll" -print0 | xargs -0 rm -rf

Find the number of .jpg file in the current folder and all sub-folder recursively:

find . -name "*.jpg" -print | wc -l

Move all .m2ts files to /mnt/backup/m2ts folder:

find . -iname "*.m2ts" -type f | xargs -I '{}' mv {} /mnt/backup/m2ts

Install GUI on Ubuntu Server

sudo apt-get upgrade
sudo apt-get install ubuntu-desktop

Find out the disk usage

df -h

You can free up some space in /boot by removing old kernel with:

sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")

according this post

Search for a string in all text files:

find folder_name -name '*.txt' -exec grep -i 'text-to-search-for' {} \; -print

Search for all .jpg files modified (taken) in the last year and move them to another folder:

find . -iname "*.jpg" -mtime -365 -print -type f | xargs -I '{}' mv {} /mnt/backup/jpg_last_year

Delete .jpg files older than 1 year:

find . -iname "*.jpg" -mtime +365 -print -type f | xargs -I '{}' rm {}

Delete .jpg images smaller than 500KB

find /mnt/backup/_wd3 -iname "*.jpg" -size -500k -delete

Move all .jpg files modified in 2013 to a separate folder:

find . -iname "*.jpg" -newermt "2013-01-01" ! -newermt "2013-12-31" | xargs -I '{}' mv {} /mnt/tank/common/multimedia/pictures/jpg_3/2013

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.