Basic Command Line Tips
- 32bit or 64bit
- Works for every binary, not only java:
- file - < $(which java) # heavily bashic
- cat `which java` | file - # universal
- Cat all non-commented and non-empty lines from fileegrep -v '^(#|$)' filename
- Create list of ping-able hosts from list of hosts
- for i in `cat all`;do ping -c 2 $i 2>pinglog ; if [ $? != 0 ]; then echo "cant ping $i >> pinglog"; else echo $i >> pingfile; fi; done
AWK
- Remove all line breaks from file
- awk 'BEGIN{}{printf "%d, ", NR}END{printf "\n"}' filename
- Add up numbers in a file
- cat numberlist | awk '{total = total +$1}END{print total}'
Bash Prompt
- $ PS1="[\u@\h:\w ] $ "
- put in .bashrc if ya want /etc/skel
- Run 'unalias' to remove alias
- unalias cp
- Clear bash history
- history -c && rm -f ~/.bash_history
- Setup Shell for vi command editing
- set -o vi (place in .bashrc)
- Set Background Terminal Color
- set_color -b blue
- ksh file completion
- set EDITOR to vi then ESC \ will do file completion.
Check if Server is VM?
- dmidecode | grep -i product
Product Name: VMware Virtual Platform
CPU Tips
- Get number of CPU
- grep -i "physical id" /proc/cpuinfo | sort -u | wc -l
- dmidecode |grep -i cpu
Socket Designation: CPU1Socket Designation: CPU2Socket Designation: CPU3Socket Designation: CPU4CPU.Socket.1CPU.Socket.2CPU.Socket.3CPU.Socket.4 - Check if HyperThreading is enabled
- # of siblings = # of cores
- cat /proc/cpuinfo |egrep 'sibling|cores'
- grep -i "processor" /proc/cpuinfo | sort -u | wc -l
Cut Tips & Sort
- Cut with space as delimeter
- cut -d ' ' -f 1
- Sort list of IP Address
- Cat (or whatever cmd) iplist | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
- cut 1st field and show remaining 3
- hostname | cut -d . -f 2,3,4
- Sort Files by Size
- ls -lh | sort -n -k5,5
Disk Usage
- Check size of directory
- du -ch directory
Email Tips
- mail -s “Some Subject” you@youremail.com < /opt/app/app.log
For Loops
- Sequence Numberfor i in `seq 1 10`;do> echo $i
- Use Seq to go thru 1-5for i in {1..5};do> echo "host-X-$i"> done
Grep
- to stop after the first match.
- grep -m 1
LDAP
tcpdump -n tcp port ldap
IP Address
- ifconfig eth0 | grep inet |awk ' {print $2 }'| cut -d ':' -f2
Iozone Testing
- iozone -s 1g -r 1024 -i 0 -i 1 -e -t 1 -F f:\IOTest\t1 -b f:\iotest\t1-10.xls Test 1
- iozone -s 2g -r 1024 -i 0 -i 1 -e -t 1 -F f:\IOTest\t1 -b f:\iotest\test2.xls Test 2
- iozone -s 2g -r 2048 -i 0 -i 1 -e -t 1 -F f:\IOTest\t1 -b f:\iotest\test3.xls Test 3
- iozone -s 2g -r 2048 -i 0 -i 1 -e -t 2 -F f:\IOTest\t1 f:\iotest\t2 -b f:\iotest\test4.xls Test 4 Notes: 2 Threads
- iozone -s 2g -r 2048 -i 0 -i 1 -e -t 4 -F f:\IOTest\t1 f:\iotest\t2 f:\iotest\t3 f:\iotest\t4 -b f:\iotest\test5.xls Test 5 Notes: 4 Threads
- iozone -s 2g -r 4096 -i 0 -i 1 -e -t 4 -F f:\IOTest\t1 f:\iotest\t2 f:\iotest\t3 f:\iotest\t4 -b f:\iotest\test6.xls Test 6 Notes: 4 Threads
NIC Info
To invoke diagnostics from ethtool, enter this command: (will disrupt traffic)
- ethtool -t <EthX>
- ethtool -S eth0
NTP
- to sync, add ntp server to /etc/ntp.conf
- service ntpd stop
- ntpdate -u myntpserver.com
- date
- verify it synced
- restart with 'service ntpd start'
check with 'ntpq -p'
NMAP
Run nmap to view subnet IP's
- nmap -sP 10.48.24.0/22
PATHS
Add to the beginning of the $PATH environment variable, use the following:
- PATH=/data/myscripts:$PATH
To add that directory to the end of the path, use the following command:
- PATH=$PATH:/data/myscripts
Pause in a script
- read -p "Press [Enter] key to reboot"
Process
- Show extended info
- ps awwx
RPM & YUM
- Clean up rpm database
- rm -rf /var/lib/rpm/_db*
- rpm --rebuilddb -vv
- View dependencies
- Rpm -qR package
- Rpm -qipR rpmfile
Routes
Add default gateway (if router is ip below)
- # route add default gw 192.168.1.254 eth0
Rsync
- Rsync -auvP (src dir) (dest dir)
rsync -avz --exclude-from 'exclude-list.txt' source/ destination/
Screen
To launch screen, type screen and some commnads
- To disconnect (but leave the session running)
- Hit Ctrl + A and then Ctrl + D in immediate succession. You will see the message [detached]
- To reconnect to an already running session
- screen -r
- To reconnect to an existing session, or create a new one if none exists
- screen -D -r
- To list open screen windows
- Hit Ctrl + A and then W in immediate succession
Sudo
Check Syntax of sudoers
- visudo -c
Tar
To list contents
- tar -tvf file.tar
Tar exlude file/directory
- tar cvf --exclude
Top
- top, press shift ‘>’ and it will sort by memory used.
Users
Show all unique users who last logged in.
- last | awk '{ print $1 }' |sort |uniq
No comments:
Post a Comment