Sunday, July 18, 2010

ln Command

Creates a link to a file.

Syntax

ln [-f] [-n] [-s] existingfile newname

-fLink files without questioning the user, even if the mode of target forbids writing. This is the default if the standard input is not a terminal.
-nDoes not overwrite existing files.
-sMakes it so that it does not create a symbolic link (not on System V..) existingfile - The file that you want to create a new link.
existingfileSpecifies file(s) that you want to create a link to.
newnameThe new name of the file.
directoryThe directory were you want the new link.

Examples

ln public_html/myfile.txt

Would create a hard link to myfile.txt in the current directory assuming that it is not public_html. Note: A link cannot be created to a file if currently in the directory where the file exists.

ln -s file1 file2

Creates a Symbolic Link to file1 with the name of the file2.

rm Command

Deletes a file (without confirmation by default).

Syntax

rm [-f] [-i] [-R] [-r] [filenames | directory]

-fRemove all files (whether write-protected or not) in a directory without prompting the user. In a write-protected directory, however, files are never removed (whatever their permissions are), but no messages are displayed. If the removal of a write-protected directory is attempted, this option will not suppress an error message.
-iInteractive. With this option, rm prompts for confirmation before removing any files. It over- rides the -f option and remains in effect even if the standard input is not a terminal.
-RSame as -r option.
-rRecursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally prompted for removal of any write-protected files which the directory contains. The write-protected files are removed without prompting, however, if the -f option is used, or if the standard input is not a terminal and the -i option is not used. Symbolic links that are encountered with this option will not be traversed. If the removal of a non-empty, write-protected directory is attempted, the utility will always fail (even if the -f option is used), resulting in an error message.
filenamesA path of a filename to be removed.

Examples

rm file.txt

Remove the file file.txt without user's Confirmation.

rm -r directory

Remove a directory, even if files existed in that directory.

Saturday, July 17, 2010

mv Command

Renames or moves a file from one directory to another directory.

Syntax

mv [-f] [-i] oldname newname

-fmv will move the file(s) without prompting even if it is writing over an existing target. Note that this is the default if the standard input is not a terminal.
-iPrompts before overwriting another file.
oldnameThe oldname of the file renaming.
newnameThe newname of the file renaming.
filenameThe name of the file you want to move directory - The directory of were you want the file to go.

Examples

mv test.cpp newdir/

moves the file test.cpp to the directory newdir.

mv test.txt ../

moves the file test.txt back one directory (only if directory available).

cp Command

Copies files from one location to another.

Syntax

cp [OPTION]... SOURCE DEST

-a, --archivesame as -dpR
--backupmake a backup of each existing destination file
-blike --backup but does not accept an argument
--copy-contentscopy contents of special files when recursive
-dsame as --no-dereference --preserve=link
--no-dereferencenever follow symbolic links
-f, --forceif an existing destination file cannot be opened, remove it and try again
-i, --interactiveprompt before overwrite
-Hfollow command-line symbolic links
-l, --linklink files instead of copying
-L, --dereferencealways follow symbolic links
-psame as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: links,
all
--no-preserve=ATTR_LISTdon't preserve the specified attributes
--parentsappend source path to DIRECTORY
-Psame as '--no-dereference'
-R, -r, --recursivecopy directories recursively
--remove-destinationremove each existing destination file before attempting to open it (contrast with --force)
--reply={yes,no,query}specify how to handle the prompt about an existing destination file
--sparse=WHENcontrol creation of sparse files
--strip-trailing-slashesremove any trailing slashes from each SOURCE argument
-s, --symbolic-linkmake symbolic links instead of copying
-S, --suffix=SUFFIXoverride the usual backup suffix
--target-directory=DIRECTORYmove all SOURCE arguments into DIRECTORY
-u, --updatecopy only when the SOURCE file is newer than the destination file or when the destination file is missing
-v, --verboseexplain what is being done
-x, --one-file-systemstay on this file system

Examples

cp file.sh newfolder

Copies the file.sh from current directory to the newfolder directory.

cp /home/log.txt /home/backuplog.txt

Copies the log.txt file in the home directory to the home directory itself but as backuplog.txt. The files are identical however have different names.

cp *.c new

