Tuesday, November 02, 2004

Shell procedures

Shell procedures

From Steve Parker

The shell may be used to read and execute commands contained in a file. For example,
	sh file [ args ... ]

calls the shell to read commands from file. Such a file is called a command procedure or shell procedure. Arguments may be supplied with the call and are referred to in file using the positional parameters $1, $2, .... For example, if the file wg contains
	who | grep $1

then
	sh wg fred

is equivalent to
	who | grep fred

Saturday, September 25, 2004

Linux Cheat Sheet

alias
Create an alias

Usagealias [name[=’value’]]
Examplealias la=’ls -la --color=auto’
ExplanationCreates an alias for the ls command which displays a detailed list with various file types in different colours.
Windows equivalentN/A

cat
Display the contents of a file

Usagecat [options] [file1] [file2] ...
Examplecat index.html
ExplanationDisplays the contents of the index.html file.
Windows equivalenttype

cd
Change directory

Usagecd [-LP] [directory]
Examplecd /usr/local/bin
ExplanationChanges the /usr/local/bin directory.
Windows equivalentcd

chgrp
Change group ownership

Usagechgrp [options] group file1 file2 ...
Examplechgrp apache index.html
ExplanationChanges the group ownership of the index.html file to the apache group.
Windows equivalentN/A

chmod
Change access permissions

Usagechmod [options] mode file1 file2 ...
Examplechmod 755 script.cgi
Explanation"Changes the permissions of script.cgi so that everyone can execute and read it
Windows equivalent but only the owner can write to it."

chown
Change file owner and group

Usagechown [options] new-owner file1 file2 ...
Examplechown root index.html
ExplanationChanges the ownership of the index.html file to root.
Windows equivalentN/A

cmp
Character-by-character compare between two files

Usagecmp [options] from-file to-file
Examplecmp index.html default.htm
Explanation"Compares each character in index.html and default.htm
Windows equivalent and displays the differences."

cp
Copy one or more files to another location

Usagecp [options] source destination
Examplecp index.html index.html.bak
ExplanationMakes a second copy of the index.html file in the same directory. The new copy has the BAK extension.
Windows equivalent"copy

df
Display free disk space

Usagedf [options] [file]
Exampledf
ExplanationDisplays the used and free disk space on all mounted filesystems.
Windows equivalentdir

du
Estimate file space usage

Usagedu [options] [file]
Exampledu
ExplanationDisplays the disk usage of the current directory.
Windows equivalentdir

echo
Display message on screen

Usageecho [options] [string]
Exampleecho Hello World!
ExplanationDisplays the Hello World! message on the screen.
Windows equivalentecho

env
"Display

Usage set or remove environment variables"
Exampleenv [options] [name[=value]] [comand [args]]
Explanationenv HOME=/home/username
Windows equivalentChanges the HOME environment variable to /home/username.

exit
Exit the shell

Usageexit
Exampleexit
ExplanationExits from the current shell.
Windows equivalentN/A

free
Display memory usage

Usagefree [options]
Examplefree -s 5
Explanation"Displays current memory usage
Windows equivalent updating it every five seconds."

fsck
Filesystem consistency check and repair

Usagefsck [options] [filesystem]
Examplefsck /dev/hda1
ExplanationPerforms a filesystem check on the first partition of the primary master IDE drive.
Windows equivalentchkdsk

grep
Search file(s) for lines that match a given pattern

Usagegrep [options] string [file1] [file2] ...
Example"grep ""search string"" /home/*"
Explanation"Searches all files in /home for the occurence of the ""search string""."
Windows equivalentN/A

gzip
Compress or decompress named file(s)

Usagegzip [options] file
Examplegzip index.html
ExplanationCompressed index.html into a file named index.html.gz.
Windows equivalentN/A

kill
Stop a process from running

Usagekill [options] pid
Examplekill 1234
ExplanationTerminates the process with id 1234. Use ps to determine a processes id.
Windows equivalentkill

less
Display content one screen at a time

Usageless [options]
Examplecat index.html | less
Explanation"Displays the index.html file on the screen
Windows equivalent one screen at a time."

ln
Make links between files

Usageln [options] target [linkname]
Exampleln -s /var/www/html /home/user/website
ExplanationCreates a shortcut named website from the user’s home directory to the /var/www/html directory.
Windows equivalentshortcut

locate
Find files

Usagelocate [options] string
Examplelocate perl
ExplanationSearches filesystem databases for files containing the term perl.
Windows equivalentdir /s

ls
List information about file(s)

Usagels [options] [file/directory]
Examplels -la /var/www/html
ExplanationPrints a detailed list of all files and directories located in the /var/www/html directory.
Windows equivalentN/A

man
Help manual

Usageman [options] [command]
Exampleman man
ExplanationDisplays the manual for the man command.
Windows equivalentN/A

mkdir
Create new folder(s)

Usagemkdir [options] directory
Examplemkdir html
ExplanationCreates a directory named html under the current directory.
Windows equivalentmd

mount
Mount a file system

Usagemount [options] [device/directory]
Examplemount cdrom
ExplanationMounts the CD-ROM drive.
Windows equivalentN/A

mv
Move or rename files or directories

Usagemv [options] source destination
Examplemv index.html /var/www/html
ExplanationMoves the index.html file from the current directory to /var/www/html.
Windows equivalentmove

nice
Set the priority of a command or job

Usagenice [options] [comand [args]]
Examplenice -n 19 httpd
ExplanationRuns the httpd process with the lowest possible priority (-20 is the highest priority).
Windows equivalentN/A

passwd
Modify a user password

Usagepasswd [options]
Examplepasswd
ExplanationPrompts you to change the password for the current user. It will prompt for the old password first.
Windows equivalentN/A

ping
Sends and echo packet to a host

