Skip to content

Linux Commands

Data management commands

List folder size :

du -h --max-depth=1

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 :

find -type f -name "*.[FILETYPE]" -delete

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 :

find -empty -type d -delete

Count empty directories :

find -empty -type d | wc -l

Create a folder to each files :

for %i in (*) do md "%~ni"
for %i in (*) do move "%i" "%~ni"

Move every .ext to the current folder:

find -type f -name "*.ext" -exec mv {} . \;

Unrar recurcively (Source:

find . -name '*.rar' -execdir unrar e '{}' +

Unzip recurcively (Source:

find . -name '*.zip' -execdir unzip -tq '{}' +

Rename a file the same as its containing folder (Source: )

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:

cp --backup=numbered /source/* /destination/

Every 1 second print the number of seconds that passed since the script started (Based on:

    while   sleep   "$((RANDOM%1))"
    do      sleep   "$((1-(SECONDS%1)))"
            echo    "$SECONDS"


Pack :

tar -cfv [FILENAME].tar [SOURCE]

Unpack :

tar -xfv [FILENAME].tar

View :

tar -tfv [FILENAME].tar


Insert text at the begining of every line (Source: )


Delete all lines containing [REPLACEME] (Source: )


Remove Comments :


Remove blank lines:


Remove blank lines (including the lines that have zero or more whitespace characters)


Sort lines alphabetically (Source: )



Get all packages installed from a specific repository? (Source: )

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):

pacman -Qm

List installed packages originating from the Arch repositories

pacman -Qn

List explicitly installed packages:

pacman -Qe


Create SymLink :

ln -s [Source] [Name]

View used port :

netstat -npl

Rclone :

rclone move --verbose --transfers 2 [SOURCES] [DEST]
rclone copy --verbose --transfers 2 [SOURCES] [DEST]
rclone move --verbose --transfers 2  '/path/to/source/' 'Backups:Dest/'