Saturday, February 28, 2009

Class 10 The gnu-Linux File System


The first thing that most new users shifting from Windows will find confusing is navigating the Linux filesystem. The Linux filesystem does things a lot more differently than the Windows file system.This article explains the differences and takes you through the layout of the Linux filesystem.there is only a single hierarchal directory structure.Everything starts from the root directory, represented by '/', and thenexpands into sub-directories.Windows, the various partitions are detected at boot and assigned a drive letter. Under Linux, unless you mount a partition or a device, the system does not know of the existence of that partition or device. This
might not seem to be the easiest way to provide access to your partitions or devices but it offers great flexibility.

the file system can be classified accourding to the purpose
1)Sharable/Variable
2)Unsharable/Static For eg:

                    Sharable                        Unsharable
..................................................................................
Static           /usr                                    /etc                      
                    /opt                                    /boot

..................................................................................
Variable     /var/mail                             /var/run
                   /var/spool/news                  /var/lock


We cant load them in a different file system location(partition) for eg, we cant load /etc & /lib in other partiotion.it should be under / the (root).here is the list of files n directories under / for fedora linux:

bin
boot
dev
etc
home
lib
lost+found
media
mnt
opt
proc
root
sbin
selinux
srv
sys
tmp
usr
var

some explanations:
/usr->Unique System resource
/etc->Configuration files
/opt->Optional packages
/boot->boot files
/var->variable
/bin->essential executables for every user & to be used in single user mode
/sbin->essential system executables
/lib->essential shared libraries & kernel modules
/boot->static files of bootloader
/dev->device files & scripts called MAKEDEV,device types-c,h,d,b,l

the major no: & minor no: is used by kernel to identify a device
Major no:- it is an indication for which device driver should be used to acess a particular device.
Minor no:- is which tells the kernel the special characterstics of the device to be acessed.

to know the malor & minor no: of a device :- ls -la 'device name' eg: ls -la sd*

we should be familiar with the most of the files n directories under /etc. These files are of high imoprtance and should be modifiled for administration and for trouble shooting! the files n directories under /etc for fedora are:

adjtime
aliases
aliases.db
alsa
alternatives
anacrontab
anthy-conf
asound.conf
asound.state
at.deny
audisp
audit
avahi
bash_completion.d
bashrc
blkid
bluetooth
bonobo-activation
chkconfig.d
ConsoleKit
cron.d
cron.daily
cron.deny
cron.hourly
cron.monthly
crontab
cron.weekly
csh.cshrc
csh.login
cups
dbus-1
default
depmod.d
dhcp6c.conf
DIR_COLORS
DIR_COLORS.256color
DIR_COLORS.xterm
dirmngr
dnsmasq.conf
dnsmasq.d
dumpdates
enscript.cfg
environment
esd.conf
ethers
event.d
exports
favicon.png
fb.modes
fedora-release
festival
filesystems
fonts
foomatic
fstab
gconf
gcrypt
gdm
ghostscript
gimp
gnome-vfs-2.0
gnome-vfs-mime-magic
gnupg
gpm-root.conf
gpm-syn.conf
gpm-twiddler.conf
gre.d
group
group-
grub.conf
gshadow
gshadow-
gssapi_mech.conf
gtk-2.0
gtkmathview
hal
host.conf
hosts
hosts.allow
hosts.deny
httpd
idmapd.conf
init.d
initlog.conf
inittab
inputrc
iproute2
issue
issue.net
jwhois.conf
kde
kernel
kerneloops.conf
krb5.conf
ldap.conf
ld.so.cache
ld.so.conf
ld.so.conf.d
lftp.conf
libaudit.conf
libuser.conf
localtime
login.defs
logrotate.conf
logrotate.d
logwatch
lvm
mail
mailcap
mail.rc
makedev.d
man.config
mime.types
minicom.users
mke2fs.conf
modprobe.conf
modprobe.d
motd
mtab
mtools.conf
multipath.conf
netconfig
netplug
netplug.d
NetworkManager
networks
nscd.conf
nsswitch.conf
nsswitch.conf.bak
ntp
ntp.conf
obex-data-server
openldap
openvpn
opt
PackageKit
pam.d
pam_pkcs11
pam_smb.conf
pango
passwd
passwd-
pcmcia
pki
pm
pm-utils-hd-apm-restore.conf
PolicyKit
popt.d
portreserve
ppp
prelink.cache
prelink.conf
prelink.conf.d
printcap
profile
profile.d
protocols
pulse
purple
quotagrpadmins
quotatab
rc
rc0.d
rc1.d
rc2.d
rc3.d
rc4.d
rc5.d
rc6.d
rc.d
rc.local
rc.sysinit
redhat-release
resolv.conf
rmt
rpc
rpm
rsyslog.conf
rwtab
rwtab.d
samba
sane.d
sasl2
scim
scsi_id.config
securetty
security
selinux
sensors3.conf
services
sestatus.conf
setroubleshoot
setuptool.d
sgml
shadow
shadow-
shells
skel
smartd.conf
smolt
smrsh
sos.conf
sound
ssh
statetab
statetab.d
stunnel
sudoers
sysconfig
sysctl.conf
system-release
system-release-cpe
terminfo
udev
updatedb.conf
virc
vpnc
warnquota.conf
wpa_supplicant
wvdial.conf
X11
xdg
xinetd.d
xml
yp.conf
yum
yum.conf
yum.repos.d


