Ṣakoso awọn faili Ni lilo daradara ni ori, iru ati awọn Agbo ologbo ni Lainos
Ọpọlọpọ awọn ofin ati awọn eto ti a pese nipasẹ Lainos fun wiwo awọn akoonu ti faili. Ṣiṣẹ pẹlu awọn faili jẹ ọkan ninu iṣẹ ṣiṣe ti n bẹru, pupọ julọ awọn olumulo kọnputa jẹ tuntun, olumulo deede, olumulo ti o ni ilọsiwaju, Olùgbéejáde, abojuto, ati bẹbẹ lọ n ṣe. Ṣiṣẹ pẹlu awọn faili daradara ati daradara jẹ aworan kan.
Loni, ninu nkan yii a yoo jiroro lori awọn ofin ti o gbajumọ julọ ti a pe ni ori, iru ati o nran, pupọ julọ wa ti mọ tẹlẹ si awọn iru awọn ofin bẹẹ, ṣugbọn diẹ diẹ ninu wa lo n ṣe nigba ti o nilo.
1. ori Commandfin
Aṣẹ ori ka awọn ila mẹwa akọkọ ti eyikeyi orukọ faili ti a fun. Iṣeduro ipilẹ ti aṣẹ ori ni:
head [options] [file(s)]
Fun apẹẹrẹ, aṣẹ atẹle yoo han awọn ila mẹwa akọkọ ti faili ti a npè ni '/ etc/passwd'.
# head /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh
Ti o ba fun ni ju faili kan lọ, ori yoo fihan awọn ila mẹwa akọkọ ti faili kọọkan lọtọ. Fun apẹẹrẹ, aṣẹ atẹle yoo fihan awọn ila mẹwa ti faili kọọkan.
# head /etc/passwd /etc/shadow ==> /etc/passwd <== root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin ==> /etc/shadow <== root:$6$85e1:15740:0:99999:7::: bin:*:15513:0:99999:7::: daemon:*:15513:0:99999:7::: adm:*:15513:0:99999:7::: lp:*:15513:0:99999:7::: sync:*:15513:0:99999:7::: shutdown:*:15513:0:99999:7::: halt:*:15513:0:99999:7::: mail:*:15513:0:99999:7::: uucp:*:15513:0:99999:7:::
Ti o ba fẹ lati gba nọmba awọn ila diẹ sii ju mẹwa aiyipada lọ, lẹhinna a ti lo aṣayan ‘-n‘ papọ pẹlu odidi odidi kan ti n sọ nọmba awọn ila lati gba pada. Fun apẹẹrẹ, aṣẹ atẹle yoo han akọkọ awọn ila 5 lati faili '/var/log/yum.log' faili.
# head -n5 /var/log/yum.log Jan 10 00:06:49 Updated: openssl-1.0.1e-16.el6_5.4.i686 Jan 10 00:06:56 Updated: openssl-devel-1.0.1e-16.el6_5.4.i686 Jan 10 00:11:42 Installed: perl-Net-SSLeay-1.35-9.el6.i686 Jan 13 22:13:31 Installed: python-configobj-4.6.0-3.el6.noarch Jan 13 22:13:36 Installed: terminator-0.95-3.el6.rf.noarch
Ni otitọ, ko si iwulo lati lo aṣayan '-n'. O kan awo ki o pato nọmba odidi laisi awọn aye lati gba abajade kanna bi aṣẹ ti o wa loke.
# head -5 /var/log/yum.log Jan 10 00:06:49 Updated: openssl-1.0.1e-16.el6_5.4.i686 Jan 10 00:06:56 Updated: openssl-devel-1.0.1e-16.el6_5.4.i686 Jan 10 00:11:42 Installed: perl-Net-SSLeay-1.35-9.el6.i686 Jan 13 22:13:31 Installed: python-configobj-4.6.0-3.el6.noarch Jan 13 22:13:36 Installed: terminator-0.95-3.el6.rf.noarch
Aṣẹ ori tun le ṣe afihan eyikeyi nọmba ti o fẹ ti awọn baiti nipa lilo aṣayan '-c' atẹle nipa nọmba awọn baiti lati han. Fun apẹẹrẹ, aṣẹ atẹle yoo han awọn baiti akọkọ 45 ti faili ti a fun.
# head -c45 /var/log/yum.log Jan 10 00:06:49 Updated: openssl-1.0.1e-16.el
2. iru Commandfin
Ofin iru gba ọ laaye lati ṣe afihan awọn ila mẹwa to kẹhin ti eyikeyi faili ọrọ. Iru si aṣẹ ori loke, aṣẹ iru tun ṣe atilẹyin awọn aṣayan ‘n‘ nọmba awọn ila ati ‘n‘ nọmba awọn kikọ.
Iṣeduro ipilẹ ti aṣẹ iru ni:
# tail [options] [filenames]
Fun apẹẹrẹ, aṣẹ atẹle yoo tẹ awọn ila mẹwa to kẹhin ti faili kan ti a pe ni 'access.log'.
# tail access.log 1390288226.042 0 172.16.18.71 TCP_DENIED/407 1771 GET http://download.newnext.me/spark.bin? - NONE/- text/html 1390288226.198 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html 1390288226.210 1182 172.16.20.44 TCP_MISS/200 70872 GET http://mahavat.gov.in/Mahavat/index.jsp pg DIRECT/61.16.223.197 text/html 1390288226.284 70 172.16.20.44 TCP_MISS/304 269 GET http://mahavat.gov.in/Mahavat/i/i-19.gif pg DIRECT/61.16.223.197 - 1390288226.362 570 172.16.176.139 TCP_MISS/200 694 GET http://p4-gayr4vyqxh7oa-3ekrqzjikvrczq44-if-v6exp3-v4.metric.gstatic.com/v6exp3/redir.html pg 1390288226.402 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html 1390288226.437 145 172.16.18.53 TCP_DENIED/407 1723 OPTIONS http://172.16.25.252/ - NONE/- text/html 1390288226.445 0 172.16.18.53 TCP_DENIED/407 1723 OPTIONS http://172.16.25.252/ - NONE/- text/html 1390288226.605 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html 1390288226.808 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html
Ti o ba ti pese faili to ju ọkan lọ, iru yoo tẹ awọn ila mẹwa to kẹhin ti faili kọọkan bi a ṣe han ni isalẹ.
# tail access.log error.log ==> access.log <== 1390288226.042 0 172.16.18.71 TCP_DENIED/407 1771 GET http://download.newnext.me/spark.bin? - NONE/- text/html 1390288226.198 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html 1390288226.210 1182 172.16.20.44 TCP_MISS/200 70872 GET http://mahavat.gov.in/Mahavat/index.jsp pg DIRECT/61.16.223.197 text/html 1390288226.284 70 172.16.20.44 TCP_MISS/304 269 GET http://mahavat.gov.in/Mahavat/i/i-19.gif pg DIRECT/61.16.223.197 - 1390288226.362 570 172.16.176.139 TCP_MISS/200 694 GET http://p4-gayr4vyqxh7oa-3ekrqzjikvrczq44-if-v6exp3-v4.metric.gstatic.com/v6exp3/redir.html pg 1390288226.402 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html 1390288226.437 145 172.16.18.53 TCP_DENIED/407 1723 OPTIONS http://172.16.25.252/ - NONE/- text/html 1390288226.445 0 172.16.18.53 TCP_DENIED/407 1723 OPTIONS http://172.16.25.252/ - NONE/- text/html 1390288226.605 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html 1390288226.808 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html ==> error_log <== [Sun Mar 30 03:16:03 2014] [notice] Digest: generating secret for digest authentication ... [Sun Mar 30 03:16:03 2014] [notice] Digest: done [Sun Mar 30 03:16:03 2014] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.0-fips configured -- resuming normal operations
Bakan naa, o tun le tẹ awọn ila diẹ ti o gbẹhin ni lilo aṣayan '-n' bi a ṣe han ni isalẹ.
# tail -5 access.log 1390288226.402 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html 1390288226.437 145 172.16.18.53 TCP_DENIED/407 1723 OPTIONS http://172.16.25.252/ - NONE/- text/html 1390288226.445 0 172.16.18.53 TCP_DENIED/407 1723 OPTIONS http://172.16.25.252/ - NONE/- text/html 1390288226.605 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html 1390288226.808 0 172.16.16.55 TCP_DENIED/407 1753 CONNECT ent-shasta-rrs.symantec.com:443 - NONE/- text/html
O tun le tẹ nọmba awọn ohun kikọ silẹ nipa lilo ariyanjiyan '-c' bi a ṣe han ni isalẹ.
# tail -c5 access.log ymantec.com:443 - NONE/- text/html
3. o nran Commandfin
A ti lo aṣẹ 'o nran' ni ibigbogbo, irinṣẹ agbaye. O ṣe idawọle igbewọle boṣewa si iṣẹjade boṣewa. Aṣẹ naa ṣe atilẹyin yiyi lọ, ti faili ọrọ ko baamu iboju lọwọlọwọ.
Iṣeduro ipilẹ ti aṣẹ ologbo ni:
# cat [options] [filenames] [-] [filenames]
Lilo loorekoore ti o nran ni lati ka awọn akoonu ti awọn faili. Gbogbo ohun ti o nilo lati ṣii faili kan fun kika ni lati tẹ ologbo atẹle pẹlu aaye ati orukọ faili naa.
# cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh lp:x:7:7:lp:/var/spool/lpd:/bin/sh …
Agbo ologbo tun lo lati ṣe apejọ nọmba awọn faili papọ.
# echo 'Hi Tecmint-Team' > 1 # echo 'Keep connected' > 2 # echo 'Share your thought' > 3 # echo 'connect us [email ' > 4
# cat 1 2 3 4 > 5
# cat 5 Hi Tecmint-Team Keep connected Share your thought connect us [email
O tun le lo lati ṣẹda awọn faili bakanna. O ti ṣaṣeyọri nipasẹ ṣiṣe ologbo atẹle nipasẹ onišẹ redirection o wu ati orukọ faili lati ṣẹda.
# cat > tecmint.txt Tecmint is the only website fully dedicated to Linux.
A le ni oluṣe opin aṣa fun aṣẹ ‘ologbo’. Nibi o ti ṣe imuse.
# cat > test.txt << end I am Avishek Here i am writing this post Hope your are enjoying end
# cat test.txt I am Avishek Here i am writing this post Hope your are enjoying
Maṣe foju si agbara aṣẹ ‘ologbo’ ati pe o le wulo fun didakọ awọn faili.
# cat avi.txt I am a Programmer by birth and Admin by profession
# cat avi.txt > avi1.txt
# cat avi1.txt I am a Programmer by birth and Admin by profession
Bayi kini idakeji ti o nran? Bẹẹni o jẹ 'tac'. 'Tac' jẹ aṣẹ labẹ Linux. O dara lati fi apẹẹrẹ ti ‘tac’ han ju lati sọrọ ohunkohun nipa rẹ.
Ṣẹda faili ọrọ pẹlu awọn orukọ ti gbogbo oṣu, iru ọrọ kan ni o han loju ila kan.
# cat month January February March April May June July August September October November December
# tac month December November October September August July June May April March February January
Fun awọn apẹẹrẹ diẹ sii ti lilo pipaṣẹ ologbo, tọka si Lilo pipaṣẹ 13 o nran
Iyẹn ni gbogbo fun bayi. Emi yoo wa nibi lẹẹkansi pẹlu Nkan Nkan miiran ti o nifẹ, o tọ si Mọ. Titi lẹhinna wa ni aifwy ati sopọ si Tecmint. Maṣe gbagbe lati pese wa pẹlu awọn esi rẹ ti o niyelori ni apakan asọye wa.