Posts

Showing posts from March, 2015

ubuntu practical guide

The shell doesn't require that the name of the program appear first on the command line ubuntu@ubuntu:~/test1$ ls ubuntu@ubuntu:~/test1$ <b cat ubuntu   tty7         2015-03-15 02:28 (:0) ubuntu   pts/0        2015-03-15 02:33 (:0) Sun Mar 22 10:20:41 PDT 2015 ubuntu@ubuntu:~/test1$ >t <b cat ubuntu@ubuntu:~/test1$ ls b  t ----------------------- The shell doesn't look through all directories but only the ones specified by the variable named PATH ----------------------- ubuntu@ubuntu:~/test1$ cat b ubuntu   tty7         2015-03-15 02:28 (:0) ubuntu   pts/0        2015-03-15 02:33 (:0) Sun Mar 22 10:20:41 PDT 2015 ubuntu@ubuntu:~/test1$ cat b | grep -o ubuntu | tr ubuntu UBUNTU UBUNTU UBUNTU ubuntu@ubuntu:~/test1$  ---------------------- ubuntu@ubuntu:~/test1$ who | tee who.out | grep ubuntu ubuntu   tty7         2015-03-15 02:28 (:0) ubuntu   pts/0        2015-03-15 02:33 (:0) ubuntu@ubuntu:~/test1$ ubuntu@ubuntu:~/test1$ ls

processes | environment variables

The shell is an interpreter that executes commands on the user's behalf The terminal is not the same as the shell ----------------- Check which shell is running: ubuntu@ubuntu:~$ echo $0 bash ----------------- pipe |  allows using the output from some commands as an input to other ----------------- ubuntu@ubuntu:~$ vim & [1] 4515 ubuntu@ubuntu:~$ ps   PID TTY          TIME CMD  3255 pts/0    00:00:00 bash  4515 pts/0    00:00:00 vim  4522 pts/0    00:00:00 ps [1]+  Stopped                 vim ubuntu@ubuntu:~$ jobs [1]+  Stopped                 vim ubuntu@ubuntu:~$ fg %1 vim           #runs VIM ubuntu@ubuntu:~$ ----------------- ubuntu@ubuntu:~$ pwd_text=$(pwd;date) ubuntu@ubuntu:~$ echo "pwd_text" pwd_text ubuntu@ubuntu:~$ echo "$pwd_text" /home/ubuntu Sun Mar 15 02:58:32 PDT 2015 ubuntu@ubuntu:~$  ----------------- to make variable - environment variable ubuntu@ubuntu:~$ export pwd_text=$(pwd;date)

lsof | which process is listening upon a port

So to see which process is listening upon port 80 we can run: root@mystery:~# lsof -i :80

int questions

Probably the simplest and most common way to do this would be by using the command: tail -F $LOGFILE ------------- How To check Memory stats and CPU stats ? Ans:  Using ‘free’ & ‘vmstat’ command we can display the physical and virtual memory statistics respectively.With the help of ‘sar’ command we see the CPU utilization & other stats. ------------- Why is LVM is required ? Ans: LVM stands for Logical Volume Manager , to resize filesystem’s size online we required LVM partition in Linux. Size of LVM partition can be extended and reduced using the lvextend & lvreduce commands respectively. ------------- How to create partition from the raw disk ? Ans: Using fdisk utility we can create partitions from the raw disk.Below are the steps to create partition from the raw dsik : – fdisk  /dev/hd* (IDE) or /dev/sd* (SCSI) – Type n to create a new partition –  After creating partition , type w command to write the changes to the partition table. ------------- Ho

find

get list of subdirectories containing file approach#1 $ find . - type f - name '*f*' | grep - o "\(.*\)/" | sort - u | head - 5 ./ dir1 / dir103 / ./ dir1 / dir104 / ./ dir1 / dir105 / ./ dir1 / dir106 / ./ dir1 / dir107 / approach#2 $ find . - type f - name '*f*' - exec dirname {} \; | sort - u | head - 5 ./ dir1 / dir103 ./ dir1 / dir104 ./ dir1 / dir105 ./ dir1 / dir106 ./ dir1 / dir107 --------- Find all txt and copy to newfolder find . -name "*.txt" -exec cp {} newfolder \; ------- $ find ./test -name "*.php" ./test/subdir/how.php ./test/cool.php To ignore the case, just use the "iname" option instead of the "name" option. $ find ./test -iname "*.Php" ./test/subdir/how.php ./test/cool.php For example we don't want to go more than 2 or 3 levels down in the sub directories. This is done using the maxdepth option. $ find ./test -maxdepth 2 -name "*.

