Table of Contents

Random commands from

linux

strings
fsview (file tree view)
xwin32 (xclient for windows)
cygwin (runs linux software on windows machine)
Vmware (virtual computer on computer)
which ping (which version/location the command runs)
find ... 2> /dev/nell ("2> /dev/null" redirects stderr to bit bucket)
fgets, fput are system level commands used by databases file reads.
stat will give file information

(this is the administration tool for the apple disk array)

/root/apple_xserver_raid/  
  #RAID_Admin
du disk usage
df disk free
fsview -- visual disk usage, won't run as root on alexandria stuff. 

It would be easier to hack up a copy of the /home/sysadmin/bin/makehomes.sh (I might have a few characters wrong in that filename) to run du -sk on everyone's home directory, then glob the output into a sort -nrd command.

/proc/cpuinfo

/proc/scsi/scsi
parted
  print
LVM
  LVS

jabber im.iad.vt.edu gaim->jabber
lspci 

vim -R
:!cat /proc/uptime |cut -d'.'-f1
/etc/init.d/nfs reload

Locate module

rsync -aztv

Backup and restore, one one machine, without an intermediate file:

(cd /home/lscharf ; tar -cf - . ) | ( cd /home/stedwar1/lukebackup ; tar -xvf - ) 

Network backup:

(cd /foo/bar1 ; tar -cvf - . ) | ssh user@remotehost 'cat > /foo/bar2/mybackup.tar.gz'

Network backup and restore:

(cd /foo/bar1 ; tar -cf - . ) | ssh user@remotehost 'cd /foo/bar2 ; tar -xvf - '
rsync /foo/bar1/ user@remotehost:/foo/bar2

Edit this file and eth0 to change network configuration

/etc/sysconfig//etc/sysconfig/network-scripts/ifcfg-eth0
aoe.mysql.inc.php
jobs
lsof
\\aoe.vt.edu\NETLOGON

cc -lm  compile using math library.
CC  C++ compiler

last (reports last users logged in.)

cat /etc/redhat-release
Scientific Linux SL release 4.4 (Beryllium)

dd if=/dev/hda | gzip > outputfile.img.gz
dd if=/dev/hdX bs=$[ 1024 ** 2 ] | bzip2 > whatever.img.bz2

http://wiki.linuxquestions.org/wiki/Dd

fdisk -l

sudo /usr/sbin/apachectl start
# service mysqld start
netstat -rn
netstat -ap
netstat -ar ( forrouting table)
tcpdump -vvv -i eth0 -w results.tcpdump ip6
chkconfig --list |grep ':on'
https://sourceforge.net/projects/webcalendar/
FSSTND
# dumpe2fs /dev/sdb3 | grep -i 'Block size'
$ dd conv=noerror if=/dev/hdc of=winR2006b-1.iso
mount -o loop -t iso9660 filename.iso /mnt/iso
lsof (list open files.)
source .cshrc
cdwg/vtengineering michael(?) mcdonald@cdwg.com(?)
/sbin/lspci
modprobe.conf
system-config-soundcard (automatic soundcard detection)

For windows machines to test directX:

dxdiag

Disconnected jobs:

nohup
screen
nohup /path/to/your/program > output.txt 2>&1 &
zterm
man 5 nfs
man rpc.nfsd
or man nfsd

Drive fill:

dd if=/dev/zero of=/dev/hda bs=1M
dd if=/dev/zero of=/dev/rdsk/cXtYdZ bs=64k followed by
tr '\000' '\377' < /dev/zero | dd bs=64k of=/dev/rdsk/cXtYdZ

Repeat the above as many times as you like. The first will write all 0's the latter will write all 1's.

http://forums13.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F1%2C%2C0x24b53a7b3682d611abdb0090277a778c%2C00.html&admit=109447627+1294289352159+28353475

http://forums13.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1294289174862+28353475&threadId=136569


To get a progress report:

ps aux |grep sdb (or something that identifies the dd)
kill -USR1 <pid>

or

dd if=/dev/urandom of=/dev/sdb bs=1M & pid=$!
kill -USR1 $pid ; sleep 1

From the sans GCFA listserv:

FWIW Here's my hero one-liner for dd with progress via pipebench and auto md5sum

##dd imaging with progress, auto md5sum
dd if=/dev/sda | pipebench | tee sda.dd | md5sum > sda.md5.txt

—- grep DenyHosts imap email folder for raw email addresses

grep -i "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" mail/DenyHosts |sort -n | uniq > DeniedHosts

generate md5 password hash:

