Show phrase in context (-B(n) - n lines backward, -b(n) - n lines forward)
  find . -name "pom.xml" | xargs -I {} grep -B3 -b1 GUI-SNAPSHOT {}


Find all any-depth directories named "target" in the current working and perform mvn clean on each:

find . -name "target" -type d -exec mvn -f {}/../pom.xml clean \;

Find all 3-depth directories named "target": 

find . -maxdepth  3 -name "target" -type d


File last modified file in current directory

groovy -e "println new File('.').listFiles()?.sort { -it.lastModified() }?.head()"

Find last modified file matching given pattern in current directory

groovy -e "println new File('.').listFiles()?.sort { -it.lastModified() }?.find{ it ==~ /.*test.*jar$/}"


How to synchronize folder with remote on another machine running ssh on custom port

rsync -av -e "ssh -p 49153" /src

How to sync two folders ignoring synchronizing file permissions

rsync -rltgoDv --exclude '*db' --exclude ".svn" m/bdg .  


How to edit file with sed in place

sed -i.bak 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
-i[SUFFIX] option instructs sed to create backup file with specified SUFFIX - in the example above "/etc/ssh/sshd_config.bak" will be created

Disable PAM authentication

sed -i '/^UsePAM/s/yes/no/' /etc/ssh/sshd_config

How to remove new line characters with sed

 cat ala.txt | sed -e ':_LABEL;N;$!b_LABEL;s/\n/ /g'

How to remove lines with certain extension

 for i in `ls`; do sed -i '/^[SQL| ]/d' $i; done


How to write infinite while loop as one-liner

 while :; do date; sleep 2;  done


How to remove all but 3 most recent files matching given pattern

ls -1tr build-x86-20* | sort -n | head -n -3 | xargs -I {} rm -rf {}
# or for more regexp patterns
ls -1tr | grep ^[bB]uild-x86-20* | sort -n | head -n -3 | xargs -I {} rm -rf {}


How to merge two zip files

zip -U "" --out

Brak komentarzy:

Prześlij komentarz