-
To check the avilable memory
df -h
-h is human readable
-
current directory
pwd
-
to list the directory with the permission
ls -l
to list all directory with hidden files
ls -a
-
SCP commands
Copy the file "foobar.txt" from a remote host to the local host
$ scp your_username@remotehost.edu:foobar.txt /some/local/directory
Copy the file "foobar.txt" from the local host to a remote host
$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory
Copy the directory "foo" from the local host to a remote host's directory "bar"
$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar
Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"
$ scp your_username@rh1.edu:/some/remote/directory/foobar.txt \
your_username@rh2.edu:/some/remote/directory/
Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host
$ scp foo.txt bar.txt your_username@remotehost.edu:~
Copy the file "foobar.txt" from the local host to a remote host using port 2264
$ scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory
Copy multiple files from the remote host to your current directory on the local host
$ scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} .
$ scp your_username@remotehost.edu:~/\{foo.txt,bar.txt\} .
- checking folder size
du -sh ./*
- ./* mean everything in current directory
- s only the directory in current directory
- h for human readable
for only hidden files and folders
du -hs .[!.]*
for all ( hidden + non hidden files and folders)
du -hs .[!.]* *
- change directory color
LS_COLORS="di=1;33"
- zipping a folder
zip -r web.zip web
web == directory to zip
web.zip == zip file name
- The groups command will show you what groups the user belongs to
groups
looking for groups luser belongs to
groups luser
- To get running process with process id
ps -eaf
- Listing all the LISTENING Ports of TCP and UDP connections
netstat -a
Listing TCP Ports connections
netstat -at
Listing UDP Ports connections
netstat -au
Listing all LISTENING Connections
netstat -l
Listing all TCP Listening Ports
netstat -lt
Listing all UDP Listening Ports
netstat -lu
Listing all UNIX Listening Ports
netstat -lx
netstat -tunlp
-
To add cronjob on linux
crontab
-
grep, which stands for "global regular expression print," processes text line by line and prints any lines which match a specified pattern.
grep --color -n -i "search string" targetfile
here --color to color the match string -n is to show the line numbers in file -i option to perform a case-insensitive match: r option, which tells grep to perform its search recursively in folder file name can be replaced with * to search all files targetfile is name of file in which we are searching
-
Find file in directory
find /search/directory/ -name "matching file search criteria" -actions find /dir/to/search -name "pattern" -print find /dir/to/search -name "file-to-search" -print find /dir/to/search -name "file-to-search" -print [-action]
-
file folder listing with size in MB
ls -l --block-size=M
-
To run a node app forever install forever after going in to the node project
$ [sudo] npm install forever -g
If you are using forever programmatically you should install forever-monitor.
$ [sudo] npm install forever-monitor
Usages Example
forever start app.js
-
Installing node and npm
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - $ sudo apt-get install -y nodejs $ node -v $ sudo npm install npm --global
-
change node version
$ nvm install 0.10.25 $ nvm use 0.10.25 $ nvm alias default 0.10.25
-
To list the current rules that are configured for iptables.
sudo iptables -L
-
installing mongo on ubuntu 16.04
Step 1 — Adding the MongoDB Repository sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
Step 2 - add the MongoDB repository details so apt will know where to download the packages from. echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
Step 3 - update the packages list. sudo apt-get update
Step 4 - Step 2 — Installing and Verifying MongoDB sudo apt-get install -y mongodb-org
Step 5 - MongoDB with systemctl. sudo systemctl start mongod
Step 6 - check that the service has started properly. sudo systemctl status mongod
Step 7 - enable automatically starting MongoDB when the system starts. sudo systemctl enable mongod
The MongoDB server is now configured and running, and you can manage the MongoDB service using the systemctl command (e.g. sudo systemctl stop mongod, sudo systemctl start mongod).
-
setting up swap in linux
Setup Swap By default there is no swap setup on my VPS, it is required especially on a system with limited memory. I am setting up a 4GB swap, which is the most common swap size used for a VPS.
dd if=/dev/zero of=/mnt/myswap.swap bs=1M count=4000 mkswap /mnt/myswap.swap swapon /mnt/myswap.swap
Now let’s add it into fstab so it will activate at boot.
nano /etc/fstab
Add the following line at the end of the file.
/mnt/myswap.swap none swap sw 0 0
Ctrl+O to save, and Ctrl+X to exit the nano editor.
Now your swap is setup, you can modify the size in the future if you need more or less.
-
Find file in directory
find /search/directory/ -name "matching file search criteria" -actions find /dir/to/search -name "pattern" -print find /dir/to/search -name "file-to-search" -print find /dir/to/search -name "file-to-search" -print [-action]
luser : test luser adm cdrom sudo dip plugdev lpadmin sambashare chmod - modify file access rights su - temporarily become the superuser chown - change file ownership chgrp - change a file's group owner iptables telnet crontab nano iptables grep netstat -tunlp telnet crontab nano ps -eaf
Others
2>/dev/null
2 = Error Output ...
= ...is redirected...
/dev/null = ...to device NULL (no Output)