echo -n password |md5sum

Change permissions for files and folders:

find STK8.1/ -type f -exec chmod o+r {} \;
find STK8.1/ -type d -exec chmod o+rx {} \;

block broadcast pings

echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

—-

block spam

move email from IMAP folder to a new local folder named aa in thunderbird.

From hephaistos (or local machine used to check email.)

grep 'Received: from' aa|cut -s -d [ -f 2|cut -d ] -f 1|sort -n|uniq|grep -v ^127|sed s/^/'ALL: '/g|ssh root@courier.aoe.vt.edu 'cat >>/etc/hosts.deny'
grep 'Received: from' aa|cut -s -d [ -f 2|cut -d ] -f 1|sort -n|uniq|grep -v ^127|sed s/$/'    REJECT'/g|ssh root@courier.aoe.vt.edu 'cat >>/etc/mail/access'

On courier,

makemap hash /etc/mail/access < /etc/mail/access

remove any duplicates

Check for any campus addresses

Create CD file list archive

http://www.freesoftwaremagazine.com/columns/indexing_offline_cd_rom_archives

find /cdrom > TCD2001-001.files
tree -d /cdrom > TCD2001-001.tree
find /cdrom -name "*.tgz"                  \
  -exec echo "ARCHIVE {}" \;             \
  -exec tar tf {} \; >> TCD2001-001.arch

“In case you’re not already familiar with them: the backslash characters (\), are there to “escape” the carriage return so that the first three lines above appear as one single line to the shell.”

arp ping

arping <ipaddress or name>

remove CR/LF

cat file | tr '\012' ' '; echo > new_file

System Information

http://alinuxblog.wordpress.com/2008/08/18/how-to-get-system-info-in-linux/

Most of this commands can be run as non-privileged user, but more information can be obtained if (and should be) run as root.:

linux_inside

General system information:

# uname -a

Process information:

# top

(Shift-M to order the list by memory use) Memory information:

# free -m

BIOS information:

# dmidecode | less

Distro information:

Ubuntu:

# lsb_release -a

Redhat/Mandriva/Fedora:

# cat /etc/osname_version

Devices:

# lspci -tv
# lsusb
# lshw

Partitions:

# fdisk -l

Memory usage:

# free -m

Mounted filesystem:

# df -hT

Disk usage:

# du / -bh | more

Disk performance:

# hdparm -t /dev/hda

IP adress:

# ifconfig -a

Ethernet adapter:

# ethtool -i eth0

The /proc directory (cpuinfo, devices, filesystems, meminfo, partitions, uptime, etc.)

E.g.:

# cat /proc/cpuinfo
# cat /proc/version
# cat /proc/swaps

network statistics

http://searchenterpriselinux.techtarget.com/tip/0,289483,sid39_gci1307722,00.html

hardware
ip -s -s link
ipconfig eth0
ethtool eth0
yum install sysstat
service sysstat start (this may not be required.)
(Wait 10 minutes.)
sar -n FULL
iptraf
netstat -tulp

wgetscript

cat wgetscript

#!/bin/bash
# Usage: ./wgetscript <file with list of links>
stuff=`grep -v \# $1`
echo "wgetting..."
for filetoget in $stuff
  do
    echo file $filetoget
    wget $filetoget
    echo
  done

service tag

http://www.debianadmin.com/how-to-obtain-the-dellhp-may-be-other-vendors-service-tag-in-debian.html

To Find the service tag use the following command

# dmidecode -s chassis-serial-number

you will get your service tag printed on screen.

To Find the model number use the following command

# dmidecode -s system-product-name

PowerEdge 2970

And if you sadly have the pain of managing a few windows hosts too, the same can be retreived with:

wmic bios get serialnumber

Or thinks like (for more informations):

wmic csproduct get vendor,name,identifyingnumber,serialnumber

webcam

http://tech.shantanugoel.com/2008/05/12/fun-with-webcam-in-linux.html

Did you know that instead of installing special software to view your webcam video, you can simply use mplayer for the same purpose, and with a lot of fine control. e.g. try running the following command with your webcam attached to your computer.

mplayer -fps 15 tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0

And you can use mencoder to capture and encode video from your webcam:

mencoder tv:// -tv driver=v4l2:width=60:height=40:fps=60:device=/dev/video0 -nosound -ovc lavc -lavcopts vcodec=mjpeg -o test.avi

Have fun playing with the huge number of options available. You could even cat the test.avi file into a folder of your web server and have instant streaming video :-) .

mplayer

Save real player file:

mplayer -noframedrop -dumpfile T-S_Waves_and_Beyond_300k.mov -dumpstream rtsp://iddl.vt.edu/aoe4064/T-S_Waves_and_Beyond_40k.mov

record desktop

http://www.junauza.com/2009/05/10-unknown-but-useful-linux-terminal.html

5. Record or capture a video of your desktop:

ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg

http://www.dralnux.com/2008/10/30/linux-tip-of-the-day-look-for-a-string/

grep “hello world” `find ./ -name “*” -print -exec file {} \; | grep text | cut -d ‘:’ -f 1`

bash

http://www.linux-mag.com/id/7171 Equivalent operations

echo {1,2,3,4,54,6,7,8,9}
echo {1..9}

An obvious way to make a series of directories is with a loop in the shell (or other scripting language). Build the directory names in one or a set of variables. For instance, to make directories named foo1 through foo9, bar1 through bar9, and so on, try the nested for loops below. (You can type these directly at a shell prompt, by the way; you don’t need to make a script file. And indentation isn’t required.)

for name in foo bar baz ...
do
  for num in 1 2 3 4 5 6 7 8 9
  do
    mkdir "$name$num"
  done
done

or

mkdir {foo,bar,baz}{1,2,3,4,5,6,7,8,9}

Date time zone

The “date” command is enought :) If you give any date with any time zone to “date” you get your local time :

date -d '2008-11-07 09:00 CST'
     
Fri Nov  7 16:00:00 CET 2008

– Best regards, Robert FRANCHISSEUR

system information

http://www.linuxjournal.com/content/interrogating-linux-machine

486  route -n
487  cat /proc/kcore 
488  ls -lah /proc/kcore
489  lspci
490  cat /proc/cpuinfo 
491  ifconfig -a
492  cat /proc/interrupts 
494  fdisk -l /dev/?d?*
495  cat /proc/filesystems 
496  cp /proc/config.gz config.gz
497  lsmod
498  lsusb
499  rpm -qa
500  dpkg -l
501  emerge --pretend --emptytree world

from the user comments:

lshw
cat /proc/meminfo
sysinfo (Suse)
dmidecode
uname -a
free
sosreport (Fedora)

another nice tool….is CFG2HTML, which can be found at http://www.cfg2html.com/

Open-AudIT It should give you everything you need for inventorying Windows and Linux machines http://www.open-audit.org

compare directories

http://linuxtoday.com/news_story.php3?ltsn=2009-02-18-004-35-OS-SW To compare two directories

$ diff -r --brief dir1 dir2

To copy the content of dir1 into dir2 without copying the files that are already exist and are the same, use rsync(faster, flexible replacement for rcp):

$ rsync -a dir1/ dir2/

Tip: Simple Regular Expressions For Reviewing Log Files

Tip: Simple Regular Expressions For Reviewing Log Files

Find examples

find files with other write permissions

find . -perm +o=w

change file permissions

find -type f -exec chmod 644 {} \; converts file permissions
find -type d -exec chmod 755 {} \; converts directory permissions

find files owned by apache

find / /var /tmp  -xdev -user apache

Basically, looking for files that are owned by apache that are located anywhere outside of /www (since www is on another partition) -xdev means “don't go into a mount”

fun

http://www.quicktweaks.com/2009/11/26/10-linux-commands-for-fun/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+quicktweaks%2FmyFe+(Quick+Tweaks) #1 Browse and display images in Terminal

Browse and display images in Terminal? Yes! To browse the images in the current directory:

$ sudo zgv

To browse the images in /home/username/pictures directory:

$ sudo zgv /home/username/pictures

Note: If you get any mouse not initialized message, just unplug your mouse, type zgv and plug your mouse back

#2 Burn a CD/DVD/BluRay Disk

Let’s add a small twist; make an ISO image of a large folder and burn them to a CD/DVD. Crate an ISO image (myISOFile) out of a folder (or filename)

$ mkisofs –r –o myISOFile.ISO folderOrFilename

Now burn the above ISO image to a CD/DVD

$ cdrecord --device=cdwriter-device -tao -eject myISOFile.ISO

#3 Create ASCII text graphics

$ figlet Linux

This is displayed with the default font, to use other fonts, give a font name after switch f:

$ figlet quick tweaks –f script
$ figlet Quick Tweaks –f script

The fonts for figlet are installed in /usr/share/figlet directory

#4 Run remote applications in full GUI mode