Copy all files ending in .c extention into the "new" directory.

ls Command

Lists the contents of a directory.

Syntax

ls [-a] [-A] [-b] [-c] [-C] [-d] [-f] [-F] [-g] [-i] [-l] [-L] [-m] [-o]
[-p] [-q] [-r] [-R] [-s] [-t] [-u] [-x] [pathnames]


-aShows you all files, including hidden files (Note :
hidden files begin with a dot.)
-AList all files including the hidden files. but not
displays the working directory (.) and parent directory (..).
-bForce printing of non-printable characters to be in
octal notation.
-cUse time of last modification of the i-node (file
created, mode changed, e.t.c)
-CMulti-column output with entries sorted down the
columns. Generally the default one.
-dIf an argument is a directory it only lists its name
not its contents.
-fForce each argument to be interpreted as a directory
and list the name found in each slot. This option turns off -l, -t, -s,
and -r, and turns on -a; the order is the order in which entries appear
in the directory.
-FMark directories with a trailing slash (/), doors with
a trailing greater-than sign (>), executable files with a trailing
asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links
with a trailing at-sign (@), and AF_Unix address family sockets with a
trailing equals sign (=).
-gSame as -l except the owner is not printed.
-iFor each file, print the i-node number in the first
column of the report.
-lShows you informations such as permissions, owners,
size, and when last modified e.t.c.
-LIf an argument is a symbolic link, list the file or
directory the link references rather than the link itself.
-mStream output format; files are listed across the page,
separated by commas.
-nThe same as -l, except that the owner's UID and group's
GID numbers are printed, rather than the associated character strings.
-oThe same as -l, except that the group is not printed.
-pDisplays a slash ( / ) in front of all directories.
-qForce printing of non-printable characters in file
names as the character question mark (?).
-rReverses the order of how the files are displayed.
-RIncludes the contents of subdirectories.
-sGive size in blocks, including indirect blocks, for
each entry.
-tShows you the files in modification time.
-uUse time of last access instead of last modification
for sorting (with the -t option) or printing (with the -l option).
-xDisplays files in columns.
-1Print one entry per line of output.
pathnamesFile or directory to list.

Examples

ls -l

In the above example this command would list each of the files in the current
directory and the files permissions, the size of the file, date of the last
modification, and the file name or directory. Below is additional information
about each of the fields this command lists.

PermissionsDirGroupSizeDateDirectory/file
drwx------3www4096Nov 1 19:50usr/
drwxr-s---32system32768Jan 20 20:30etc/
-rw-------1user3Nov 25 07:58first.c

Below is brief description of each of the above categories shown
when using the ls -l command.

Permissions - The permissions of the directory or file.

Directories - The amount of links or directories within the directory.

The default amount of directories is going to always be 2 because of the . and
.. directories.

Group - The group assigned to the file or directory

Size - Size of the file or directory.

Date - Date of last modification.

Directory of file - The name of the file or file.


ls ~

List the contents of your home directory by adding a tilde after the ls
command.

ls /

List the contents of your root directory.

ls ../

List the contents of the parent directory.

ls */

List the contents of all sub directories.

ls -d */

Only list the directories in the current directory.

Thursday, July 1, 2010

Linux Commands (Quick Reference)

Here are few commands for quick reference.
Commands in detail will be discussed later.



File/Directory Basics
ls -List Files
cp -Copy files
mv -Move files
rm -Delete files
ln -Link files
cd -Change directory
pwd -Print current directory name
mkdir -Create directory
rmdir -Delete directory

File Viewing
cat -View files
less -Page through files
head -View file beginning
tail -View file ending
nl -Number lines
od -View binary data
xxd -View binary data
gv -View Postscript/PDF files
xdvi -View TeX DVI files

File Creation and Editing
emacs -Text editor
vim -Text editor
umask -Set default file protections
soffice -Edit Word/Excel/PowerPoint docs
abiword -Edit Word documents
gnumeric -Edit Excel documents

File Properties
stat -Display file attributes
wc -Count bytes/words/lines
du -Measure disk usage
file -Identify file types
touch -Change file timestamps
chown -Change file owner
chgrp -Change file group
chmod -Change file protections
chattr -Change advanced file attributes
lsattr -List advanced file attributes

