Now I am going introduce you to a set of commands & System Admin Tools that may come handy
FIND
[bash]
find -perm 777 -type d -exec chmod 755 {} \; #Command to change all the folders under present directory with 777 to 755
find -perm 755 -type f -exec chmod 644 {} \; #Command to change all the folders under present directory with 755 to 644
find -type d -maxdepth 3 -exec cp file {} \; #Copy file to 3 levels of directories below the present directory
find . -name “*.trn” -ctime +3 -exec rm -f {} \; #Forcible remove files with .trn extension and 3 days old.
find . -cmin -5 #Find all files created or updated in the last five minutes:
[/bash]
(Great for finding effects of make install)
LS
[bash]
ls -lSh #List files by their size
ls -ltr #List files by date
ls -F #Appends a symbol after files and directories
[/bash]
RSYNC
[bash]
rsync -e ssh -az /currentdirectory IP:/remotedirectory #Sync remote directory with our current directory.
rsync –bwlimit=1000 fromfile tofile #Locally copy with rate limit
[/bash]
GPG
[bash]
gpg -c file #Encrypt file
gpg file.gpg #Decrypt file
[/bash]
DF
[bash]
du -h –max-depth 1 #Show disk space used by all the files and directories.
du -s * | sort -k1,1rn | head #Show top disk users in current directory.
df -h #Show free disk space
df -i #Show free inodes
[/bash]
Add system swap space for virtual memory paging used for System Admin Tools
Swap space may be a swap partition, a swap file or a combination of the two. One should size swap space to be at least twice the size of the computer’s RAM. (but less than 2GB)
[bash]
dd if=/dev/zero of=/swapfile bs=1024 count=265032 – #Create file filled with zeros of size 256Mb
mkswap /swapfile #Create swap file
swapon /swapfile #Begin use of given swap file.
[/bash]
Assign a priority with the “-p” flag.
[bash]
swapon -s #List swap files
scat /proc/swaps #Same as above
[/bash]
This example refers to a swap file. One may also use a swap partition.
Make entry to /etc/fstab to permanently use swap file or partition.
[bash]
/swapfile swap swap defaults 0 0
[/bash]
Note: To remove the use of swap space, use the command swapoff. If using a swap partition, the partition must be unmounted.
Debugging System Admin Tools
[bash]
strace -c ls >/dev/null #Summarise/profile system calls made by command
strace -f -e open ls>/dev/null #List system calls made by
command
ltrace -f -e getenv ls >/dev/null #List library calls made by command
lsof -p $$ #List paths that process id has open
lsof -p PID #List paths PID has open
lsof ~ #List processes that have specified path open
last reboot #Indicates last reboot time
[/bash]
renice +15 PID #To give lower priority for a PID -19 is highest and +20 is lowest
To check number of IP’s connecting to port 80
[bash]
netstat -tanpu |grep :80 |awk {‘print $5’} |cut -d: -f1 |sort -n |uniq -c
tcpdump not port 22 #To show network traffic except on port 22
[/bash]
Perl Administration using System Admin Tools
Installation of perl module can be done from tar file.
[bash]
tar xzf yourmodule.tar.gz #Untar Module
perl Makefile.PL #Build with PERL makefile:
make
make install #Install
[/bash]
You can also do this from cpan shell
[bash]
perl -MCPAN -e shell #First time through it will ask questions Answer “no” to the first question for
autoconfigure
cpan> install URI
cpan> i /PerlMagick/ #Inquire about module. (Search by keyword)
Distribution J/JC/JCRISTY/PerlMagick-5.36.tar.gz
Module Image::Magick (J/JC/JCRISTY/PerlMagick-5.36.tar.gz)
cpan> install Image::Magick
cpan>force install Image::Magick #Install a module forcefully.
[/bash]
YUM :RPM Updater
YUM (Yellowdog Updater, Modified) is a client command line application for updating an RPM based system from an internet repository (YUM “yum-arch” server) accessible by URL (http://xxx, ftp://yyy or even file://zzz local or NFS)
[bash]
yum -y install package-name #To install a package along with its dependencies
yum remove package-name #To remove package
yum list #To list available packages version and state
yum list extras #To list packages not available in repositories but listed in config file
yum list obsoletes #To list packages which are obsoleted by repositories
yum clean all #To list packages which are obsoleted by packages in yum repository
yum update #Update all packages on your system
yum update package-name #Update a package
yum update package-name-prefix\* #Update all with same prefix
[/bash]
You can add new repos in /etc/yum.repos.d with files named file.repo For the option “gpgcheck=1” to work, use the “rpm –import GPG-KEY
[bash]
rpm –import /usr/share/rhn/RPM-GPG-KEY
rpm –import /usr/share/rhn/RPM-GPG-KEY-fedora
File: /etc/yum.repos.d/fedora.repo with following entry
[base]
name=Fedora Core $releasever – $basearch – Base
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/core/$releasever/$basearch/os/
mirrorlist=http://fedora.redhat.com/download/mirrors/fedora-core-$releasever
enabled=1
gpgcheck=1
[/bash]
Additional Commands
[bash]
tzselect #To change time zone of the machine
command 2>&1 | tee outputfile.txt #Output of a command is send to a text file
wget –mirror http://www.example.com #To mirror a site
wget -c http://www.example.com/largefile #To continue downloading partially downloaded file
[/bash]
Many more tricky commands to be updated soon based on System Admin Tools for more visit
)