Skip to content

Instantly share code, notes, and snippets.

@Mahedi-61
Last active January 19, 2020 20:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Mahedi-61/640b5721f09161d77cf685d28dd3281e to your computer and use it in GitHub Desktop.
Save Mahedi-61/640b5721f09161d77cf685d28dd3281e to your computer and use it in GitHub Desktop.
some useful unix commands used most commonly.
#!/bin/bash
# This gist contains commands used in my everyday life
### compressing a file
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
# -c: create an archive.
# -z: compress the archive with gzip.
# -v: verbosity
# -f: allows you to specify the filename of the archive
### unzip / unarchiving a file
tar -xvzf community_images.tar.gz
# z: tells tar to decompress the archive using gzip
# x: collect files or extract them
### moving or renaming a file
mv old_directory/file new_directory/file
### making a file executable
chmod +x filename.sh
# delete or removing a file
rm -rf test_file.txt
### installing .tar.gz file
tar -zxvf archive-name.tar.gz
cd archive-name
./configure
make
sudo make install
# making a symbolic link
ln -sf /path/to/file /path/to/symlink
# -sf : for create and update
# converting file extension of a directory
for i in *.png
do
filename=${i%%.*};
convert $i "$filename.jpg"
done
num=300
for i in *.png
do
num=$(( $num + 1 ))
mv $i "$num.jpg"
done
# print only first few lines of a file (for example 20 lines)
head -n 20 file_name
# split a large file into chunks based on given line number (for example 50000 lines)
split -l 50000 file_name
# remove first 3 lines in a file (starts from: 1 and "d" for delete, and "i" for inplace)
sed -i '1,3d' file.txt
# remove first 10 lines and print it in another file
sed '1,10d' <input_file >output_file
# 's' for substitue and 'g'for global replace
sed -i 's/original/new/g' file.txt
# saving selected columns into one output csv file
awk 'BEGIN {OFS=","}; {print $2,$5,$7,$9,$12,$13}' file.tsv > new.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment