Category: Linux

9 Aug

How to create git alias by editing .gitconfig

We can create git aliases simply using the git config command.
Example is
git config --global alias.co checkout

But here, we are discussing another method of managing git aliases by editing the .gitconfig file.

Using git aliases will help you to use shorter commands for various operations.
You can create git aliases by following the below steps.

1) Open your .gitconfig from your home folder.
If you are using vim, you can open it by the below command.

vim /home/[user]/.gitconfig
Replace [user] with your username.
You can use any editor.

2)If you already added your email and name to the config, your .gitconfig
will be like
[user]
email = myemail@domain.com
name = myName

Now we have to add a new section [alias]

After that your .gitconfig will be

[user]
email = myemail@domain.com
name = myName
[alias]

3) Now let’s add one alias.

Instead of typing git status, if you would like to use git st
Then we have to add the below line under [alias].
st = status

Now the new .gitconfig will be like

[user]
email = myemail@domain.com
name = myName
[alias]
st = status

4) If you would like to add more aliases,
You can do as shown below.

[user]
email = myemail@domain.com
name = myName
[alias]
st = status
br = branch
co = checkout
pl = pull origin
ps = push origin
plm = pull origin master
psm = push origin master
coi = checkout integration
cob = checkout -b
lbd = branch -D
rbd = push origin –delete
com = commit -m
mg = merge

9 Aug

Create a bootable USB flash drive from linux terminal

First have a look at the partitions and file systems on the system with this command:
sudo fdisk -l

The drive that you’d like to target might be something like /dev/sdc, /dev/sdd or /dev/sde. You can get the target drive from the fdisk -l command.

Then locate the path of the iso image. Assume that the path of iso image is: /home/user/Downloads/ubuntu-18.04-desktop-amd64.iso
and the path of target drive is: /dev/sdc

Then command to create the bootable USB flash drive is

sudo dd if=/home/user/Downloads/ubuntu-18.04-desktop-amd64.iso of=/dev/sdc status=progress

status=progress will give you the progress report on the terminal.

19 Jul

Useful Linux Tips

#Replace all occurrence of City with Town in every txt file within the current directory.
$sed -i 's/City/Town/g' *.txt

Using vim editor, replace foo with bar from line 23 to 30
:23,30s/foo/bar/g

19 Jul

Useful git commands

#remove files only from local, not from git
$git rm -r --cached myfolder/

#reset back to the head
$git reset --hard my_branch

#make a branch same as master
$git checkout -B new master

#Delete local branch
$git branch -d branch_name

#delete a remote branch
git push origin --delete branch_name

#push a new local branch to remote
$git push -u origin my_branch

#ignore file mode change
$git config core.fileMode false

#Fetch a remote branch
$git fetch
$git checkout new_branch

19 Jul

Useful PostgreSQL Queries and Commands

Connecting as root
$sudo -u postgres psql

Connect to database server:
$psql --username=myusername --host=localhost --password

Select a database with name mydatabase:
myusername=>\c mydatabase;

List all tables:
myusername=>\dt;

Get table structure:
myusername=>\d+ my_table;

Take a dump
$pg_dump --username=myusername --host=localhost --password mydatabase > db.sql

Import a database
$psql --username=myusername --host=localhost --password mydatabase < db.sql

10 Jan

How to do FTP auto login from Linux?

How to create a FTP auto login set up in Linux?

1)Go to your home folder.

cd /home/my-name

2)Crate a file named .netrc in your home folder.

And add a line as below.
machine [ftp.myserver.com] login [my-username] password [my-password]

Then save the file

3)Set permissions so that only owner can read the file.

chmod 0600 ~/.netrc

4)From shell just type
ftp [ftp.myserver.com] [port]

You are logged in!
It won’t ask any user name or password now.