File Location
find -Locate files
slocate -Locate files via index
which -Locate commands
whereis -Locate standard files

File Text Manipulation
grep -Search text for matching lines
cut -Extract columns
paste -Append columns
tr -Translate characters
sort -Sort lines
uniq -Locate identical lines
tee -Copy stdin to a file and to stdout simultaneously

File Compression
gzip -Compress files (GNU Zip)
compress -Compress files (Unix)
bzip2 -Compress files (BZip2)
zip -Compress files (Windows Zip)

File Comparison
diff -Compare files line by line
comm. -Compare sorted files
cmp -Compare files byte by byte
md5sum -Compute checksums

Disks and Filesystems
df -Show free disk space
mount -Make a disk accessible
fsck -Check a disk for errors
sync -Flush disk caches

Backups and Remote Storage
mt -Control a tape drive
dump -Back up a disk
restore -Restore a dump
tar -Read/write tape archives
cdrecord -Burn a CD
rsync -Mirror a set of files

Printing
lpr -Print files
lpq -View print queue
lprm -Remove print jobs

Spelling Operations
look -Look up spelling
aspell -Check spelling interactively
spell -Check spelling in batch

Processes
ps -List all processes
w -List user’s processes
uptime -View the system load
top -Monitor processes
xload -Monitor system load
free -Display free memory
kill -Terminate processes
nice -Set process priorities
renice -Change process priorities

Scheduling Jobs
sleep -Wait for some time
watch -Run programs at set intervals at Schedule a job
crontab -Schedule repeated jobs

Hosts
uname -Print system information
hostname -Print the system’s hostname
ifconfig -Set/display network information
host -Look up DNS
whois -Look up domain registrants
ping -Check if host is reachable
traceroute -View network path to a host

Networking
ssh -Securely log into remote hosts
telnet -Log into remote hosts
scp -Securely copy files between hosts
sftp -Securely copy files between hosts
ftp -Copy files between hosts
evolution -GUI email client
mutt -Text-based email client
mail -Minimal email client
mozilla -Web browser
lynx -Text-only web browser
wget -Retrieve web pages to disk
slrn -Read Usenet news
gaim -Instant messaging/IRC
talk -Linux/Unix chat
write -Send messages to a terminal
mesg -Prohibit talk/write

Audio and Video
grip -Play CDs and rip MP3s
xmms -Play audio files
cdparanoia -Rip audio
audacity -Edit audio
xcdroast -Burn CDs


References:
1) http://linux.about.com
2) www.linux.org

Refer above sites for more details
i.e. commands with descriptions, usage e.t.c.

Sunday, June 20, 2010

Understanding Kernel


The Linux kernel provides the basic services and device drivers used by all other programs running on a Linux OS system as we can see in the diagram.

The kernel is the part of the Operating System(OS) that interacts directly with the hardware of computer through device drivers that are built into the kernel. It provides set of services that can be used by programs insulating these programs from the underlying hardware.

Major functions of kernel are:

1. to manage computer memory

2.to control acces to the computer

3.to maintain file system

4.to handle interrupts

5.to handel errors

6.to perform input and output services(which allows computers to interact with terminals storage devices and printers) and

7.to allocate the resources of the computer(such as CPU and input/output devices) among users.




History Of Linux

The History of Linux began in 1991 with the commencement of a personal project by, Linus Torvalds (a Finnish student) to create a new operating system kernel. Since then the resulting Linux kernel has been marked by constant growth throughout its history. Since the initial release of its source code in 1991, it has grown from a small number of C files under a license prohibiting commercial distribution to its state in 2009 of over 370 megabytes of source under the GNU (General Public License).

See this too....
1) Free Unix!
Starting this Thanksgiving I am going to write a complete Unix-compatible software system called GNU (for Gnu's Not Unix), and give it away free (1) to everyone who can use it. Contributions of time, money, programs and equipment are greatly needed...

- Richard Stallman; Posting to net.unix-wizards; 27 Sept. 1983.


2) Hello everybody out there using minix - I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones... I'd like to know what features most people would want. Any suggestions are welcome, but I won't promise I'll implement them :-)

- Linus Torvalds; Posting to comp.os.minix; 25 Aug. 1991.