FIND

Any file in unix that starts with a ".", like .profile, is a hidden file. That's how that works

to include these files in your find:

ls -a

find txt in file
$ find . -name "*.log" -exec grep -l "addQuickDepositAccounts" {} \;

find file by name
$ find . -name "rc.conf" -print

$ find . -name "event*.jar"

Fine a filename that contains properties

$ find . -print | grep properties

Find a string in all directories for a string.

$ find . -exec grep "string" {} /dev/null \;

TAR command


extract a tar file to current dir
tar -xvwf myfile.tar


create a tar file to current dir
tar -cvwf file.tar myfile.txt

tar -zxvf yourfile.tar to extract the file to the current directory.

tar -C /myfolder -zxvf yourfile.tar to extract to /myfolder directory.

Change Home path

As root, open the file /etc/passwd

You will see a line that looks like this:
Code:
  • davidq:x:1000:100:,,,:/home/davidq:/bin/bash
Change it to this:
Code:
  • davidq:x:1000:100:,,,:/home/whatevery:/bin/bash

Make sure you have done this:

Code:
  • mkdir /home/whatevery
  • chown davidq /home/whatevery

crontab

Visual CRONTAB: http://www.corntab.com/pages/crontab-gui

===========================

===========================

http://www.pantz.org/software/cron/croninfo.html

# backup will run on 7th day of the month
0 0 7 * * cp -r -u -f /media/shares/ /media/backup/shares/ >>/var/log/cronrun

/root/backup.sh

#!/bin/sh
####################################
#
# Backup to NFS mount script.
#
####################################
# What to backup.
#backup_files="/root /srv /home /var/spool/mail /etc /boot /opt"
backup_files="/root /srv /home /var/spool/mail /etc /boot /opt"

# Create archive filename.
day=$(date +"%Y-%m-%d.%H-%M-%S")
servername=$(hostname -s)
archive_file="$servername.$day.tgz"

# Where to backup to.
env=01
#mount=/mnt/local/sdb1
mount=/mnt/nfs/fs-$env.sdb1
#dest="$mount/backup/$servername"
dest="$mount/backup"
mkdir -p $dest

fullpath=$dest/$archive_file
# Print start status message.
echo "Backing up $backup_files to $fullpath"
echo $(date)
echo

# Backup the files using tar.
#tar czf $fullpath $backup_files
tar czf $fullpath $backup_files
chmod 400 $fullpath

# Print end status message.
echo
#echo $(date)
echo "Backup finished"
date

# Long listing of files in $dest to check file sizes.
ls -lh $dest

read this: http://www.thegeekstuff.com/2010/09/rsync-command-examples/

Shutdown/Restart

shutdown command

shutdown arranges for the system to be brought down in a safe way. All logged-in users are notified that the system is going down and, within the last five minutes of TIME, new logins are prevented. The shutdown utility provides an automated shutdown procedure for supersers to nicely notify users when the system is shutting down, saving them from system administrators, hackers, and gurus, who would otherwise not bother with such niceties.

The shutdown command can be used to turn off or reboot a computer.


How do I use shutdown command?

Type the command as follows to shutdown server / computer immediately:
$ sudo shutdown -h now
OR
$ sudo shutdown -h 0

How do I shutdown compute at specific time?

To shutdown computer at 6:45pm, enter:
$ sudo shutdown -h 18:45 "Server is going down for maintenance"
At 6:30pm message will go out to all user and 6:45 system will shutdown.

halt or poweroff or reboot command for stopping and restarting the system:
$ sudo halt
OR
$ sudo poweroff

Simply use reboot command:
$ sudo reboot
OR
$ sudo shutdown -r 0

Disk Usage

Helpful info: http://www.codecoffee.com/tipsforlinux/articles/22.html

http://www.makeuseof.com/tag/how-to-analyze-your-disk-usage-pattern-in-linux/

http://www.google.com/#sclient=psy&hl=en&source=hp&q=linux+disk+usage&aq=1&aqi=g5&aql=&oq=linux+disk+&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=ae988db1847db761&biw=1280&bih=872

Command line

If you are geeky enough, the easiest and fastest way is to use the ‘df’ command in your terminal. Simply type

$ df -h

in the terminal and it will show the disk usage percentage of your hard disk.

$ du -a -m /app 2>/dev/null | egrep '.*[123456789]{3}\.[123456789]{2}.*/.*' | less
output
118.69 /app/Apache22/0/logs
162.93 /app/Apache22/0
162.93 /app/Apache22
114.83 /app/Tomcat55/0/reference
367.62 /app/Tomcat55/0
367.62 /app/Tomcat55
114.82 /app/vpc/activemq-4.1.1/activemq-data
136.45 /app/vpc/activemq-4.1.1
4894.78 /app/vpc/event-normalizer-service/nohup.out
739.71 /app/vpc/sxg-event-normalizer-service-delete-me/lib
739.71 /app/vpc/sxg-event-normalizer-service-delete-me
6612.81 /app

Java 7 provicdes a solution:

http://stackoverflow.com/questions/1051295/how-to-find-how-much-disk-space-is-left-using-java

NumberFormat nf = NumberFormat.getNumberInstance();
for (Path root : FileSystems.getDefault().getRootDirectories())
{
System.out.print(root + ": ");

try
{
FileStore store = Files.getFileStore(root);
System.out.println("available=" + nf.format(store.getUsableSpace()) + ", total=" + nf.format(store.getTotalSpace()));
}
catch (FileSystemException e)
{
System.out.println("error querying space: " + e.toString());
}
}

Active Users

Two options:

  • users

davidq root tomcat6

  • w

12:51:40 up 3 days, 20:49, 3 users, load average: 0.00, 0.05, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.129.42.213 12:51 0.00s 0.02s 0.00s w
davidq pts/1 172.29.255.151 11:43 48:14 1:13 0.03s bash
tomcat6 pts/2 172.29.255.151 11:50 39:28 0.07s 0.06s bash


Tag Cloud