Most of the configuration files for the system lies under /etc.  So please be sure before you edit them, or else take a back-up of it and edit to feel the changes on your system :)
tell2humanlinux@gmail.com

class 9 Answers

will be updated soon!

Thursday, February 19, 2009

Class 8 A few exercises.

Here let us do some exercises using the commands i have mentioned in the above classes.Please try yourselves, answers will be posted in next class!

1)list the last modified file at the beginning.(last modified file should be listed first)
2)descent the files according to its size.
3)to list the files and directories in a list and not in lines
4)to make directories recursively or like a tree ,one inside the other in a single command(ie a ,b inside a,c inside b ...etc)
5)needs to find all the .txt files in the current directory and copy it to a file in a single command
6)to list the files belonging to a user using uid
7)to copy all the files except the directories to a folder
8)to know the disk usage of the current folder


tell2humanlinux@gmail.com

Tuesday, February 17, 2009

Class 7 continued

cat >filename :to i/p the items to a file, but replaces the old data.
cat >>filename :will append the files,wont delete old data.
cat file1 file2 >file3 :file3 contains o/p of file file1 & file2 which are concatenated.
sort : hit enter, n type the data, n press ctrl D . it will sort the data alphabetically.
sort :will sort the contents of 'file' alphabetically.
who | sort :here a pipe '|' is used to o/p the sorted list of users.
host www.website.com : to display the static ip of a 'website'.
grep: to seach inside a file
grep -i "word" file : will search for files with "word" within a directory recursively.
grep -r "word" /etc :will search for "word" inside /etc, recursively.
grep 'word' *.c : to search for files with particular extension *.c
man heir :to know file system hierarchy.

next i wil post the file system hierarchy,some more commands n files.

tell2humanlinux@gmail.com

Saturday, February 14, 2009

Class 6 more commands!

More commands:

Here I am discussing some useful commands that might be helpful to work with,And some explanations for them.*NB: use tab to get the complete list of possible commands
for eg: if we pres tab, after typing 'trace' , will list the possible commands like
tracepath,tracepath6, traceroute, traceroute6. Then type the next letter n tab to display the correct command!

ifconfig:ifconfig (short for interface configurator) serves to configure and control TCP/IP network interfaces from a command line interface (CLI).
here is the screen short for the ifconfig command result--->

lspci:lists PCI devices in the system, pci --v gives more detailed
description.
lsusb:lists the usb port details,lsusb --v
gives more detailed description.
tty:to find the terminal location
type command :shows the type of the command "command".
eg: type reboot shows the result /sbin/reboot,(sbin will be described in the file system,later)
ls -R :recursive listing
ls -r :reverse listing of files directories
ls -lt:longlisting with last modified file at first
ls -sSt: size in bytes,Sorted,longlisting
ls -F:to classify accouirding to directories n files
ls -lh:lists in human readable format

rm -r dir :removes the directory, but wont work if it is empty.
rm -rf dir : removes the directory dir recursively and forcefully.
mkdir -p dir1 dir2 dir3 :makes directories dir1,dir2 and dir3 in a single command
findfs LABEL=/ :to search the file system using label or UUID(universially unique identifier)
dumpe2fs /dev/sda1 | more :shows the UUID for the device dev/sda1, | more is used to show the output of the first command. ' | ' is called as grep which is used to input the output of the first command.
su username : to switch the user to username,su(substitute user)
su - username :goes to the home directory of the username
less /etc/services : will lists all available ports and to which it is assigned to.
ps :shows current running process
ps -aux : all user server process
top :lists live processes

tell2humanlinux@gmail.com

Class 5 gnu-Linux basic commands

