html'>linux basic commands:
ls
ls -a -- lists all files (hidden as well .)
ls -l -- list with permission and details
ln -s A B -- create soft link btw two file/folders
ps -- see current process
ps -e -- see background process as well
ps -H -- list process hierarchy
ps -f -- ?
pstree
top - see all proc's at one shot
pmap [PID] : list all the resource held by this proc.
cat /proc/[PID]/maps :
kill -3 [PID] -to get the status of threads
$ killall httpd -kill all the procs with name httpd
grep -- useful for search. Very powerful if we combine with other commands
eg: ps -ef | grep liferay == will return all the liferay process
fg -- bring the process to foreground
bg -- send the process to background
CTRL Z -- send the process to background..Can bring it to foreground using fg.
CTRL C -- close a program.
tail myfile.txt -n 100 -- list the last 100 lines in
the file
mail -s "picture of me surfing" sylvia@home.com < surfing.jpeg --- To mail a file
tail -f catalina.out --display the contents in real time
head -15 myfile.txt - Would display the first
fifteen lines of myfile.txt.
diff -r -N folder1/ folder2/ ---find difference b/n folders.. -N do display diff content.
cat test.txt --display content of file test.txt
cat t.txt t2.txt > t3.txt -- merge t.txt+t2.txt= t3.txt
difference b/n folder
du -hs liferay1/webapps/* liferay2/webapps/*
touch file.txt -- quickly create a empty file
VI editor commands
i -- insert mode
r -- replace mode
/ -- search
:%s/fred/joe/igc : general substitute command(replace)
w -- write
wq --write and quit
q-- quit
:#20 - moving to a line 20
Ctrl u --page up
Ctrl d -- page down
:set number -- to set the number
~ Toggle case of the character under the cursor, or all visually-selected characters.
q: You can bring up the command line history while in Normal mode.
:42G -- ways to go to a particular line (line 42 for example)
Multiple Files Management
vim test xyz
:bn -- next file
:bp -- next file
:wn -- write file and move to next (SUPER)
Screen
Ref: http://www.kuro5hin.org/story/2004/3/9/16838/14935
Screen is best described as a terminal multiplexer.
Using it, you can run any number of console-based
applications--interactive command shells,logging, curses-based
applications,
text editors, etc.--within a single terminal.Also can reattach again to
the screen even after logout.Excellent isn't it. Should have had a
separate blog :0). Any way the quick reference below:
$
screen --
Start screen just by typing screen at your favorite command shell prompt
Ctrl a c --create another screen
ctrl a ctrl A --switch screen
ctrl a n -- switch next screen
ctrl a p -- switch prev screen
ctrl a A -- Give a name to the current screen.
ctrl a " -- to get a full-screen list of windows
ctrl a K --You can also kill misbehaving programs
$screen -r --will reattach the screen to the current session which.
Networking commands:
ping
netstat -- active connections
netstat -r --shows routing table
ifconfig (like ipconfig in windows)
ifconfig eht0 down -- shutdown lan card (to renew ip u can do this)
ifconfig eht0 up --startup lan card
iptraf
nmap -- port sniff
dig
NATing
/etc/hosts file
It is used to map simple human readable names with ip address.
Eg:
127.0.0.1 localhost.localdomain localhost
127.0.0.1 access.idp1.com
Installation
rpm -i foo-v123.rpm ---install a package
rpm -i http://oss.oracle.com/kernel-2.4.20-18.10.1.i686.rpm
rpm -e foo
rpm -qi foo -- To query a RPM package and display info
more details refer http://www.idevelopment.info/data/Unix/Linux/LINUX_RPMCommands.shtml
Autoexec.bat in linux
vi /root/.bashrc # the user is root here.
---Do whatever needs to be done on login in the .bashrc
To load the properties without relogging in use : source /root/.bashrc
Secured remote copy:
scp <target1> <target2>
eg: scp test.zip sandeepm@xHost:/export/home/sandeep -- copies the test.zip to the target2 from target 1.
scp sandeepm@xHost:/export/home/sandeep/test22.zip . -- copies the test22.zip from target2 to target1 .
Use grep recursively
You can search recursively i.e. read all files under each directory for a string “192.168.1.5″
cd /etc
$ grep -R "192.168.1.5" *
Use grep to search words only
When you search for boo, grep will match fooboo, boo123, etc. You
can force grep to select only those lines containing matches that form
whole words i.e. match only boo word:
$ grep -w "boo" /path/to/file
Grep invert match
You can use -v option to print inverts the match; that is, it
matches only those lines that do not contain the given word. For
example print all line that do not contain the word bar:
$ grep -v bar /path/to/file
Count line when words has been matched
grep can report the number of times that the pattern has been matched for each file using -c (count) option:
$ grep -c 'word' /path/to/file
To get the DB conn list
$ netstat|grep -c app610
Shell script
The below will run a command for configurable no of times.
chmod +x test
usage : ./test [NO_TIMES] [COMMAND]
for (( i = 0 ; i < $1; i++ ))
do
echo "Executing $2";
$2;
sleep 1;
done
More scripts here http://www.usd.edu/~sweidner/lsst/
One of the best methods to capture a Unix terminal session is to use the `script` command.
In this example we start a script session, run a couple of commands,
and then use the `exit` command to stop capturing the terminal session:
$ script
Script started, output file is typescript
$ pwd
/home/will
$ ps
PID TT STAT TIME COMMAND
11909 p0 Ss 0:00.05 -bash (bash)
25622 p0 S+ 0:00.01 script
25623 p1 Ss 0:00.01 /usr/local/bin/bash -i
25624 p1 R+ 0:00.00 ps
$ exit
Ref:
http://vim.wikia.com/wiki/Best_Vim_Tips