Guest User

Untitled

a guest
Apr 22nd, 2018
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.67 KB | None | 0 0
  1. ls * list file and directory
  2. ls -l *long list file and directory , ll
  3. ls -R *listing the file and directory with recurrsive.
  4. ls -laR
  5. pwd *present working direcory
  6. cd dirname *enter a directory
  7. cd.. back one directory cd - * to enter
  8. cd ../.. *two level dir back
  9. cd/ *root partition
  10. cd and enter * to enter users home directory , "cd~"
  11. rm filename *Remove file
  12. rmdir directory_name * Remove directory (If empty)
  13. rm -r dirname *Remove directory (If not empty) (r -> recurrsive).
  14. rm -rf dirname *Remove directory and file forcefully.
  15. cp filename destination_address *to copy file.
  16. cp -a dirname destination_address *to copy directory.
  17. mv - filename/dirname newname *to rename
  18. mv - filename/dirname destination_address *to move file or directory.
  19.  
  20. Command /syntax
  21. command option argument
  22. [root@localhost Desktop]#
  23. user machine using dir root user
  24. $ Local user
  25.  
  26. useradd username or adduser username (with root permissions only)
  27. to chg password -> passwd username
  28. #newpassword ******
  29.  
  30. File System Hierarchy
  31.  
  32. / is root directory
  33. /bin user essential commands
  34. /sbin Superuser essential commands
  35. /dev to store device files
  36. /boot Its a bootloader (to store required booting file) Grub2 (Grand unified Bootloader)
  37. /etc to store configuration file.
  38. /root root user data.
  39. /tmp temporary directory (after 10 days file will be deleted automatically)
  40. /usr to install programs.
  41. /var Its a variable data (different types of files available )
  42. /var/log for logs /var/tmp after 30 days /var/spool/mail mail
  43. /run/media removable drives (For rhel 6 and old in /media directly)
  44.  
  45.  
  46. vim - Text Editor.
  47. 1.) Command Mode vim filename.
  48. 2.)Insert Mode - Edit or Modify file . press 'i' or Insert key.
  49. 3.)Ex Mode close a file with saving or not saving. ESC key
  50. to save file :wq (close file with save)
  51. :wq! (save forcefully)
  52. :q (without saving)
  53. ESC o open a new line below from cursor
  54. ESC u undo
  55. ctrl + r redo
  56. ESC n yy
  57. no of lines yy(yanked)
  58. ESC p paste copied data
  59. ESC :7,12 copy between lines
  60. Search and replace -> :%s/oldwordname/newname/g
  61. search global
  62. ESC /word_name to search a word n-> next find match word shift+n -> previous
  63. ESC :nohl No Highlighted
  64. ESC :set nu to set line numbers
  65. ESC :set nonu remove or unset line numbers
  66. ESC gg First line
  67. ESC shift+g last line
  68. ESC :line_number
  69.  
  70. View content of a file
  71. cat filename
  72. less filename view content page wise
  73. more filename view content page wise show % studied
  74. head filename (first 10 lines)
  75. head -n3 filename (first n lines)
  76. tail filename (last 10 lines)
  77. head -n3 filename (last n lines)
  78. wc filename (show line,word,size)
  79.  
  80.  
  81. Help
  82. whatis cmd_name
  83. man cmd_Name
  84. info cmd_Name more details then man
  85. which cmd_Name from where cmmd is running
  86. rpm -q -f /usr/bin/mv to know the package
  87.  
  88. Users and Groups :
  89. 3 types of users
  90. 1.) SuperUser - rootuser user Id '0'
  91. 2.)System user -to manage and create system services.
  92. 3.)Regular user/local start from 1000(RHEL7) 500(Rhel 6)
  93.  
  94. 1-201 (Static-Id) 201-999(dynamic Id)
  95.  
  96. id - current user id
  97. id username - user id
  98.  
  99. userdel -r username delete user
  100. usermod -L username
  101. usermod -U username
  102. usermod -l newname oldname
  103. chfn username - change info about user
  104. chage -l username to check age on an user
  105. chage -E "days/weeks/year" username expire
  106. chage -E -1 username unexpire
  107.  
  108. chage -m 5 -M 45 -I 3 -W 2 mustfzz *min max inactive warning
  109. chage -m 0 -M 99999 -I -1 -W 7 mustfzz *bring back to original
  110.  
  111. Group Users
  112. groupAdd group_name
  113. groupmod -n newname oldname
  114. usermod -G groupname username
  115. usermod -G groupname,group2,group3 username
  116. gpasswd -M user1,user2,user3 groupname
  117.  
  118. groupmems -g groupname -l *list of user in a group
  119. groupmems -d username -g groupname *delete user from group
  120. groups mustfzz display group info
  121.  
  122.  
  123. IT:x:1004:mustfzz
  124. groupname:password:Group_iD:list_of_users_in_group
  125.  
  126. userfields in passwd file 7
  127. username:password:user_id:group_id:user_comments:users_home_dir:users_shell
  128.  
  129. password stored in /etc/shadow stores username/password/age information
  130. shadow has 9 fields.
  131. username:password:user_creation_no_of_days:min_days:max_days:warning_days:inactive_days:user_account_age_info:future_reserve
  132.  
  133.  
  134. Linux File System Permissions
  135.  
  136. File has three categories
  137. 1.) User
  138. 2.) Group
  139. 3.) Others
  140.  
  141. UMASK controls the permission automatically
  142.  
  143. permissions r-w-x
  144. file dir
  145. r
  146. rw
  147. rwx rwx
  148. --- rx
  149.  
  150. - --- --- --- . +
  151. file_type : User_permission : Group_premission : Other_permission ACL
  152.  
  153. _ file
  154. d dir
  155. l Link File
  156. --------------------
  157. b block file |
  158. c character file | =>h/w device (in /dev)
  159. p pipe file |
  160. s socket file |
  161. --------------------
  162.  
  163. Switch User (from one to another from terminal)
  164. su - username
  165.  
  166. Symbolic
  167. ---------------
  168. who - u,g,o,a
  169. what - +,-,=
  170. which - r,w,x
  171.  
  172. cmmd/syntax - chmod whoWhatWhich file/dir_name
  173. chmod g+w file/dir_name
  174.  
  175. chmod -R whoWhatWhich file/dir_name
  176. chmod -R g+w file/dir_name
  177.  
  178. chmod go+wx file/dir
  179. chmod a+rwx file/dir
  180.  
  181. chmod g+wx,o-rx file/dir
  182. Numeric
  183.  
  184. r-4
  185. w-2
  186. x-1
  187. --0
  188.  
  189. stat file/dir show the permissions of file/dir in symbolic and numeric method
  190.  
  191. Changing User and Group Ownership
  192.  
  193. chown user/owner_name file/directory_name * change ownership
  194. chown -R user/owner_name file/directory_name * Reccurrsive
  195.  
  196. chgrp group_name file/dir
  197. chown username:groupname file/dir_name * to change user and group ownership (-R for reccurrsive)
  198.  
  199. Special Permissions
  200.  
  201. 1.) Suid (Set user id) - when only particular user can execute. this time permission apply on user execution position. (i.e. in place of --x).
  202. Symbol - 's' and no. 4 . It can only be applied to file.
  203. ex: _rwsr_xr_x
  204. chmod 4755
  205. here 4 is for special permissions.
  206.  
  207. 2.) Sgid
  208. sgid assign on group execute position that mean place of x
  209. when sgid is set on a directory then files new created in the directory have there group owner set to match the group owner of the directory.
  210.  
  211. symbol - 's' and no. 2
  212. Ex chmod 2775 directory
  213.  
  214. 3.) Sticky
  215. It assings on a directory
  216. It assign on other execute postion.
  217. When sticky is set on a directory then file/dir created under this directory , then
  218. only file/dir deleted by only owner.
  219. Symbol 't' and no. '1'
  220. EX: chmod 1757 litc/a
  221.  
  222. Break Root Password
  223. Rhel 6
  224. Enter in kernel mode by s
  225. passwt root
  226. and then Enter the new password
  227. Rhel 7
  228. ctrl+alt+del then e
  229. take to linux16 then to end and rd.break
  230.  
  231. Archiving files creating and Compressing
  232. ---------------------------------------------------------
  233.  
  234. Tar (tape archive)
  235. The archive file creates from Tar command.
  236.  
  237. tar -cvf filename.tar files/dirname
  238. create verbose file
  239. tar -tvf filename.tar
  240. to list file/dir from
  241. tar -rvf filename.tar
  242. to add files and directory if already archive file existing
  243. tar -xvf filename.tar
  244. to restore particular file and directory from archive file
  245. After Tar
  246. 1.) gzip | gzip filename.tar
  247. gunzip filename.tar.gz
  248. 2.) bzip2 | bzip2 filename.tar
  249. bunzip filename.tar.bz2
  250. 3.) xz | xz filename.tar
  251. unxz filename.tar.xz
  252.  
  253. tar -czvf filename.tar.gz file/dirname -> gzip
  254. tar -cjvf filename.tar.bz2 file/dirname -> bzip2
  255. tar -cJvf filename.tar.xz file/dirname -> xz
  256.  
  257. UMASK
  258. -------------------------------------------
  259. It is a value that controls file/dir permission.
  260. without umask file permission 666 | directory permission 777
  261. localuser mask 002 and root user mask 022
  262.  
  263. to calculate umask Default Mask - Required Mask
  264. Ex:
  265. [u1@localhost ~]$ vim ~/.bash
  266. [u1@localhost ~]$ vim ~/.bashrc
  267. add umask 007 at the end
  268.  
  269. Permanent for all user
  270. root user
  271. vim /etc/bashrc
  272. change 002 to 007
  273. Repeat the same for /etc/profile
  274.  
  275. ACL (Access Contol List)
  276. ---------------------------------------------
  277.  
  278. when we want to multiple permission assing one a single target file/dir and access by user and group then we can implement ACL.
  279.  
  280. getfacl file/dir * to get acl info
  281. setfacl -m u:username:permission file/dirname * set acl
  282. setfacl -m g:groupname:permission file/dirname * set acl
  283. on group
  284.  
  285. EX: setfacl -m u:mustfzz:rw file/dirname
  286.  
  287. setfacl -x u:username file/dirname * remove permissions
  288.  
  289. setfacl -b file/dirname * remove all acl
  290.  
  291. Link - Hard Link and Soft Link
  292. ------------------------------------------------
  293. 1.) can create only within a partition 1.) can create accross the partition
  294. 2.) Inode number will be the same 2.) Inode number are different
  295. 3.) original and link file are in same size. 3.) size is less than original file.
  296. 4.) If original file is removed then we can access the link file 4.) Link file can not be accessed
  297. 5.) Only for file 5.) for file and directory.
  298.  
  299. Link is an another name of our original file.
  300. df -TH * show partitions
  301. ls -il file/dirname * show inode number
  302.  
  303. ln file/dirname link-file/dirname
  304. unlick file/dirname * unlink and file will be deleted
  305.  
  306. Find Files and Directory
  307. ------------------------------------------
  308. by name * -name
  309. by size * -size 10m | +5m | -5m
  310. by permission * -perm 755
  311. by ownername and ownership * -user username
  312. by groupname * -group groupname
  313. by uid and gid
  314. by File-Type * -type f(file) d(directory) l(linked) b(block) c() p(pipeline) s(socket)
  315. particular extention *.txt
  316.  
  317. by no of days access time * atime 5days | +5days | - days
  318. by no of minutes * amin | mmin (m for modification time).
  319. by links * find / -type f -links 2 | +2 | -2
  320.  
  321. Search and save file
  322. find / - user mustfzz -exec cp -av {} /destination_address \;
  323. Syntax
  324. find path file/dirname * whole system
  325. find /etc file/dirname * particular directory
  326. find -name file/dirname * working directory
  327.  
  328. Using Grep
  329. --------------------------------------------------
  330. to find particular string
  331.  
  332. grep stringname filename
  333. grep --color stringname filename 8 with color for rhel 6
  334. grep ^stringname filename | start
  335. grep stringname$ filename | end
  336.  
  337. grep -e stringname -e stringname filename
  338. grep --color stringname filename >> path/filename
  339.  
  340. Sudo
  341. --------------------------------------------------
  342. Sudo gives root priveledges to the local user.
  343. If any is a member of wheel group It can execute root commands.
  344. vim /etc/sudoers
  345.  
  346. NETWORKING
  347. ----------------------------------------------------------
  348. Lan Cable
  349. 4-Pair
  350. 1) Cross-over cale
  351. 2) Straight cable
  352. 3) Roll-over cable /console cable
  353.  
  354. IP-Address
  355.  
  356. class - A 1-127
  357. class - B 128-191
  358. class - C 192-223
  359. class - D 224-239
  360. class - E 240-255
  361.  
  362. Private Ip Range
  363.  
  364. class - A 10.0.0.0
  365. 10.255.255.255
  366. class - B 172.16.0.0
  367. 172.31.255.255
  368. class - C 192.168.0.0
  369. 192.168.255.255
  370.  
  371. Subnet Mask
  372.  
  373. Its a property of IP address.
  374. CIDR
  375. class - A 255.0.0.0 /8
  376. class - B 255.255.0.0 /16
  377. class - C 255.255.255.0 /24
  378.  
  379. CIDR (Class-Less Inter Domain Routing)
  380.  
  381. Total Host and Total N/W in each classes
  382.  
  383. class A 1 00000001
  384. 127 0111111111
  385.  
  386. 2^7 = 127 N/W
  387. 2^24 = 16777216-2 = 16777214
  388.  
  389. Class B
  390. 128 10000000
  391. 191 10111111
  392. 2^14 = 16384 N\W
  393. 2^16 = 65534 Total host
  394. 65532 Valid host
  395.  
  396. Class C
  397. 192 11000000
  398. 223 10111111
  399. 2^21 = 16384 N\W
  400. 2^8 = 256 Total host
  401. 254 Valid host
  402.  
  403. CIDR (/8-/32 {/9-/30}) and Subnet Mask calculation.
  404. /8 255.0.0.0
  405. /9 255.128.0.0
  406. /10 255.192.0.0
  407. /11 255.224.0.0
  408. /12 255.240.0.0
  409. /13 255.248.0.0
  410. /14 255..252.0.0
  411. /15 255.254.0.0
  412. /16 255.255.0.0
  413. /17 255.255.128.0
  414. /18 255.255.192.0
  415. /19 255.255.224.0
  416. /20 255.255.240.0
  417. /21 255.255.248.0
  418. /22 255.255.252.0
  419. /23 255.255.254.0
  420. /24 255.255.255.0
  421. /25 255.255.255.128
  422. /26 255.255.255.192
  423. /27 255.255.255.224
  424. /28 255.255.255.240
  425. /29 255.255.255.248
  426. /30 255.255.255.252
  427.  
  428. Subnetting :
  429. To breakup large network into small using subnetting.
  430. Rules
  431. 1.) Class IP-Address
  432. 2.)Subnet MAsk
  433. 3.)Blocksize (256-Mask)
  434. 4.)Subnetwork id -(First valued Host | Last Valued Host | Broadcast Address )
  435. 5.)Total Host on each subnetwork id - 2^x-2 x= off bit of host part.
  436. 6.)Total Subnetwork id 2^y where y = on bit of host part.
  437.  
  438.  
  439. class c
  440. 1.) 192.168.10.0 /26
  441. 2.)subnet mask 255.255.255.192
  442. 11000000
  443. 3.)block size 256-192 = 64
  444. 4.)subnet id
  445. FVH LVH B/C
  446. 192.168.10.0 10.1 10.62 10.63
  447. 192.168.10.64 10.65 10.126 10.127
  448. 192.168.10.128 10.129 10.190 10.191
  449. 192.168.10.192 10.193 10.254 10.255
  450.  
  451. 5.)Total Host on each subnetwork id = 2^6-2=62
  452. 6.) TOTAL SUBNET ID 2^2 =4
  453.  
  454. Networking
  455. -----------------------------
  456. N/W address
  457. IP address
  458. Subnet Mask
  459. Gateway
  460. DNS
  461. DHCP
  462.  
  463. Rhel 6
  464. setup
  465.  
  466. service network restart
  467. cat e
Add Comment
Please, Sign In to add comment