Troubleshooting

September 10, 2008 by Mohammad Mahmudul Hasan

1. Get password to enter kernel

Ø Insert the 1st CD of Linux

Ø Boot: linux rescue [Enter]

Ø Language: English [Enter]

Ø Keyboard: US [Enter]

Ø Yes/No [Enter]

Ø Continue [Enter]

Ø Ok [Enter]

Ø chroot /mnt/sysimage à to work in root user.

ü [#] vi /etc/grub.conf
password = 1234 à write this line below or upper of hide menu line

2. Get root password

ü Insert CD and take the above steps.

ü [#] vi /etc/passwd
delete password [:x: à ::]
root: x: 0:0: root: /root/bin/bash

ü Reboot the machine and login without root password and then write

ü [#] passwd à and change the root password.

Or

ü Reboot the server by Alt+ctrl+del

ü When booting option come select Linux à press e for edit run level à select Kernel (2nd option) à e à give a space and write 1 (run level) or single or single b or single boot (single user mode to change password) à Enter à b

ü After login write Passwd and give a new password root

3. Recover Linux boot loader.

ü Insert CD and take the above steps.

ü [#] fdisk –l à See the hard disk is hda or hdb

ü [#] grub-install /dev/hdc

ü [#] reboot

4. Reboot the machine during startup

ü [#] vi /etc/rc.local à This file execute during startup a machine
erase reboot or give hash before reboot to inactive the command.

ü [#] reboot


Or

ü Reboot the server by Alt+ctrl+del

ü When booting option come select Linux à press e for edit run level à select Kernel (2nd option) à e à give a space and write 1 (run level) or single or single b or single boot (single user mode to change password) à Enter à b

ü After login write vi /etc/inittab and change the run level form 0 or 6 to 3

5. Retrieve file and data loss due to power loss before save the file.

ü During editing a file if the power goes down before save it the file will save as .abc.swp format where abc is the original file name.

ü [#] vi -r abc à To recover the file and it’s data

ü [#] rm .abc.swp à Delete the .swp file that created for power loss.


6. dsafda



Basic Command

September 10, 2008 by Mohammad Mahmudul Hasan

Linux Command

  • Linux is multi user & multi task Operating System.
  • Alt + F1 to Alt+F6 à Console Mode. (By default)
  • Alt + F7 à Graphical Mode. (By default)
  • [root@ns1 ~]# à Here root is User name, ns1 is Host name
  • # à Super user. Have access to all application.
  • $ à Normal user. Do not have access to all application

System Information

1. [# $] tty à Type of terminal. Display the current working terminal.

2. [# $] logout, exit, Ctrl+d à Exit form the login user.

3. [# $] clear, Ctrl+L à Clear screen.

4. [# $] date à Display Operating System date and time.

5. [#] hwclock à Display BIOS date and time.

6. [# $] date 021520522008.35 –> Edit Operating System year, date, time

Format- MM DD HH mm YYYY.sec (second is optional).

7. [#] hwclock – -systohc à Edit BIOS (hardware) time from OS time then reboot machine.

8. [#] hwclock – -hctosys à Edit OS time from BIOS (hardware) time then reboot machine.

9. [# $] history à Display the command used previously.

10. [# $] history 5 à Display the last 5 command used previously.

11. [# $] !10 à Execute the number 10 history command.

12. [# $] !p à Execute the most recent command that have an alphabet p

13. [# $] history –c à Clear history.

14. [# $] cal à Display the current month calendar.

15. [# $] cal 2 2001 à Display calendar of February 2001

16. [# $] cal 2 à Display calendar of year 2 (12 month)

17. [# $] bc à Calculator (press 12+15 à Enter, result =28)
quit à exit from calculator

18. [# $] man à Manual. Ex – man cal (give the manual of calendar).

19. [# $] init 0 à shutdown now
poweroff à shutdown now
shutdown –h now à shutdown now
shutdown –h 0 à shutdown now
shutdown –h 10 à shutdown after 10 minutes.
halt –p à shutdown now

20. [# $] init 6 à reboot now
reboot à reboot now
shutdown –r now à reboot now
shutdown –r 0
à reboot now
shutdown –r 10 à reboot after 10 minutes.
Alt + Ctrl + Delete à reboot now

21. [# $] Ctrl + C à Cancel Shutdown and Reboot

22. [# $] Shift + Page UP à Page UP

23. [# $] wall à Send message to every console. Ex- wall welcome (“welcome”
message is send to all working terminal) or Ex – wall “dmidexcode –q”.

24. [# $] w à USER TTY FROM LOGIN (time) IDLE JCPU PCPU WHAT
who
à root tty1 April 12 21:24
finger
à Login Name Tty Idle Login Time Office OfficePhone
users à mahmud root

25. [# $] finger mahmud à Display user mahmud is exist or not and display its folder
information.

26. [#] fdisk –l à [fixed disk]. Display the hard drive information.

27. [# $] free –m à Display free memory of RAM and Swap.

28. [# $] df –h à [d - Disk, f – free, h - human readable.] Display Linux Drive space
Information.

29. [# $] du –sh /home/Alex à [s- summary, h-human readable]. Display the
summary of space used of /home/Alex directory.

30. [# $] du –h /home/Alex à [h-human readable]. Display the details space use sage
of /home/Alex directory.

31. [# $] cat /proc/cpuinfo à Display CPU (processor) information.

32. [# $] cat /proc/meminfo à Display memory of RAM & Swap information.

33. [# $] cat /proc/partitions à Display partition information of Hard Disk.

34. [# $] cat /proc/version à Display OS (Linux) version.

35. [# $] uname –r à Display kernel version.

36. [# $] top à Display Linux Task Manager.
Z à Display Colored files.
q à Exit form Task Manager.

37. [# $] eject à Open CD-ROOM.

38. [# $] eject –t à Close CD-ROOM.

39. [# $] startx à Go to graphical mode.

40. [# $] init 5 à Go to graphical mode.

41. [# $] pwd à Display present working directory.

42. [# $] hostname à Display the Host name.

43. [# $] ls à Display list of files and directories under the working directory.

44. [# $] ls –l à Display long list of file and directories under the working directory.

45. [# $] ls –l test à Display long list of file [test] under the working directory.

46. [# $] ls –ld test or alex à Display long list of file [test] and directory [alex]
under the working directory.

47. [# $] ls –la à Display also hidden files and directories under the working directory.

48. [# $] cd / à Go to root directory.

49. [# $] cd /home à Go to home directory.

50. [# $] cd .. à Go to previous directory.

51. [# $] ./test à Run a test file from current Directory

52. [# $] ../test à Run a test file form Parent Directory.

User Add, delete and lock

All user account information is store in Home directory.

53. [#] useradd mahmud à Add the user named mahmud
[#] passwd mahmud à Create/Change password of mahmud (doesn’t need
user’s current password).
New Password:
Retype Password:

54. [$] password à Change password of logging User.
Current password:
New Password:
Retype Password:

55. [#] useradd –ou 0 alex à [o=duplicate, u =user, 0 (zero) =user id]. Give super
power when create the user alex
[#] passwd mahmud à Give password to super user alex
New Password:
Retype Password:

56. [#] userdel mahmud à Delete user mahmud without delete the directory of user
mahmud located in Home directory.

57. [#] userdel –r mahmud à Delete user mahmud with delete the directory of user
mahmud located in Home directory.

58. [#] passwd –l mahmud à Lock user mahmud

59. [#] passwd –u mahmud à Unlock user mahmud

60. [$] su - à Switch user (root)/ super user.

[#] Password: à Give password of root.
[#] exit à Exit form root and go to previous normal user.

61. [# $] su mahmud à Switch to user mahmud for login.

62. [#] chfn usernameà [Ex – chfn mahmud] Change the information of user- name,
address, phone number etc.

Create Group and User under the group

[#] groupadd aktel à Create a group named aktel
[#] useradd –g aktel mahmud à Create a user named mahmud under aktel group.

[#] useradd -g aktel -d /home/aktel mahmud à Create user under specific directory.

[#] passwd mahmud à Give password to user mahmud.

New password:
Retype password:

63. [#] vi /etc/group à Display the group list.

64. [#] gpasswd –a username groupname à [Ex- gpasswd –a mhamud aktel].
Display the user under its group in /etc/group directory.

Create File, Hidden file, Link file, Directory

65. [#$] touch abc à Create empty file, name abe under pwd.

66. [#$] touch abc xyz à Create 2 empty file, name abc and xyz under pwd.

67. [#$] touch “video song” or touch video\ song à create empty file video song.

68. [#$] touch .abc or vi .abc à Create hidden file named abc

69. [#$] mkdir Folder1 à Create folder, name Folder1 under pwd.

70. [#$] mkdir F1 F2 à Create 2 folder, name F1 and F2 under pwd.

71. [#$] mkdir “video song” or mkdir video\ song à create folder, name video song.

72. [#$] mkdir F1/F2 à Create folder F1 & F2 but F2 under F1.

73. [#$] mkdir –p F1/F2/F3 à Create folder F1, F2 & F3 but F3àF2àF1.

74. [#$] mkdir /home/sum/F1 à Create folder F1 under /home/sum directory.

Create Link file ( Shortcut in Windows)
[$#] ln –s sourcefile destinationfile
[$#] ln –s /home/Alex/abc /temp/abc à If we edit any link file then both source
and destination file will edited. If we delete source file then destination file will
be deleted. If we delete destination file then there will be no effect in source file.
[$#] ln –s /home/Alex /temp/* à Link all file form Alex directory.
[$#] ln –d /home/Alex/song /temp/song à Link directory of song folder.
[$#] unlink /temp/abc à Unlink the destination abc file.

Copy, Move, Delete, Rename file and directory

75. [#$] cp abc /temp à [cp source destination]. Copy abc file form current
directory to /temp.

76. [#$] cp /home/mahmud/abc /temp/Alex à Copy abc file from /home/mahmud
directory to /temp/Alex directory.

77. [#$] cp abc def à Copy abc to def file when abc and def are in same directory. If
def file does not exist in current directory then create a new file named def and
copy the file to it.

78. [#$] cp –r F2 F1 à Copy folder F2 in F1 when they are in same directory.

79. [#$] cp *.out /home/mahmud à Copy all .out extension file to mahmud.

80. [#$] mv /home/abc /temp/new/xyz à Move abc file from /home directory to
/temp/new directory by name xyz if xyz file is exist in destination folder
otherwise rename new.

81. [$#] mv sum /home/mahmud à Move sum folder to /home/mahmud directory.

82. [#$] mv new old à Rename file new to old in same directory.

83. [#$] rm abc à Remove abc file.

84. [#$] rm –r new à Remove folder named new

85. [#$] rm –fr new à Forcefully remove folder named new, don’t ask to delete
subdirectory of new folder.

86. [#$] rm * à Delete all file form current directory.

[#$] rm * .in à Delete all file that have .in extension from current directory.

87. Display permissions (read, write, Execute ) of a file or directory

[#] vi /home/mahmud
[#] ls –l

- rw- r- - r- – 1 mahmud aktel 26 Feb 21:39
[-] [- - -] [- - -] [- - -] 1 mahmud aktel 26 Feb 21:39

Here

[-] à Type of file d = directory/ folder.
- = ordinary file/ normal file
l = link file.

[- - -] à Owner permission
[r w x] à r = read, w = write, x = Execute

[- - -] à Group permission. User under the group.
[r w x] à r = read, w = write, x = Execute

[- - -] à Other permission. User excluded owner and its group.
[r w x] à r = read, w = write, x = Execute

r = 4
w = 2
x = 1
———-
Total 7

88. Give permission to all kind of users.

[#] chmod u+x abc à [u=owner], Give permission to the owner of the file to
execute abc file.

[#] chmod u-w abc à [u=owner], Take permission from owner to write abc file.

[#] chmod g+w xyz à [g=group], Give permission to other user of the same group
to write xyz file.

[#] chmod o+r abc à [o=other],Give permission to other user to read abc file.

[#] chmod u+rwx abc à Give permission to the owner of the file to read, write
and execute the abc file.

[#] chmod ugo+x abc à Give permission to the owner, group and other users to
execute the abc file under current working directory.

[#] chmod +x /home/mahmud/abc à Give permission to all user (owner, group,
other) to execute the abc file under /home/mahmud.

[#] chmod ugo+rwx abc or chmod +rwx abc or chmod 777 abc à Give permission
to the owner, group, other user of to read, write and execute the abc file.

89. Mount CD Room/ Writer, DVD Room/ Writer, Flash memory, HDD.

Mount CD Room/DVD Rom

ü [#] mount /media/cdrom àFedora & Enterprise
mount /media/cdrecoder
à for cd writer. User tab
mount /media/dvdrom
à for dvd rom. Use tab
mount /media/dvdrecoder
à for dvd writer. User tab
[#] cd /media/cdrom

ü [#] mount /mnt/cdrom à Red Hat
cd /mnt/cdrom

ü [#] fdisk –l à See HDD is hda or not. If HDD is hda then CD Room must
be others like hdb/hac/had
[#] mkdir /home/cddata
[#] mount /dev/hab /home/cddata
[#] cd /home/cddata
[#] ls

ü [#] umount /media/cdrom or umount /dev/hdd or umount /home/cddata

Mount Flash Drive

ü [#] mkdir /home/pendata
[#] mount /dev/sda1 /home/pendata

ü [#] umount /dev/sda1 or umount /home/pendata

Mount HDD

ü [#] fdisk –l à show windows Drive only FAT, FAT -32, NTFS
[#] mkdir /home/Ddrive
[#] mount /dev/hda5 /home/Ddrive

ü umount /dev/hda5 or umount /home/Ddrive

90. Compress and Extract file(*.tar) and folder (*.Zip)

tar - Tape of Archive.

[#] tar –cvf etc.tar /etc à [c-create, v –verbose, f – file]. Create etc.tar file of
/etc folder in current directory.

[#] tar –xvf etc.tar à [x- extract]. Untar etc.tar file to etc folder in current
working directory. And both etc.tar and tar folder are exist.

[#] gzip etc.tar à Create etc.tar.gz file form etc.tar in PWD.
[#] gunzip etc.tar.gz à Unzip etc.tar.gz file to etc.tar file in PWD

Create command

91. [#] vi /root/.bashrc à Open .bashrc file of root (Only root user can access the
command)
alias c=clear à set c for clear
alias 12=pwd
à set 12
unalias c
à diactive the command c for clear
:x !

ü Logout and Login by root user to activate the alias command.

[#] vi /home/mahmud/.bashrc à Open .bashrc file of user mahmud (Only user
mahmud can access the command).

92. [#] vi /etc/skel/.bashrc à All user can access the command.

Shell Script

(Create command; create a command using combination of some command)

93. [#] vi cdrom

#!/bin/bash
eject
à Open the cdrom
sleep 5
à Wait 5 second
eject –t
à Close cdrom
:x !

Or

[#] vi cdrom
#! /bin/bash
eject; sleep 5; eject –t

:x !

[#] bash cdrom à Execute file from current directory without execute permission
[#] bash /hom/cdrom à Execute file from current directory without execute permission
[#] ls –l à See the file is executable or not. If not executable write command.
[#] chmod +x cdrom à give executable permission to cdrom.
[#] /home/cdrom à Write the path of the file to execute it.
[#] ./cdrom à Execute file from current directory.
[#] ../cdrom à Execute file from parent directory.

Ø After move the file to /user/bin then only we writer the file name except path to
execute the file command

[#] mv cdrom /usr/bin
[#] mv cdrom /usr/bin/cdrom

Usually the location of command is
/bin
/sbin
/usr/bin
/usr/sbin
/usr/local/bin

/usr/local/sbin

94. [#$] date > a.txt à Create a file named a.txt in PWD and Copy system date to a.txt

95. [#$] cal 2 2007 > a.txt à Overwrite the calendar in a.txt.

96. [#$] cal 2 2007 >> a.txt à Append or Add calendar after the previous text.

97. [#$] date > a.txt; cal >> a.txt [not date;cal>> a.txt]

98. [#$] echo “Linux patshala” à Display Linux patshala in the screen.

99. [#$] echo 1 > a.txt à 1 is write in a.txt file.

100. Write the things in a file named a.txt and display the things in screen.

********************
System date
——————————-
Calendar of January 2008
********************

[#$] echo “***************” > a.txt
[#$] date >> a.txt
[#$] echo “———————–“ >> a.txt
[#$] cal 1 2008 >> a.txt
[#$] echo “***************” >> a.txt
[#$] cat a.txt

Software install, update and uninstall
rpm – Red Hat Package Manager (*.rpm where *.exe for windows)

101. [#$] rpm –qa à [q- query, a- all]. Display the software installed in Linux.

102. [#$] rpm –qa | grep sendmail à Display the sendmail software is installed or not.

103. [#$] rpm –qa sendmail à Display the exact sendmail software is installed or not.

104. Display how many package installed in Linux.
[#$] rpm –qa > r.txt
[#$] wc –l r.txt
or
[#$] rpm –qa | wc –l

105. [#] rpm –ivh abc.rpm à [i- install, v-verbose, h-hash (#)]. Install package

106. [#] rpm –Uvh abc.rpm à [U- upgrade]. Upgrade abc.rpm package. If abc.rpm
package is installed then upgrade it, if not install then install abc.rpm

107. [#] rpm – ivh – -nodeps abc.rpm à Install abc.rpm package without dependency
of another package. [def.rpmàxyz.rpmà abc.rpm]

108. [#] rpm -e abc.rpm à Uninstall abc.rpm package.

109. [#] rpm -e – -nodeps abc.rpm à Uninstall abc.rpm package without dependency.

110. [#$] ps –a à[p-process, s-status, a-all]. Dsplay process ID that are running in TTY

111. [#] kill -9 1960 à [9-priority (0-10) to a process, 1960- process ID]. Kill a process
which has process ID – 1960.

Schedule Task (Cron)

112. [#] crontab –l à Display list of task in schedule.

113. [#] crontab –e à Edit schedule task list.

114. [#] crontab –r à Remove all jobs from schedule task.

MH HD DM MY DW
Minute Hour Date Month Weak Command
[0-59] [0-23] [1-31] [1-12] [0-6] reboot

115. [#] vi /etc/crontab

5 * * * * reboot
à Reboot machine 5 minute of every hour.
5 9 1 12 * reboot root reboot à Reboot machine 9:05 minute of 01 December
by root user. All time are system time
5,10,15 * * * * reboot à Reboot machine 5, 10, 15 minute of every hour.
0-59/5 * * * * reboot à Reboot machine after 5 minute of every hour.
0-59/7 * * * * reboot à Reboot machine after 7 minute of every hour.
5 0-23/2 * * * reboot à Reboot machine after 2 hour & 5 minutes of every day.
:x !

116. To execute the schedule task below command should be write

[#] service crond stop
[#] service crond start
or
[#] service crond restart
or
[#] service crond reload
or
[#] /etc/init.d/crond stop
[#] /etc/init.d/crond start
or
[#] /etc/init.d/crond stop
[#] /etc/init.d/crond start


Linux

September 8, 2008 by Mohammad Mahmudul Hasan

This topic cover linux documentation.

OSI Layer

September 8, 2008 by Mohammad Mahmudul Hasan

7 OSI layer

Networking

September 8, 2008 by Mohammad Mahmudul Hasan

This topic cover network document.