Linux Advance Command
Vi Replace
cw – Vi replace a single word from the current cursor position. To replace a whole word, you put the cursor on the the first character of the word.c$ – replace the current line but doesn’t extend to change the rest of a wrapped sentence on the screen
r – Vi Replace the character under the cursor
R – Replaced the text on the same line until Esc is pressed, but it doesn’t change text on the next line. Instead, it pushes to ahead of the current changes.
Vi Delete
x – Deletes a single character under the cursorX – Deletes a single character before the cursor
dw – Deletes a single word that’s currently under the cursor, from the cursor position onward.
Vi Delete Line
dd – Vi delete line, regardless of the cursors position on the lineD – Deletes all text from the cursor position to the end of the line
dL – Deletes all text from the cursor position to the end of the screen
dG – Deletes all text from the cursor to the EOF
d^ – Deletes all text from the beginning of the line to the cursor
Vi Copy & Paste
Commands for Vi copy & paste:yy – Vi copy line – copies a line of text to the unnamed buffer
3yy – Copies 3 lines of text to the unnamed buffer
yw – Copies a word (under the cursor) to the unnamed buffer
3yw – Copies 3 words to the unnamed buffer
P – Pastes the contents 0f the unnamed buffer to the right of the cursor
p – Pastes the contents of the unnamed buffer to the left of the cursor
Vi Page Down
Ctrl+F – Vi page down – Moves forward a pageCtrl+D – Moves forward half a page
Vi Page Up
Ctrl+B – Vi page up – Moves back a pageCtrl+U – Moves backward a half-page
Vi Save & Exit
:q – Vi exit – this will close Vi:wq – Vi save & exit
:w – Vi Save, write the file out to disk
: x – Vi exit, and prompts it you want to save on exit.
Shift+ZZ - Alternative way to save and exit Vi
:q! – Exits vi and discards and changes you made
:wq! – Vi Save and exit if you are root and do not have the write bit set for the file you are attempting to write.
# visudo
root ALL = (ALL) ALL
jons ALL = (ALL) ALL
shutdown command
#init 0
#halt
#shutdown –h now
#power0ff
#shutdown -r 30
well be shutdown after 30minit
Reboot Command
#reboot
#shutdown –r
#init 6
VIM Editor
# :s/string1/string2/g
replace all string1 to string2 All line in text file.
#
:s/string1/string2/gc
replace all string1 to string2 All line in text file. show
line and word
# :set nu
Enable the line number
# :set nonu
Disable the line number
#cat a.txt > b.txt
#touch a.txt
for mack a new file.
#vim a.txt
for mack a new file
#wc –w a.txt
how mane line in the text file
#head –n 1 a.txt
show the fist line in the text file
#cat –n a.txt
show the line number in the text file
RPM Command
#rpm –qa | wc –l
how to pakage install in the system
#rpm –qa nano
when the nano package
install in the system
#rpm –qc sandmail
show the where sendmail Configuration file
# rpm –qd sandmail
show the sandmail document file.
#rpm –ivh <pakag name>
for rpm pakage install
# rpm –ivh --forch <pakag name>
for rpm pakage forch install
#rpm –ivh –nodeps <pakage name >
for install rpm pakage without dependence file.
1.
nstall a local RPM:
rpm -ivh /path/to/my.rpm or: rpm -Uvh /path/to/my.rpm
2.
Remove a locally installed RPM:
rpm -e /path/to/my.rpm
3.
Upgrade/Update a locally installed RPM:
rpm -Uvh /path/to/my.rpm
4.
Find out what package a particular file belongs to:
rpm -qf /usr/bin/ssh
5.
Find useful information about a package:
rpm -qi openssh
6.
Find out when a package was installed:
rpm -q openssh --last
7.
List the dependencies of a package:
rpm -qR openssh
8.
List all gpg keys known by RPM on the system:
rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n'
9.
Install an RPM from a website or anonymous FTP server:
rpm -ivh http://www.somewebsite.com/package.rpm
rpm -ivh ftp://ftp.somewebsite.com/package.rpm
10.
Repair and rebuild a corrupted RPM database:
rm -f /var/lib/rpm/__db* && rpm -vv --rebuilddb
11.
Find out what locations the files from a specific RPM were
installed to:
rpm -ql openssh
12.
Make a text file of all the packages currently installed on the
system sorted alphabetically:
rpm -qa | sort -d | uniq > all_packages.txt
samba-
2.0- 2.0.0-3.i386. rpm
name
version relese pakage name
Directory
#cd ~
for go home directory
#cd ..
back one directory
#cd /
for go root directory
# last
login history all user
#last root
jest info about root user
#uptime
show the system uptime
#cat /proc/cpuinfo
for information on cpu
#free –t
system all information
#vmstat -s
show the virtual memory
#w
current all login user
#ps –A
Display the processes list
Change the time zone at system
#timeconfig
#rout or netstat –r
show all of the routing tables
#tracerout google.com
for trace the google site
#history
Show the before commands
#history –c
Remove the before command
#du –sh
Show the directory size
#top
Monitoring command
Network Command
#ss –s
Display sockets summary
#ss –l
Display all open network port
#ss –t –a
Display tcp sockets
#ss –u –a
Display udp sockets
#ip –a
For about ip
#ip route
Show the getaway
#wall
Send massage in sash
Firewall Configuration
Iptables –l INPUT -i
eth0 –s 192.168.2.4 –j DROP drop ip address
Iptables –l INPUT –s 192.168.2.0/24 –j DROP
Iptables –l
INPUT -p tcp - -dport 80 –j DROP
Iptables –l INPUT -i
eth0 -p tcp –dport 80 –j DROP
Iptables –l INPUT -p
tcp –s 192.168.2.2 - - dport 80 –j DROP
User Account
#adduser jons
for add user
#passwd jons
for password on user
#passwd –l jons
lock account
#passwd –u jons
unlock account
#awk –F:’($==””){print}’/etc/shadow
verify account for empty password
#failog –r –u jons
for remote server a file upload
#scp –r /var/ root@hostname:/root/ssl
Viewing
live Bandwidth
#yum install iftop
#iftop –I eth0 –B
#iftop –I eth0 –n
#iftop –I eth0 –p –n
folder permission
#chmod –R 777 *.*
#chmod –R 776 /var/www/html/
all folder or file in directory permission 776
#chown –R user:group /var/www/html/
0 = no permission
1 = X Execute only
2 = W Write only
3 = R Read only
# well
Send massage in ssh in command terminal
#lsof
for All port chack
#lsof –I tcp:80
for 80 port chack
#cksum jonsxm
for jonsxm file show size
#echo ‘wget url’ | at 1:00
if 1:00
time download the file then
#wget –limit-rate=20k url
if 20kbps speed to download the file
#wget –c url
#wget –r www.google.com
for full site download
#time cat
start stopwatch (ctrl+d to stop stopwatch)
#du –sch /var /home
home and var how many size between two folder
#du –sh –exclude=’*.iso’ /home
all .iso file size in the home folder
#find / -name filename
search of total root folder
#locate filename
search of total root folder
#find / cmin -5
find all file created or update in the five minit
ls -l files and directories
show current folder
ls -la show file with (.) files
ls -ls show files with size
ls -ln show list numeric user/group
ids instead of name
ls -c show files listing
columns
ls --color
=always show files types as different
colors
Play Song
#play song.wav
play song
#play *.wav
play all song
#mpg321 song.mp3
ISO CD Burn
#cdrecode -v
windows.iso
for burn cd
# cdrecode -v
speed=24 windows.iso
# cdrecode -v –eject
windows.iso
enject cd drive when burn in done
#restorecon –Rv /var/www/html
restore the Default
security
#mtr www.google.com
no stop traceroute
#host www.google.com
remote server know for hostname & IP
#yum chack –update
chack for update list
#yum update
for update all package
#tar –xvf file.tar
for unzip
#tar –cvf
file.tar foldername
for tar
#ifup eth0
network card disable
#ifdown eth0
network card enable
#groupdel groupname
delet groupname
#gpasswd -a
username groupname
under user on groupname
#userdel -r username
delete username
#cat /set/group
show group
#chfn -f newname oldname
for change username
#df –l
harddisk information
#rmdir foldername
#rm –r foldername
delete folder
To create a tar.gz archive from a given folder
you can use the following command
#tar -zcvf tar-archive-name.tar.gz
source-folder-name
To extract a tar.gz compressed archive you can
use the following command
#tar -zxvf tar-archive-name.tar.gz
How to
Disable SSL?
sudo a2dismod ssl
sudo a2dissite default-ssl
sudo service apache2 restart
sudo a2dissite default-ssl
sudo service apache2 restart
Network Masks
Short Form
|
Full Form
|
No. Machines
|
Comment
|
/8
|
255.0.0.0
|
16,777,215
|
Used to be called an `A-class'
|
/16
|
255.255.0.0
|
65,535
|
Used to be called an `B-class'
|
/17
|
255.255.128.0
|
32,767
|
|
/18
|
255.255.192.0
|
16,383
|
|
/19
|
255.255.224.0
|
8,191
|
|
/20
|
255.255.240.0
|
4,095
|
|
/21
|
255.255.248.0
|
2,047
|
|
/22
|
255.255.252.0
|
1,023
|
|
/23
|
255.255.254.0
|
511
|
|
/24
|
255.255.255.0
|
255
|
Used to be called a `C-class'
|
/25
|
255.255.255.128
|
127
|
|
/26
|
255.255.255.192
|
63
|
|
/27
|
255.255.255.224
|
31
|
|
/28
|
255.255.255.240
|
15
|
|
/29
|
255.255.255.248
|
7
|
|
/30
|
255.255.255.252
|
3
|
|
#hostame - Displays the hostname and/or FQDN of the system
#uname -a - Displays the hostname and
detailed kernel version
#cat /etc/redhat-release - Displays the
version of Linux installed Example:
#cat /proc/cpuinfo - Displays
information about the CPU(s)
#df -h - Displays the partitions, their
sizes details, and mount points
#free - Displays detail about the system
memory and usage
#lsof - Displays all open files
#lsof -nPi:22
- Displays any open files which use port 22
#locate httpd.conf
- Displays the full path to any file named httpd.conf
#updatedb - Rebuilds index of files for
search using the locate utility
Copy,
Move, Delete
#cp file1.txt
file2.txt - Copies file1.txt to file2.txt
#mv old.txt
new.txt - Renames a file called old.txt to new.txt
#rm file1.txt -
Deletes file1.txt
#mkdir httpds
- Creates a new directory called httpds
#cp -R httpd
httpds - Recursively copies all files from directory httpd to httpds
#cp -PR httpd
httpds - Recursively copies all files from directory httpd to httpds
and retains all permission settings
#rm -rf httpd
- Recursively deletes folder httpd and all contents
#chkconfig --level 35
httpd on - Sets httpd to start on
runlevels 35 when machine is booted
#service httpd start - Immediately starts Apache
File
Attributes
#chown apache virtualhosts.txt
- Changes ownership of the virtualhosts.txt file to user apache
#chgrp apache virtualhosts.txt
- Changes membership of the virtualhosts.txt file to group apache
#chmod a+x sniffer.pl
- Allows the sniffer.pl file to be executed
CHMOD
7 rwx read, write, execute
6 rw- read, write
5 r-x read, execute
4 r-- read
3 -wx write, execute
2 -w- write
1 --x execute
0 --- no permissions
#chmod 777 passwords.txt
- Allows read, write, and execute on the file passwords.txt to anyone
#chmod 000 passwords.txt
- Blocks read, write, and execute on the file passwords.txt to anyone
Yum
#yum update -y - Updates all packages without prompting
#yum install iptraf
- Installs a package named iptraf
#yum whatprovides */iostat - Searches
all repositories and returns RPMs that provide the program iostat
#yum update samba
- updates a package named samba
RPM
#rpm -q http
- Displays the version of daemon http (apache)
#rpm -qa | grep bind
- Displays all packages installed with the word bind. Example:
#rpm -qa | grep bind
bind-chroot-9.3.6-16.P1.el5
system-config-bind-4.0.3-4.el5.centos
bind-utils-9.3.6-16.P1.el5
bind-9.3.6-16.P1.el5
bind-libs-9.3.6-16.P1.el5
ypbind-1.19-12.el5
#rpm -ivh proftpd
- Interactively installs proftpd
#rpm -Uvh proftpd
- Interactive upgrades named proftpd
#rpm -e proftpd
- Removes package proftpd
#rpm --rebuilddb - Rebuilds a corrupt
RPM database
Compressed
files
#unzip package.zip
- Unzips the file package.zip
#tar -zvxf stunnel.tar.gz
- Decompressed a gzip file named stunnel.tar.gz
Networking
#ifup eth0
- Enables network interface eth0
#ifdown eth0
- Disables network interface eth0
#vi /etc/sysconfig/network-scripts/ifcfg-eth0
- Uses vi to edit network settings on eth0
IP
tables
#service
iptables status -
Displays status of iptables (running or not)
#iptables -L - Displays ruleset of
iptables
#iptables -I INPUT -p tcp -m tcp -s 192.168.15.254/26 --dport 22 -j ACCEPT -
Accepts incoming SSH connections from IP range 192.168.15.254/26
#iptables -I INPUT -p tcp -m tcp -s 0.0.0.0/0 --dport 22 -j DROP -
Blocks SSH connections from everywhere else
#iptables -I INPUT -s "192.168.10.121"
-j DROP - Drops all traffic from IP 192.168.10.121
#iptables -D INPUT -s "192.168.10.121"
-j DROP - Removes previously allied drop all from IP 192.168.10.121
#iptables -I INPUT -s "192.168.10.0/24"
-j DROP - Drops all traffic from IP range 192.168.10.0/24
#iptables -A INPUT -p tcp --dport 25 -j DROP -
Blocks all traffic to TCP port 25
#iptables -A INPUT -p tcp --dport 25 -j ACCEPT -
Allows all traffic to TCP port 25
#iptables -A INPUT -p udp --dport 53 -j DROP -
Blocks all traffic to UDP port 53
#/etc/init.d/iptables save - Saves all
IPtables rules and re-applies them after a reboot
Processes
#ps ax - Displays all
running processes
#ps aux - Displays all running processes including CPU and memory usage
of each
#ps ax | wc -l - Displays the total number of processes
#top - Interactive process manager which allows sorting by criteria
Logs
#tail
-f /var/log/messages - Displays the most
current entries to the messages log in real-time
#tail -50 /var/log/messages - Displays the last 50 lines of the messages
log
#head -50 /var/log/messages - Displays the first 50 lines of the
messages log
#cat /var/log/messages - Displays the entire messages log
#cat /var/log/messages | grep "FTP session opened" - Displays
any entries in the messages log that contain the ext FTP session opened
#cat /var/log/messages | grep "FTP session opened" > log2.txt
- Writes any entries in the messages log that contain the ext FTP session
opened to a file named log2.txt
Paths to Common Files
Bind (named)
/var/named -
Bind zone files (non chrooted)
/etc/named.conf - Bind configuration file (non chrooted)
/var/named/chroot/var/named - Bind zone files (chrooted)
/var/named/chroot/etc/named.conf - Bind configuration file (chrooted)
Apache (httpd)
/etc/httpd/conf/httpd.conf -
Main apache configuration file
/var/www/html - Default directory for serving pages
/var/log/httpd/ - Default location for logs (access and error)
Networking
/etc/hosts - System hosts file
/etc/resolv.conf - DNS lookup configuration file
/etc/sysconfig/network - Network/hostname configuration file
/etc/selinux - SELinux configuration file
/etc/sysconfig/network-scripts/ - Default location of a network setting
file
/etc/sysconfig/iptables - Default iptables policy configuration file
/etc/sysconfig/iptables-config
- Default iptables daemon configuration file
0 comments:
Post a Comment