Linux 101

Yuwei BaoSeptember 24, 2022

A place to store some basic linux commands

Grep A or B:

grep -E "PATTERN1|PATTERN2" FILE

Extract .tar.gz file to current working directory:

tar -xf filename.tar.gz

Extract .tar.gz file to a different working directory:

tar -xf filename.tar.gz -C /home/user/files

Zip a file to .gz with progress

gzip -v filename

Decompress a file from .gz

gunzip filename.gz

Add character # to the begging of each line of a file

sed 's/^/#/' file.txt  > new-file.txt

Alternatively, use the -i option with the sed command to edit a file in place. Be careful, as this will overwrite the file with the new changes.

sed -i 's/^/#/' file.txt

Delete empty files in current directory

find . -type f -empty -print -delete