Linux Basic Commands!
There are two kinds of commands used in gnu/Linux: Built-in Shell Commands and Linux Commands.
Please note: Commands might vary somewhat in syntax and usage from one distribution of Linux to another, and from one type of shell to another. The command libraries here are provided as general references. Use the 'man command' to see how a command is used in a particular shell and on your particular Linux distribution. This session doesn't covers all commands in gnu-Linux, it just covers the basic commands used to work with for a normal user! I have categorized the commands as:
  1. FILE OPERATION COMMANDS
  2. SYSTEM INFO
  3. PROCESS MANAGEMENT
  4. FILE PERMISSIONS
  5. COMPRESSION
  6. NETWORK
  7. INSTALLATION
  8. SHORTCUTS
  9. SSH
  10. SEARCHING
1)FILE OPERATIONS:
ls – directory listing
ls -al – formatted listing with hidden files
cd dir - change directory to dir
cd – change to home
'cd -' - to goto the previous directory
cd . - current directory
cd.. - previous directory
pwd – show current directory
mkdir dir – create a directory dir
rm file – delete file
rm -r dir – delete directory dir
rm -f file – force remove file
rm -rf dir – force remove directory dir *
cp file1 file2 – copy file1 to file2
cp -r dir1 dir2 – copy dir1 to dir2; create dir2 if it doesn't exist
mv file1 file2 – rename or move file1 to file2 if file2 is an existing directory, moves file1 into directory file2
ln -s file link – create symbolic link link to file
touch file – create or update file
cat > file – places standard input into file
more file – output the contents of file
head file – output the first 10 lines of file
tail file – output the last 10 lines of file
tail -f file – output the contents of file as it grows, starting with the last 10 lines

2)SYSTEM INFO:

date – show the current date and time
cal – show this month's calendar
uptime – show current uptime
w – display who is online
whoami – who you are logged in as
finger user – display information about user
uname -a – show kernel information
cat /proc/cpuinfo – cpu information
cat /proc/meminfo – memory information
man command – show the manual for command
df – show disk usage
du – show directory space usage
free – show memory and swap usage
whereis app – show possible locations of app
which app – show which app will be run by default

3)PROCESS MANAGEMENT:
ps – display your currently active processes
top – display all running processes
kill pid – kill process id pid
killall proc – kill all processes named proc *
bg – lists stopped or background jobs; resume a
stopped job in the background
fg – brings the most recent job to foreground
fg n – brings job n to the foreground

4)FILE PERMISSIONS:
we can assign permission for every file and directories.It means that we can define a file/dir as read-only,write only,execute-only or several combinations of it.

chmod octal file – change the permissions of file
to octal, which can be found separately for user,
group, and world by adding:
● 4 – read (r)
● 2 – write (w)
● 1 – execute (x)
Examples:
chmod 777 – read, write, execute for all
chmod 755 – rwx for owner, rx for group and world
For more options, see man chmod.

5)COMPRESSION:
we can compress a file/Dir to reduce its size using just simple commands, no s/w's needed like windows,be careful with the options used.

tar cf file.tar files – create a tar named file.tar containing files
tar xf file.tar – extract the files from file.tar
tar czf file.tar.gz files – create a tar with Gzip compression
tar xzf file.tar.gz – extract a tar using Gzip
tar cjf file.tar.bz2 – create a tar with Bzip2 compression
tar xjf file.tar.bz2 – extract a tar using Bzip2
gzip file – compresses file and renames it to file.gz
gzip -d file.gz – decompresses file.gz back to file

6)
NETWORK:
netstat - to know the network status
ifconfig - to find the ip of our computer
ping host – ping host and output results
whois domain – get whois information for domain
dig domain – get DNS information for domain
dig -x host – reverse lookup host
wget file – download file
wget -c file – continue a stopped download

7)
INSTALLATION:
To Install from source:
./configure
make
make install

dpkg -i pkg.deb – install a package (Debian)
rpm -Uvh pkg.rpm – install a package (RPM)

8)
SHORTCUTS:
Ctrl+C – halts the current command
Ctrl+Z – stops the current command, resume with
fg in the foreground or bg in the background
Ctrl+D – log out of current session, similar to exit
Ctrl+W – erases one word in the current line
Ctrl+U – erases the whole line
Ctrl+R – type to bring up a recent command
!! - repeats the last command
exit – log out of current session

9)
SSH:
ssh user@host – connect to host as user
ssh -p port user@host – connect to host on port
port as user
ssh-copy-id user@host – add your key to host for
user to enable a keyed or passwordless login


10)
SEARCHING:
grep pattern files – search for pattern in files
grep -r pattern dir – search recursively for
pattern in dir
command | grep pattern – search for pattern in the
output of command
locate file – find all instances of file


*please use the commands careafully.Be caution with the options used.

For more options for the commands look 'man'.

tell2humanlinux@gmail.com