Skip to main content

Linux command 2

Frequently used Linux Terminal Commands

To create a directory/folder

mkdir myapps/app/tasks
# suppose if app folder is not exist then it will through error
# If you want to create a parent folder if not available automatically
mkdir -p myapps/app/tasks

To create a file:

touch myfile

To view a file

cat myfile

To view last few lines of file

tail myfile

To view last few lines of file with live update e.g. watching log files in terminal

tail -f myfile  # f stands for follow

To remove/delete a file

rm filename
# if you want to get a prompt asking you do u want to delete file? y/n:
rm -i filename

To remove a direcory

rm -rf dirname

To copy a file

cp filename

To rename a file

mv myoldfile mynewfile

To List files in tree structure

# In Linux
tree

#In Mac
find .

To access remote machine

ssh -l user machine
ssh -l root finance
ssh user@machine

To handle Proxies

export http_proxy=http://192.168.5.100:80
export https_proxy=https://192.168.5.100:80
export ftp_proxy=ftp://192.168.5.100:80

To remove Proxy setting when you have a direct access

export http_proxy=
export https_proxy=
export ftp_proxy=

To copy file/directory from one machine to another machine

# push to remote machine
sudo scp -r filename user@machine:path
sudo scp -r koti/kanna root@finance:myfolder/subfolder
sudo scp -r koti/kanna root@finance:/home/folder

# pull from remote machine
sudo scp -r root@finance:/home/folder koti/kanna

To Run Processes in the background

nohup application filename > output.log &
nohup node server11.js > output.log &

To know list of processes running

ps -ef

To filter the required processes

ps -ef | grep searchString

To kill the running process

kill processID
kill 25998

To add a path for node

export NODE_PATH="/usr/local/lib/node"

Mongodb

/etc/init.d/mongodb status
/etc/init.d/mongodb start
/etc/init.d/mongodb stop
/etc/init.d/mongodb restart

Convert as Executable

chmod 0777 binaryName
./binaryName

Domain Name Mappings in Mac OS

# To map your IP address to the below hosts
# edit
sudo vim /etc/hosts
# Add below line in this file
koteswara.sub.example.com koteswara localhost

Creating tar.gz file for deployment

tar -czvf myname.tar.gz sourceFolder # Contents of source folder conted as .tar.gz
# c for create; z for zip ; v for verbose list files ; f for file
# Use http://explainshell.com/ to know the meaning of the command
# For golang project sourceFolder contains go binary and static files

Extracting on Deployment machine

tar -xzvf myname.tar.gz optionalTargetFolder # if no folder name is specified it will extract to cwd
# x for Extract

Excelent Linux Commands Tutorial

Linux Commands In Structured Order with Detailed Reference - See more at: http://linoxide.com/guide/linux-command-shelf.html#sthash.wdcmOdwg.dpuf

To Remove Entries from known hosts

ssh-keygen -R hostname

Once i created a digitalOcean server, it has provided an ip. 
I used ssh to access this machine. At that time this ip got added to known_hosts of .ssh folder
Later i deleted this server and again created a new server but digitalOcean assigned same ip for the new server.
When i tried to access this machine via ssh, it throwed an err as finger print doesn't match. Used the above command to solve this problem.

Procedure to create ssh tunnel and access localhost of other machines:

My virtual Machine is linux and my physical Machine is Mac
step1: Access virtual machine and start rethinkdb
user@mac:~# ssh user@linux
user@linux:~# rethinkdb
step2: create a SSH tunnel to access locahost:8080 of linux machine
user@mac:~# ssh -L 9000:localhost:8080 user@linux
user@linux:~#
step3: open a browser and point to
http://localhost:9000
Thats it! You need not change any browser settings!
Resource:
http://www.youtube.com/watch?feature=player_embedded&v=VdkLejEN3So

To Create zip file

zip -r store.zip store/*

To Unzip

unzip store.zip -d targetlocation

Comments

Popular posts from this blog

VMware -> root access is required for the operations you have chosen FIX ubuntu 14.04

Example ~$ wget https://www.vmware.com/go/tryworkstation-linux-64 [sudo] password for javad: *****  --2016-08-11 11:19:10--  https://www.vmware.com/go/tryworkstation-linux-64 Resolving www.vmware.com (www.vmware.com)... 104.86.190.190, 2a02:26f0:c000:183::2ef, 2a02:26f0:c000:190::2ef ..... .... ... .. . .. ... .... .....  ~$ sudo chmod +x tryworkstation-linux-64 ~$ sudo -i ~#  ~# cd / root@javad-quad:/# cd /home/javad/ root@javad-quad:/home/javad# ./tryworkstation-linux-64 Extracting VMware Installer...done. ... Product: VMware® Workstation 12 Pro Version: 12.1.1 build-3770994 licence key: VY1DU-2VXDH-08DVQ-PXZQZ-P2KV8 VF58R

fix audio in kali linux

1. leafpad /etc/pulse/daemon.conf 2. find "default-sample-channels" and change the number -->1-->save-->exit 3. pulseaudio start 4. pulseaudio --start Practice  root@javad:~# sudo leafpad /etc/pulse/daemon.conf  root@javad:~# pulseaudio start E: [pulseaudio] main.c: Too many arguments. root@javad:~# pulseaudio  --start W: [pulseaudio] main.c: This program is not intended to be run as root (unless --system is specified).  root@javad:~# reboot