Skip to content

Instantly share code, notes, and snippets.

@covelus
Last active April 12, 2020 13:47
Show Gist options
  • Select an option

  • Save covelus/251471b088e2cb512015c128f613121d to your computer and use it in GitHub Desktop.

Select an option

Save covelus/251471b088e2cb512015c128f613121d to your computer and use it in GitHub Desktop.
Useful *nix SHELL commands I probably will forget
#
# Useful shell commands (mostly compatible with recent versions of GNU/BASH for GNU/Linux, or ZSH in MacOS) that almost sure I will need to write again, but I probably will eventually forget
# -AUTHOR: Breogan Costa
#
# --------------------- TESTED IN BASH 4 or superior ---------------------
# Get all filenames without extension
ls fileName* | xargs -I '{}' basename {} .extension
# Rename all the files starting by Debian name (i.e: VM images), adding an extra extension
ls Debian_* | xargs -I '{}' mv '{}'{,.pre-reclaim}
# The whole process can be improved with 2 commands
# 1.- Remove the extensions
for f in *.qcow2; do mv $f `basename $f .qcow2`; done;
# or
find ./ -name "*.qcow2" -exec sh -c 'mv $0 `basename "$0" .qcow2`' '{}' \;
#2.- Convert the images (if only these images are present in the directory)
ls * | xargs -I '{}' qemu-img convert -f qcow2 '{}' -O qcow2 '{}'.qcow2
# Remove CentOS6 or 7 games and unwanted apps (some are very cool, but not necessary for some workstations) in a very specific work environment
sudo yum remove libreoffice* gnome-games five-or-more gnome-sudoku gimp gnome-mahjongg cheese gnome-mines gnome-chess quadrapassel k3b kontact kaddressbook konquest konqueror korganizer ktimetracker gnome-games gnome-games-extra inkscape rhythmbox brasero*
sudo yum groupremove "KDE Desktop" "Games and Entertainment"
sudo yum autoremove
package-cleanup -q --leaves | sudo xargs -l1 yum -y remove
# Remove Debian 8 or 9 games and unwanted apps (some are very cool, but not necessary for some workstations) in a very specific work environment
sudo apt remove --purge libreoffice* gnome-games five-or-more four-in-a-row gnome-sudoku gnome-mahjongg gnome-tetravex gnome-nibbles gnome-robots gnome-mines gnome-chess gnome-klotski cheese hitori iagno swell-foop quadrapassel xboard transmission transmission-gtk xboard rhythmbox inkscape gimp
sudo apt autoremove && sudo apt clean # Debian 8 may require previous versions of this utilities, using apt-get
# --------------------- TESTED IN ZSH 5.7 or superior ---------------------
# Remoble the ugly .DS_Store files before processing a directory
find . -name .DS_Store | xargs rm
# Remove all files in a directory excepting the ones with a pattern in the name, i.e: '_en_'
find . -type f ! -name '*_en_*' -exec rm {} \;
# I have a directory containign other directories.
# I want to zip each of them in a single file:
find . -maxdepth 1 -exec zip -r {}.zip {} \;
# I have a set of files following a pattern name(1), name(2), .., name(10), name(11), .. name(N)
# I want to rename the 1 - 9 to 01 - 09:
# 1: install rename if not in the system (for example, $sudo apt install rename or $brew install rename)
find . -name "*(?)*" -exec rename 's/\(/\(0/g' "{}" \;
# Mount EXT4 SSDs in MacOS (read-only, as recommended) using FUSE
brew cask install osxfuse
brew install ext4fuse
diskutil list
# connect the SSD
diskutil list # check the new available unit, lets's guess /dev/disk3, with a single EXT4 partition
sudo ext4fuse /dev/disk3s1 ~/temp/LinuxFUSE -o allow_other
sudo umount temp/LinuxFUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment