« Creating & Debugging SSL Certificates | Main | Nagios »
My Favorite Commands…
By Matt | October 5, 2007
Some of the command constructs I love but don’t always remember off the top of my head:
Recursively search for a text string, and provide the file path and name.
sudo find ./ -exec grep “http://litmus.mozilla.org” {} \ ls -l {} \; 2> /dev/null
Recursively add files to svn:
svn status | grep "\?" | awk '{print $2}' | xargs svn add
Installing a Mac .dmg package from command line:
hdiutil attach ./file.dmg
The output from hdiutil will include the mount point. cd to that mount point and ls to find the mpkg name. The run this command, substituting the file.mpkg as appropriate:
sudo installer -pkg ./file.mpkg -target /
Flushing Swapfile without a reboot:
You may need to stop services using memory (i.e. sudo /etc/init.d/httpd stop) to free up some memory if it’s completely maxed. Occassionally you still need to reboot, but if you want to try and just flush it:
grep swap /etc/fstab
(This will tell you the volume used for swap)
sudo /sbin/swapoff /dev/[swapvol]
sudo /sbin/swapon /dev/[swapvol]This could take several minutes. It’s good if you have top open in another terminal — you can monitor the swap file decreasing in size!
smbmount / cifsmount replacement:
Much more elegant…but I grew up with smbmount then cifsmount and thus keep forgetting the new syntax:
mount -t cifs //192.168.218.1/shared /shared -o user=username
Manually running logrotate:
/usr/sbin/logrotate -f -s /var/lib/logrotate.status /etc/logrotate.d/[sitename.conf]
MySQL:
show processlist — shows connections.
show variables — shows settingsMySQL stores it’s data in /var/lib/mysql/ (your mileage may vary…)
ibdata1 is the default data store for innodb databases. If you need to shrink it, it’s a matter of backing up the databases, deleting ibdata1, and restoring the databases.A good thing to do when dealing with large databases is to add innodb_file_per_table to my.cnf (under [mysqld]) which will create seperate data stores for each database.
Doing that, restarting mysqld, then running
mysqloptimize –all-databases (or mysqlcheck –optimize –all-databases -u [username] -p )
will seperate the databases into seperate datastores (what MySQL calls “tablespaces” — these will be under the corresponding subdirectories in /var/lib/mysql ).
Mount a DVD iso in Linux:
sudo mount -o loop -t iso9660 ~/F-7-x86_64-DVD.iso /var/www/html/FC7
Determining top ten largest files:
du -sh * | sort -r -n | head -10
Determing disk i/o activity:
vmstat 1 360 will poll every second for six minutes, and the “bi” will show blocks read in. bo is blocks out.
procs ———–memory———- —swap– —–io—- –system– —-cpu—- r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 69384 110944 209456 2458208 0 0 0 0 179 1235 1 0 99 0
0 0 69384 110448 209456 2458208 0 0 0 16 185 406 2 0 98 0
Check if SSL is running: openssl s_client -host (host) -port (port)
If SSL is running, it will return the ssl certificate. If not, it will return a handshake failure message.
Linux Last user logon: lastlog
Failed logon attempts: faillog (needs settings enabled in /etc/pam.d/system-auth)
What ports are in use?
netstat -tunap
SCP with inline find:
This command uses find in a directory to locate the files changed in the past month:
scp $(find /var/lib/awstats/* -mtime -1) host:.
or
find /var/lib/awstats/* -ctime -1 | xargs -I{} scp {} host:.
OS X updates: softwareupdate is the equivelant to yum or apt-get.
What modules are loaded?
lsmod
Remove a module
rmmod
Add a module
modprobe
Sweet!
To view the tail end of a file interactively:
tail -f /path/to/filename
Placeholder
Topics: Linux, Sysadmin Tools, Windows | No Comments »
Comments
You must be logged in to post a comment.