Linux Commands¶
Data Management Commands¶
List folder size :
Get all extensions and their respective file count in a directory :
find ./ -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -n
Delete all file of a type :
Clean Music collection :
find -type f -name "*.mp3" -delete && find -type f -name "*.jpg" -delete && find -type f -name "*.png" -delete && find -type f -name "*.jpeg" -delete && find -type f -name "*.MP3" -delete && find -type f -name "*.JPG" -delete && find -type f -name "*.PNG" -delete && find -type f -name "*.JPEG" -delete && find -empty -type f -delete && find -empty -type d -delete
Delete empty directories :
Count empty directories :
Create a folder to each files :
Move every .ext to the current folder:
Unrar recurcively (Source: https://unix.stackexchange.com/a/97203):
Unzip recurcively (Source: https://unix.stackexchange.com/a/97203):
Rename a file the same as its containing folder (Source: https://askubuntu.com/questions/901141/can-i-rename-files-within-a-folder-with-the-name-of-the-parent-folder )
find -type f -exec bash -c 'fp=$(dirname "$1");fn=$(basename "$fp");px="${1##*.}";mv "$1" "$fp"/"$fn"."$px"' sh "{}" \;
Merge 2 folders and rename the duplicates (Source: https://www.linuxquestions.org/questions/showthread.php?p=6257365#post6257365):
Every 1 second print the number of seconds that passed since the script started (Based on: https://unix.stackexchange.com/a/235280)
Tar¶
Pack :
Unpack :
View :
Vim¶
Insert text at the begining of every line (Source: https://techglimpse.com/insert-text-beginning-line-vim/ )
Delete all lines containing [REPLACEME] (Source: https://stackoverflow.com/questions/46781951/efficient-way-to-delete-line-containing-certain-text-in-vim-with-prompt )
Remove Comments :
Remove blank lines:
Remove blank lines (including the lines that have zero or more whitespace characters)
Sort lines alphabetically (Source: https://thoughtbot.com/blog/sort-lines-alphabetically-in-vim )
Debian¶
Get all packages installed from a specific repository? (Source: https://unix.stackexchange.com/a/401625 )
dpkg -l | awk '/^.i/ {print $2}' | xargs apt-cache policy | awk '/^[a-z0-9.\-]+:/ {pkg=$1}; /\*\*\*/ {OFS="\t"; ver=$2; getline; print pkg,ver,$2,$3}'|grep -v /var/lib/dpkg/status| sed -e 's/://'|awk '{printf "%-40s %-36s %-36s %-16s \n",$1,$2,$3, $4}' | grep -i [SOURCE]
Arch Linux¶
List installed packages not originating from the Arch repositories (usually packages from the AUR):
List installed packages originating from the Arch repositories
List explicitly installed packages:
Others¶
Create SymLink :
View used port :
Rclone :