unix online terminal

http://www.tutorialspoint.com/unix_terminal_online.php

remote consoles in Linux/Solaris

Remote logins are also known as  "shell access" ------------- Advanced Lights Out Management (ALOM) ALOM is the new standard System Controller (SC) for remote out-of-band management for all current and future VSP servers.  ALOM functions allow for monitoring, logging, alerting and for basic control of the system. ALOM is particularly useful for remotely managing a server in a typical "lights out" environment.  To gain access to the server's console, enter the command 'console' or if there is already an active ALOM/RSC console session, enter the command 'console -f'. On ALOM systems, to return to the ALOM card, enter key sequence “#.” and then type 'logout'. On RSC systems, to return to the RSC car, enter key sequence “~.” and then type 'logout'. ----------------------- Sun ILOM Remote Console is a Java application that allows you to remotely redirect and control the following devices on the host server: Keyb

difference between Solaris and Linux

both are unix based and supports the  POSIX  API but the kernel implementation is completely different. the Solaris (and OpenSolaris ) kernel supports some interesting features not supported by the Linux kernel, like  ZFS  which is probably the best file system at the moment in any operating system, and  Zones  which allow you to create lightweight instances of the operating system - similar to isolated virtual machines but with much lower overhead.

crontab

Cron 01 * * * * root run-parts /etc/cron. hourly 02 4 * * * root run-parts /etc/cron. daily 02 minutes after an hour 22 4 * * 0 root run-parts /etc/cron. weekly To run /root/script/backup at 23:00, every day, enter # crontab -e 0 23 * * * /root/script/backup Run foo job very weekday (MON-Fri) at 6am, enter: 0 6 * * 1-5 /root/script/backup 1 0 * * * printf > /www/apache/logs/error_log * * * * * command to be executed ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └───── day of week (0 - 7) (Sunday=0 or 7) │ │ │ └────────── month (1 - 12) │ │ └─────────────── day of month (1 - 31) │ └──────────────────── hour (0 - 23) └───────────────────────── min (0 - 59) ------------------- 1. Scheduling a Job For a Specific Time 10th June 08:30 AM Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20. 30 08 10 06 * /home/ramesh/full-backup 30 – 30th Minute 08 – 08 AM 10 – 10th Day 06 – 6th Month (June) * – Every day of the w

cut

echo 'This is a test' | cut -d ' ' -f2- is a test How to cut TAB character cat ct Hello the world test with       tab cat ct | cut -d$'\t' -f3- tab ------------------- bash-3.00# cat a.txt root console Apr 10 15:17 (:0) root pts/3 Apr 10 15:20 (:0.0) bash-3.00# cut -f2 a.txt (:0) (:0.0) bash-3.00# cut -f1 -d":" a.txt root console Apr 10 15 root pts/3 Apr 10 15 ------------- cut -f 1-d ':' /etc/passwd | sort

join vars /dev/null bash scripting du -k kill process write

ifconfig eth0 -  display  network config pr command makes a two-column report with header headername pr -2 –h “headername” somefile  ----------- ls -lart | grep -in test -I match either upper or lowercase -n print the matched line and its line number  -----------   sort -r reverse order +x ignore first x fields when sorting  ----------- NAME[0]="1" NAME[1]="2" NAME[3]="3" echo ${NAME[0]} 1 echo ${NAME[*]} 1 2 3 echo ${NAME[@]} 1 2 3  -----------   val=`expr 2 + 2` echo $val 4 a=10 b=20 val=`expr $a + $b` echo $val 30 ===== cat test Some test here Hello how are you wc -l < test 2 cat test | wc -l 2 -=-=-=- /dev/null will redirect STDOUT to a BLACK HOLE By default: stdin  ==> fd 0 stdout ==> fd 1 stderr ==> fd 2 How to empty or clear the contents of an existing UNIX file cat /dev/null > blah.txt -=-=-=-=-=-=- last command