As a Computer Science student, I often need access my lab computers (which have Fedora installed) through SSH. After I submit my assignments, esp. those GUI based programming assignments, I wanted to check if everything is fine. Accessing remote computer is easy:

$ ssh username@example.com

If you want to run remote applications such as OpenOffice or Eclipse, just uncomment ForwardX11 yes in /etc/ssh/ssh_config file. After that if you type, eclipse, for an example, the remote application will run in full GUI mode.

#5 Split a large file into several pieces (for easy copy)

If you have a large file of about 1 GB size and have two CDs to spare (or two thumb drives of 512 MB each), how can you carry that 1GB file?

$ split –b500m myBigFile mySmallFIles.

To join the smaller files to get the big files back:

$ cat mySmallFiles.* > myBigFile

#6 Take screenshot of a rectangular area and save it as png file My Screenshot

Screenshot taken with import command

$ import –frame myScreenShot.png

After this command, the mouse pointer changes to a set of cross-hairs; left-click and drag the mouse across an area of the screen and release the mouse to capture the selected area.

#7 Resize an image, put a border around it, and add a comment

$mogrify -geometry 300x200 -border 8x8 -comment “Windows Sucks” myScreenShot.png

#8 Quickly converting a .wav file to a .mp3 file

$ lame myMusicFile.wav myMusicFile.mp3

#9 Display a nicely formatted calendar (or doing some quick maths?)

$ cal 1972

Get the factorial of 10

$ calc 10!

#10 Mirror a website to your computer for offline browsing

$ wget -mk http://example.com

Commandlinefu one liners explained

http://www.catonmat.net/series/commandlinefu-one-liners-explained

#1. Run the last command as root

$ sudo !!

#2. Serve the current directory at http://localhost:8000/

$ python -m SimpleHTTPServer

#3. Save a file you edited in vim without the needed permissions

:w !sudo tee %

#4. Change to the previous working directory

$ cd -

#5. Run the previous shell command but replace string “foo” with “bar”

$ ^foo^bar^

#6. Quickly backup or copy a file

$ cp filename{,.bak}

#7. mtr - traceroute and ping combined

$ mtr google.com

#8. Find the last command that begins with “whatever,” but avoid running it

$ !whatever:p

#9. Copy your public-key to remote-machine for public-key authentication

$ ssh-copy-id remote-machine

#10. Capture video of a linux desktop

$ ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg

#11. Edit the command you typed in your favorite editor

$ command <CTRL-x CTRL-e>

#12. Empty a file or create a new file

$ > file.txt

#13. Create a tunnel from localhost:2001 to somemachine:80

$ ssh -N -L2001:localhost:80 somemachine

#14. Reset terminal

$ reset

This command resets the terminal. You know, when you have accidentally output binary data to the console, it becomes messed up. The reset command usually cleans it up. It does that by sending a bunch of special byte sequences to the terminal. The terminal interprets them as special commands and executes them.

#15. Tweet from the shell

$ curl -u user:pass -d status='Tweeting from the shell' http://twitter.com/statuses/update.xml

#16. Execute a command at midnight

$ echo cmd | at midnight

#17. Output your microphone to other computer's speaker

$ dd if=/dev/dsp | ssh username@host dd of=/dev/dsp

#18. Create and mount a temporary RAM partition

# mount -t tmpfs -o size=1024m tmpfs /mnt 

#19. Compare a remote file with a local file

$ ssh user@host cat /path/to/remotefile | diff /path/to/localfile -

#20. Find out which programs listen on which TCP ports

# netstat -tlnp

#21. Display currently mounted file systems nicely

$ mount | column -t
$ (echo "DEVICE - PATH - TYPE FLAGS" && mount) | column -t
$ (echo "DEVICE PATH TYPE FLAGS" && mount | awk '$2=$4="";1') | column -t
$ nicemount() { (echo "DEVICE PATH TYPE FLAGS" && mount | awk '$2=$4="";1') | column -t; }
$ nicemount

#22. Run the previous shell command but replace every “foo” with “bar”

$ !!:gs/foo/bar

I explained this type of one-liners in one-liner #5 already. Please take a look for a longer discussion.

To summarize, what happens here is that the !! recalls the previous executed shell command and :gs/foo/bar substitutes (the :s flag) all (the g flag) occurrences of foo with bar. The !! construct is called an event designator. #23. Top for files

$ watch -d -n 1 'df; ls -FlAt /path'
$ watch -dn1 'df -h; ls -FlAt /path'

#24. Mount a remote folder through SSH

$ sshfs name@server:/path/to/folder /path/to/mount/point

#25. Read Wikipedia via DNS

