Cheatsheet Shell Scripts

Something useful for shell scripts/gawk scripts/git commands/aws commands

create public ssh key

1
2
$ ssh-keygen -t rsa -C "siwei"
$ cat ~/.ssh/id_rsa.pub

connect to the remote server and modify the files on the server remotely

1
2
3
#download rmate firstly
$ ssh -R 52698:127.0.0.1:52698 username@server
$ rmate -p 52698 filename

change group of files

1
2
#change all files under this folder
$ chgrp -R group file

deal with gzipped files

1
2
3
4
5
6
7
8
#have a look of compressed files
$ zcat file | head

#uncompress files
$ gunzip -c file > /directory/file

#compress files
$ gzip -c file > /directory/file

loop

1
2
3
$for i in `seq 1 22`;do
gawk -v chr=${i} '$5=="SNP" {print chr" "$2}' >> file
done

ifelse

1
2
3
4
5
6
7
$ if ["answer" == "local"]; then
for i in `seq 1 22`;do
echo "hello world" >> file1
done
else
echo "hello world" >> file2
fi

git commands

1
2
3
4
5
6
7
#one local repository to multiple remote repositories
$ git remote add both repository1
$ git remote remote set-url --add --push both repository1
$ git remote set-url --add --push both repository2
$ git add .
$ git commit -m first_commit
$ git push both

aws commands

1
2
3
4
#to get started
$ aws configure
#list the contents in S3
$ aws s3api list-buckets