Linux Basics





we start to learn basic linux with the commonly used commands.





Following command gives a list of files and directories in a long listing (even hidden files will be displayed), human readable sizes, KB, MB.



[root@pim /]# ls -l -h -a




Following command captures lines showing directories only page by page, to check for files use ^f. (This ^ d or ^f is NOT ctrl-d or ctrl-f)


[root@pim /]# ls -l | grep “^d” | less




To check for free space on your partitions:


[root@pim /]# df -h


To check for the used space by a particular directory:


[root@pim /]# du –c –h /home/Hashir
or
[root@pim /]# du –s –h /home/Hashir




Mounting / un-mounting floppies / cd-rom / directories :


To check for currently mounted partitions, use mount command without any arguments:


[root@pim /]# mount


You can also use the mounted files system table mtab to check for currently mounted partitions.


[root@pim /]# cat /etc/mtab


Following command mounts the floppy drive in mount point /mnt/floppy




[root@pim /]# mount /dev/fd0 /mnt/floppy


Similarly


[root@pim /]# mount /dev/cdrom /mnt/cdrom




Following command mounts your VFAT partition, C: drive, in /mnt/windir


[root@pim /]# mount -t vfat /dev/hda2 /mnt/windir


Following command mounts an NFS share /usr/SLES11 from the machine 192.168.0.20 to your local mount point /mnt/myfolder:


[root@pim /]# mount –t nfs 192.168.0.20:/usr/sles11 /mnt/myfolder


To unmount any mount point use the following command but the mount point must not be busy:


[root@pim /]# umount /mnt/myfolder


File copying / moving / renaming / deletion / compression and decompression:


Following command copies all (non-hidden) files, including any subdirectories from /home/Hashir to /mnt/myfolder


[root@pim /]# cp /home/Hashir/* /mnt/myfolder


The above command will change the ownership of the newly copied files on /mnt/myfolder to the uid and gid of the user issuing the copy (cp) command, in this case the user root. To preserve the file permissions while copying to the new location, use the -p switch as well. For example:


[root@pim /]# cp -v -r -p /home/Hashir/* /mnt/myfolder/


Following command deletes all files, including subdirectories, forcefully (without asking yes/no) from the directory /tmp.


[root@pim /]# rm -fr /tmp/*


Following command creates a tar file in /tmp as mytar.tar from the files in current directory


[root@pim /]# tar cvf /tmp/mytar.tar *


Following command extract the tar file mytar.tar from /tmp in current directory


[root@pim /]# tar xvf /tmp/mytar.tar


Following command extract the tar file mytar.tar from /tmp in /backup/restore


[root@pim /]# tar xvf /tmp/mytar.tar -C /backup/restore




Disk checking and formatting:


List of all partitions on all attached hard drives (both SCSI and IDE)


[root@pim /]# fdisk -l


To resize partitions use:


[root@pim /]# parted


Following command formats a floppy disk in ext2 format, also checks for and marks, bad sectors


[root@pim /]# mke2fs -c /dev/fd0


Following command formats a floppy disk in dos format


[root@pim /]# mkdosfs /dev/fd0


Following command checks for errors on the partition, the partition being checked should be in unmounted state during check.


[root@pim /]# e2fsck /dev/hda3
or
[root@pim /]# fsck -t ext2 /dev/hda3


Process management: 


Following command shows the list of all running processes with their process ids (PID), even owned by other users:


[root@pim /]# ps aux | less


You can also use pstree :


[root@pim /]# pstree


Following command will kill a specific process, say process id 12432:


[root@pim /]# kill 12432
or
[root@pim /]# kill –s KILL 12432
or
[root@pim /]# kill –KILL 12432
or
[root@pim /]# kill –9 12432


User Management and file permissions / ownerships: 


To add a new group called database use:


[root@pim /]# groupadd database


To add new user Hashir and make him a member of the group database, use:


[root@pim /]# useradd -s /bin/bash -g database Hashir


To change the password of user, run the following command:


[root@pim /]# passwd Hashir


To lock the password of user Hashir, run the following command as root:


[root@pim /]# passwd -l Hashir


To un-lock the password of user Hashir, run the following command as root:


[root@pim /]# passwd -u Hashir


To delete a user say Hashir, including his home directory, use:


[root@pim /]# userdel -r Hashir


To change permissions of an object (file or directory), use chmod:


[root@pim /]# chmod 770 myfile.txt


(changes the permissions of the file to rwx for both owner and group)
or
[root@pim /]# chmod ug+rwx,o-rwx myfile.txt


To change ownership of a directory /project to Hashir and set the group permissions to the group database, use chown (-R will change ownership of all files and subdirectories under the directory project:


[root@pim /]# chown –R Hashir:database /project




Package management : 


Following command lists all the currently installed packages and captures only those lines which have the word samba in them


[root@pim /]# rpm -qa | grep samba


or


[root@pim /]# rpm -qa sambal*


To check presence of the package 'bind' in the system, use the following command:


[root@pim /]# rpm -q bind


Following command lists all the information about the specific installed package.


[root@pim /]# rpm -qi samba


Following command lists all the documentation files and their location of a particular installed package.


[root@pim /]# rpm -qd samba


Following command lists file locations of all of the files of a particular installed package.


[root@pim /]# rpm -ql samba


Following command lists all information of the un-installed package:


[root@pim /]# rpm -qpi ymessenger-0.99.19-1.i386.rpm


Similarly,you can check the list of files a package contains, before actually installing it:


[root@pim /]# rpm -qpl ymessenger-0.99.19-1.i386.rpm


Install different programs from SLES-11 DVD If program not installed, by using the following command:


[root@pim /]# rpm -ivh /mnt/dvd/sles-11/RPMS/samba*.rpm


If an older version of the package is installed and you want to upgrade it to a new version, then use (U):


[root@pim /]# rpm -Uvh /mnt/dvd/sles-11/RPMS/samba*.rpm


Following command erases (removes / un-installs ) a specific package.


[root@pim /]# rpm -e samba




Miscellaneous:


To find help on some topic :


[root@pim /]# man samba


or


[root@pim /]# info samba


To find a file in the /mnt directory, use:


[root@pim /]# find /mnt -name “*.doc” -print


To find files and directories owned by the group database in the /mnt directory, use:


[root@pim /]# find /mnt -group database


Assuming a user left the organization and the files owned by his account name must be found and deleted for security reasons, use :


[root@pim /]# find / -user Hashir -exec rm '{}' ';'


To check for memory and swap space usage, you can use:


[root@pim /]# free


or


[root@pim /]# top


To check the system load status averages and the uptime:


[root@pim /]# uptime


To check when the system was booted last time:


[root@pim /]# who -b


To check the status of a particular service:


[root@pim /]# service samba status


check the kernel version of your system:


[root@pim /]# uname -r


find out the present working directory use:


[root@pim]# pwd

Comments

Popular posts from this blog

Create Tables in Oracle Database using TOAD

How to create Oracle stored Procedures using TOAD for Oracle

How to Create Packages in Oracle Database using TOAD for Oracle