$ dig +short txt <keyword>.wp.dg.cx

This is probably the most interesting one-liner today. David Leadbeater created a DNS server, which when queried the TXT record type, returns a short plain-text version of a Wikipedia article. Here is his presentation on he did it.

Here is an example, let's find out what “hacker” means:

$ dig +short txt hacker.wp.dg.cx

#26. Download a website recursively with wget

$ wget --random-wait -r -p -e robots=off -U Mozilla www.example.com

#27. Copy the arguments of the most recent command

ALT + . (or ESC + .)

#28. Execute a command without saving it in the history

$ <space>command

#29. Show the size of all sub folders in the current directory

$ du -h --max-depth=1

#30. Display the top ten running processes sorted by memory usage

$ ps aux | sort -nk +4 | tail

Bonus one-liner: Start an SMTP server

python -m smtpd -n -c DebuggingServer localhost:1025

Bash Shell: Trim Leading White Space From Input Variables

http://www.cyberciti.biz/faq/linux-unix-shell-trim-leading-white-space/

There are many ways to remove leading white space from input variables. The simplest one use the read command as follows:

var="    output.txt"
echo "|$var|"

Sample outputs:

|    output.txt|

Use the read command to get rid of white space:

read  -rd '' var <<< "$var"
echo "|$var|"

Sample outputs:

|output.txt|

You can also use extglob shell option (Bash v2.2+) to turn on or off the extended pattern matching features.

var="         output.txt"
shopt -q -s extglob
echo "|${var##+([[:space:]])}|"
shopt -q -u extglob

You can store result to var itself:

var="${var##+([[:space:]])}"
echo "|${var}|"

You can also use sed (see Here strings):

var="      output.txt"
var=$(sed -e 's/^[[:space:]]*//' <<<"$var")
echo "|${var}|"

HEAR strings

wc -w <<< "This is a test."

grepping into a shell variable

var="Neither in this world nor elsewhere is there any happiness in store for him who always doubts."
grep "nor" $var

fails

grep "nor" <<<$var >/dev/null && echo "Found" || echo "Not found"

works!

What just happened?

<<<

“pipes” the variable $var to

grep "nor"

The output is a line of text (exit code returns 0) if found or nothing (exit code returns 1). The result is piped to the bit bucket but the error code is evaluated with &&.

echo $?

can be used to evaluate the exit value.

twitter

http://lightlinux.blogspot.com/2009/06/twitter-updates-from-linux-cli.html

#!/bin/bash
echo "Twitter update: $1"
curl -u "username:password" -d "status=$1" http://www.twitter.com/statuses/update.xml >/dev/null

Vendor:Device ID Pairing

ajb@elrepo.org

To be able to make any suggestions, it really is necessary to see the Vendor:Device ID Pairing (the “fingerprint”) for those cards. With them both in situ, please execute this “one-liner” and then post the output it produces –

for BUSID in $(/sbin/lspci | awk '{ IGNORECASE=1 } /net/ { print $1 }'); do /sbin/lspci -s $BUSID -m; /sbin/lspci -s $BUSID -n; done

watch for bad logins on alexandria

watch -n 30 'grep -e NT_STATUS_WRONG_PASSWORD -e NT_STATUS_ACCOUNT_LOCKED_OUT /var/log/messages | tail -30'

tcpdump on alexandria

tcpdump -nnp -s0 -X -vv host not 128.173.188.50 and port not 2049 and port not 445 and not arp and not port 137 and not port 138 and not port 514

http://www.shell-tips.com/2008/01/14/printing-a-sequence-of-letters-or-numbers/ Some times, while scripting in your favorite shell (I mean Bash !! :) you need to print a sequence of letters or numbers. Don’t write it yourself ! Script it using seq or curly braces !

Print a sequence of number view source print? 1 nicolas@macvin:~$ seq 1 10 2 1 2 3 4 5 6 7 8 9 10 3 nicolas@macvin:~$ seq 0 2 10 4 0 2 4 6 8 10 5 nicolas@macvin:~$ echo {1..10} 6 1 2 3 4 5 6 7 8 9 10

Print a sequence of letters view source print? 1 nicolas@macvin:~$ echo {a..g} 2 a b c d e f g

Hope this will help you while doing a loop or building some hash directories : view source print? 1 nicolas@macvin:~$ mkdir -p test/{1..10}/{1..10}

Enjoy !

Identity Finder

Loggs stored Here on a Mac

~/Library/Application Support/Identity Finder/Identity Finder Mac Edition/logs/