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.dpufTo 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 Macstep1: 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 machineuser@mac:~# ssh -L 9000:localhost:8080 user@linux
user@linux:~#
step3: open a browser and point tohttp://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
Post a Comment