*Create a Partition:
o fdisk /dev/(device i.e. sdb)
File system types
o For ext2 use 'mke2fs'
For ext3 use 'mke2fs -j'
For reiserfs use 'mkreiserfs'
For xfs use 'mkfs.xfs'
For jfs use 'mkfs.jfs'
Create a file system (example)
o mke2fs /dev/(device i.e. sdb1)
Activate drive:
o Add entry to /etc/fstab
+ vi /etc/fstab
Mount all devices in fstab
+ mount -a
Note: If unfamiliar with vi, use pico to edit in non visual interface
Mount a Floppy Disk Drive
* mount -t msdos /dev/fd1 /mnt/floppy
(or use ufat instead of msdos)
Search for installed packages
* rpm -qa|grep package (redhat)
* dpkg -qa | grep
Remove Installed Package
* rpm -e package (Red Hat)
* dpkg -P package (Debian Linux)
else
apt-get remove package
Managing Most Services
* /etc/init.d
then use command stop i.e. ./Kasenna_Apache stop
Make a link
* ln -s destinationoflink linkname
Check kernel version
* uname -r
Make images of cd-roms or hdd
* dd if=/dev/hda of=/dev/hdc bs=4k block_size
Messages (to other users)
* Send to all
wall message
Send to one user (insert message after
write user
Send to one user on a specific terminal
write user tty1
Compare 2 Source Code Files
* diff -u file1 file2
+ means in #2 not in #1 - means in #1 not in #2
Make software tarball (compression methods)
*
tar -cvf hi.tar *
then
gzip hi.tar
Create md5 check sum
*
md5sum -b boot.gz
Find a file
*
find (dir) -name filename
o
eg. find ./ -name help.txt
find and execute a command on all found files:
o
find (dir) -name (expr) | xargs (command)
Search several text files in several directories
*
grep -r --with-filename 00:00:00:00:00: */mac_table
Get the size of all sub-directories
* du -s *
(use -sk for kilobytes or -sh for human readable)
Send e-mail from console
* echo "Message" | mail -s "subject" recipient1 recipient2 recipient3
Remove first character of line
* cut -c 2-
Remove password on sudo
* in ~/.bash_profile place the line:
export SUDO=sudo
as root run visudo uncomment
%wheel .... no passwords
add users who need passwrodless sudo to wheel group
vi /etc/group
Increase Priority of Process
* nice -n
(pri -20 to 20 where -20 is the fastest or highest priority)
To get files from a ramdisk
* Copy ramdisk to temp dir then:
gunzip ramdisk
mount -o loop -t ext2 ramdisk_img
Get the required files then:
umount
To print a test file from the cli
* lpr filename
To count the number of lines with sed
* sed -n '$=' filename
cat filename | sed -n '$='
Grab One Line out of a Text File
* cat textfile | sed -e 's#\t##g' | sed -n "Line_Number"
Replace one line in a textfile
* sed 10c\\"New_String = -mq${1}" textfile
o
-- Where 10 is the line number
Pull Out String From Line
* echo "inet addr:192.168.145.11 Bcast:192.168.145.255" |sed -e 's/[^i]*inet addr:\([0-9.]*\).*/\1/p'
Redirect Command output
* Redirect Standard to Null
* command > /dev/null
Redirect All Standard to Null
command &> /dev/null
Redirect Errors to Same Location as Standard
command > /dev/null 2>&1
Redirect Errors to Null
command 2> /dev/null
Redirect Standard to File
Just replace "/dev/null" with filename
-- use '>>' to append file instead of overwrite '>'
Use vi in split screen mode
* Enter split screen
* :split
o
Open new file
:e path/filename
o
Switch to Upper Window
ctnl+w k
o
Switch to Lower Window
ctnl+w j
Create a cron job entry
*
Run the crontab editor
crontab -e
Then add entry
Example crontab
*
A decent cron template. Remove commands or add commands as needed (was used for Gentoo so emerge commands will not be valid on a non-Gentoo rig)
#!/bin/sh
cdmailto=me
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:$HOME/bin
# minute (0-59),
# | hour (0-23),
# | | day of the month (1-31),
# | | | month of the year (1-12),
# | | | | day of the week (0-6 with 0=Sunday).
# | | | | | commands
# ------{ default cron crap }---------- #
0 * * * * rm -f /var/spool/cron/lastrun/cron.hourly
1 3 * * * rm -f /var/spool/cron/lastrun/cron.daily
15 4 * * 6 rm -f /var/spool/cron/lastrun/cron.weekly
30 5 1 * * rm -f /var/spool/cron/lastrun/cron.monthly
*/10 * * * * /usr/bin/test -x /usr/sbin/run-crons && /usr/sbin/run-crons
# ------{ daily cron jobs }------------ #
0 1 * * * emerge sync >/dev/null 2>&1
0 2 * * * /backup/backup.sh
40 1 * * * emerge -uDpv world >/home/ben/Reports/emerge.txt
0 3 * * * updatedb && eupdatedb >/dev/null 2>&1
0 4 * * * glsa-check -l | grep '\[N\]'
# ------{ weekly cron jobs }----------- #
15 7 * * 0 makewhatis
0 7 * * 1 fc-cache -fv
0 4 * * 2 tar -cvzf /backup/weekly-backup.tgz /backup/weekly/*
10 4 * * 3 rsync -v -a --delete /backup/weekly-backup.tgz /mnt/nfs/backup/weekly-backup.tgz
# ------{ bi-weekly & monthly jobs }--- #
"
Links
http://www.acck.edu/~jerod/spellbook.html
Boot into single user mode
1. On boot up get to the grub menu 2. press 'e' to edit your boot parameters 3. add "init=/bin/sh" to the list of kernel parameters 4. save and then boot off that modified selection 5. you will now have root access in singl user mode
No comments:
Post a Comment