Usageping [options] host
Exampleping www.apcmag.com
ExplanationContinually sends echo packets to the www.apcmag.com host.
Windows equivalentping

ps
Process status

Usageps [options]
Exampleps -ef
ExplanationDisplays full list of all running processes.
Windows equivalentmem

pwd
Print working directory

Usagepwd [options]
Examplepwd
ExplanationPrints the directory the terminal is presently in.
Windows equivalentcd

rm
Remove files

Usagerm [options] file1 file 2 ...
Examplerm -rf /var/www/html
ExplanationForces the removal of the /var/www/html directory and all files and subdirectories indside it.
Windows equivalentdel

rmdir
Remove folder(s)

Usagermdir [options] directory1 directory2 ...
Examplermdir /var/www/html
ExplanationRemoves the /var/www/html directory (assuming it’s empty).
Windows equivalentrd

shutdown
Shutdown or restart Linux

Usageshutdown [options] when [message]
Exampleshutdown -r 20:00
ExplanationReboots the system at 8pm.
Windows equivalentshutdown

sleep
Delay for a specified time

Usagesleep [number]
Examplesleep 30
ExplanationPauses for 30 seconds — useful in some scripts.
Windows equivalentsleep

su
Substitute user identity

Usagesu [options] [username [args]]
Examplesu
ExplanationSwitches to the root user.
Windows equivalent"su

tail
Output the last part of files

Usagetail [options] [file1] [file2] ...
Exampletail /var/log/error.log
ExplanationDisplays the last 10 lines of the error log.
Windows equivalentN/A

tar
Tape archiver

Usagetar [options] file1 [file2] ...
Exampletar - czvf archive.tar.gz /var/www/html
ExplanationCompresses the contents of the /var/www/html directory into a gzipped tarball named archive.tar.gz.
Windows equivalentN/A

touch
Change file timestamps

Usagetouch [options] file1 ...
Exampletouch /var/www/html/index.html
Explanation"Updates the timestamp on /var/www/html/index.html
Windows equivalent or creates the file if it doesn’t exist."

top
List processes running on the system

Usagetop [options]
Exampletop
ExplanationProvides an automatically-updating list of the most CPU intensive processes running on the system.
Windows equivalentN/A

traceroute
Trace route to host

Usagetraceroute [options] host [packetsize]
Exampletraceroute www.apcmag.com
ExplanationPrints a list of all routers (and IP addresses) that IP datagrams pass through en route to the www.apcmag.com server.
Windows equivalenttracert

umount
Unmount a device

Usageumount [options] [device/directory]
Exampleumount cdrom
ExplanationUnmounts the CD-ROM drive.
Windows equivalentN/A

unalias
Remove an alias

Usageunalias [options] [name]
Exampleunalias la
ExplanationRemoves the alias named la.
Windows equivalentN/A

uname
Print system information

Usageuname [options]
Exampleuname -a
ExplanationPrints all system information relating to the machine and OS.
Windows equivalentN/A

which
Locate a program file in the user’s path

Usagewhich [options] file ...
Examplewhich perl
Explanation"Same as locate
Windows equivalent but restricts the search to the user’s path."

Wednesday, August 11, 2004

POSIX version affects Coreutils

1) http://lists.debian.org/debian-glibc/2003/08/msg00127.html
This has some information about the sort & tail.
2) http://linux.com.hk/PenguinWeb/manpage.jsp?name=sysconf&section=3
This has information on the System Environment Variables
3) http://www.sunsite.ualberta.ca/Documentation/Gnu/gawk-3.0.6/html_node/gawk_136.html#IDX513
This is quite long, about GNU which relates to POSIX variable.

Friday, July 16, 2004

Mounting of Floppy on SUN Solaris

1) volcheck - equivalent to mount in Linux
2) By default, mount point is /floppy
3) eject - equivalent to umount in Linux

Very useful site from SUN

Monday, July 12, 2004

SSH Configuration

Possible Steps to Check the Configuration
1) ssh -v -v -v
To increase the verbosiy, some vs will take ssh -vvv
2) pgrep sshd
To make sure the daemon/server service is running if it return a process ID
3) /etc/ssh/sshd_config
To determine which port is in use for the ssh communication
4) Make link between ~/.ssh/authorized_keys to ~/.ssh/authorized_keys2
To ensure both protocol will grap the keys either way (SSH has 2 protocol, 1 & 2)
5) Trying "cat"ing the key instead of "cp"ing the keys as the later might change the format.

More info from www.linuxquestions.org

Wednesday, July 07, 2004

Installation of NIC driver onto Dell PowerEdge W/S


From Intel Website


Steps can be found from README pages.

Wednesday, June 16, 2004

To allow rsh

If you must use rexec, rsh, and rlogin, and if you need to use them as root, you will need to make a few modifications to the /etc/securetty file. All three of these tools have PAM configuration files that require the pam_securetty.so PAM module, so you must edit /etc/securetty to allow root access.

Before you can log in as root using these tools, you first have to have them properly set up. First, install the rsh-server RPM, which is included with Red Hat Linux 7.1. See the Official Red Hat Linux Customization Guide if you need assistance using RPM.

Next, run ntsysv and enable rexec, rsh, and rlogin. See the ntsysv man page if you need help using this tool.
Finally, restart xinetd with /sbin/service xinetd restart to activate the ntsysv changes. At this point, all users except root will be able to use rexec, rsh, and rlogin.

To allow root to use these tools, add the names of the tools you wish to allow to the /etc/securetty. If you wanted to enable root login using rexec, rsh, and rlogin, add the following lines to /etc/securetty:

rexec
rsh
rlogin

To allow root to log in using these tools via telnet (an even worse idea but necessary in some environments), add a few more lines:

pts/0
pts/1

Info from Redhat