Useful Terminal commands for linux

 

Set terminal title

Add these codes to ~/.bashrc

# function to set terminal title
function set-title(){
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}

now while in terminal, run: set-title “New Title”

Re-run previous command

mkdir /etc/myDir // sample command
# Permission denied
sudo !!
# Success!

Find PID of a process

pgrep firefox // replace firefox with expected process name

Copy contents of a file to clipboard

xclip -sel clip < 51-android.rules

Free PID/port

netstat -ntlp
kill -9 pid

Remove Non-empty folder

rm -rf mydir

Copy from terminal

Ctrl+Shift+C

Change ownership

chown -c piash:piash /var/www/html/ [new, root]

 

Install tasksel

sudo apt-get install tasksel
tasksel

Install phpmyadmin

sudo apt-get install phpmyadmin

Open mysql from terminal

mysql -u root -p

To update & upgrate OS

sudo apt-get update && sudo apt-get upgrade

Install Sublime-Text-2

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

Install Sublime-Text-3

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

Open terminal anywhere

sudo apt-get install nautilus-open-terminal

Create tar.gz

tar czf new-tar-file-name.tar.gz file-or-folder-to-archive

Extract tar.gz

tar -xzf tar-file-name.tar.gz

Run command from history

history
!800 //use number of command you want to run

Search from history

Use Ctrl+R in terminal & search for expected command

 

Clear cache

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

Which process is listening on which port

sudo netstat -peanut

Leave a Reply

Your email address will not be published. Required fields are marked *