Skip to content

Instantly share code, notes, and snippets.

@himalay
Last active January 12, 2024 22:29
Show Gist options
  • Save himalay/54b44722287794c2e3c4e6f423677f70 to your computer and use it in GitHub Desktop.
Save himalay/54b44722287794c2e3c4e6f423677f70 to your computer and use it in GitHub Desktop.
# Rename files to lowercase
for i in `ls -1`; do mv $i "${i,,}" ; done
# Image view
for i in *.jpg; do echo "<img src='$i' />" >> images.html; done;
# updae all pip packages
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
# find and replace foo with bar
ind ./ -type f -exec sed -i 's/foo/bar/g' {} \;
# find all txt file and display content
find /path/to/dir -name "*.txt" -type f -exec cat {} \;
# find js files in multiple locations
find ./foo ./bar ./baz -name "*.js"
# remove prefix or rename
for f in eremit*; do mv $f `sed "s/prefix_//g" <<< $f`; done
# find top 10 large files
find . -printf '%s %p\n'| sort -nr | head -10
# find large folders
du -cks * | sort -rn | head
# interface and ip address
ifconfig | awk '
/^[a-z]+/ {
sub(/:/,"",$2); iface=$1 }
/^[[:space:]]*inet / {
split($2, a, "/")
print iface" : "a[1]
}'
# find and replace on a file
sed -i 's/foo/bar/g' file.txt
# convert png to svg
for f in *_shape.png; do convert $f -fill black -opaque white -alpha off $(echo $f | sed 's/\.png$/.pnm/') && potrace $(echo $f | sed 's/\.png$/.pnm/') -s -o $(echo $f | sed 's/\.png$/.svg/') && cp $(echo $f | sed 's/\.png$/.svg/g') my/new/folder/; done
#duplicate en folder to the names form a.txt file each line
while read -r p; do cp -rfv en $p; done < a.txt
# cd into every directory in current folder and run npm command
for d in */; do echo $d; cd $d; npm outdate; cd - > /dev/null; done
# Repair ext* file system
e2fsck -f -y -v -C 0 /dev/sdxx
# recusively set permission on www
find /A -type d -exec chmod 0755 {} \;
find /A -type f -exec chmod 0644 {} \;
# download website with wget
$ wget \
--recursive \
--no-clobber \ # don't overwrite any existing files (used in case the download is interrupted and resumed).
--page-requisites \ # get all the elements that compose the page (images, CSS and so on).
--html-extension \ # save files with the .html extension.
--convert-links \ # convert links so that they work locally, off-line.
--restrict-file-names=windows \ # modify filenames so that they will work in Windows as well.
--domains website.org \ # don't follow links outside website.org.
--no-parent \ # don't follow links outside the directory tutorials/html/.
www.website.org/tutorials/html/
# resize /tmp
sudo echo 'tmpfs /tmp tmpfs nodev,nosuid,size=4G 0 0' >> /etc/fstab
# The tmpfs can also be temporarily resized without the need to reboot.
sudo mount -o remount,size=4G,noatime /tmp
# Resize image
# View size
find . -type f -size +1000000c -exec identify -format "%[fx:w]x%[fx:h]" {} \;
#Find and resize
find . -type f -size +1000000c -exec mogrify -resize 2000000@ {} \;
#Optimize iamge bigger than 100kb
find . -type f -size +100000c -exec mogrify -strip -interlace Plane -gaussian-blur 0.05 -quality 85% {} \;
# watch file change and run command (sudo apt install inotify-tools)
while inotifywait -e close_write n.c; do gcc -o n n.c && ./n; done
# add prefix and sufix to list of files with file extension at the end (removes if file already exist with the exact name)
for file in RPT_*.sql; do newFile="dbo.${file%.sql}.StoredProcedure.sql" && rm $newFile; mv $file $newFile; done
# fix $'\r': command not found on windows cygwin
sed -i 's/\r$//' filename
# generate ssl certificate for web
openssl genrsa -des3 -out server.key 2048 #private key
openssl req -x509 -new -nodes -key server.key -sha256 -days 1825 -out server.pem #root certificate
# android sdcard backup
rsync -aHXxv --numeric-ids --progress -e 'ssh -p22 -T -o Compression=no -x' --exclude 'ADM/*.zip' --exclude 'ADM/*.apk' --exclude 'Download/*.zip' --exclude 'Download/*.apk' --exclude '*.x' --exclude 'Android' --exclude 'data' --exclude 'DCIM/.thumbnails' /sdcard/ user@host:~/3t/
# find and replace filename
rename 's/^123_//' *.js
# remove all file and folders with the name obj and bin
find . -maxdepth 2 -name obj -exec rm -rf {} \; && find . -maxdepth 2 -name bin -exec rm -rf {} \;
# copy files newer than given file to a location recursively
for x in `find . ! -path "./obj/*" -regex ".*\.\(aspx\|dll\|js\|css\|html\)$" -type f -newer frmLogin1.aspx.cs`; \
do cp --parents $x ~/Desktop/checklist/moneyswap-vip/bo/; \
done;
# transparent gif base64 image >> data:image/gif;base64,<base64>
convert -size 256x128 xc:transparent gif:- | base64
# To remove the duplicate lines preserving their order in the file use:
awk '!visited[$0]++' your_file > deduplicated_file
# base64 aws credentials
base64 ~/.aws/credentials | tr -d \\n
# Resice images and center image with backgrund color of specific area
cat thumbs | while read line
do
c=$(convert $line -format "%[pixel:s.p{1,1}]" info:)
convert -background "$c" $line -resize 320x200 -gravity center -extent 320x200 out/$line
done
# Find and delete directory older than 6 month
find . -maxdepth 3 -type d -name node_modules -mtime +180 -exec rm -rf {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment