How to view a configuration file without the comments Kā apskatīt konfigurācijas failu bez komentāriem

by Sukrit Dhandhania on May 22, 2009 ar Sukrit Dhandhania 2009 May 22,

Linux

I have to often make changes to configuration files such as httpd.conf and squid.conf . Man ir bieži mainīt konfigurācijas failus, piemēram, httpd.conf un squid.conf. These files have a large number of lines that are commented out, mostly comments and some possible configuration directives that have been commented out as they are not required by default. Šie faili ir daudz līniju, kas komentēja, kas, galvenokārt piezīmes un daži iespējamās konfigurācijas direktīvām, ir piezīmes veic kā tie nav vajadzīgi pēc noklusējuma. A problem I face while editing such files is that there are so many lines commented out that I need to scroll down many lines before I can find the next active configuration directive. Problēma man sejas rediģēšanas laikā šādas lietas ir tas, ka ir tik daudz rindu komentēja, ka man ir nepieciešams, lai ritinātu neskaitāmas pozīcijas pirms es varētu atrast nākamo aktīvā konfigurācijas direktīva. I found a fine solution to help me out with this. Es atklāju soda risinājumu, lai man palīdzēt ar to.

I now use the following command when I want to just look at the active directives in the Apache configuration file: Es tagad var izmantot šādu komandu, kad es vēlos tikai apskatīt darbojas direktīvu Apache konfigurācijas failu:

# sed '/ *#/d; /^ *$/d' /etc/httpd/conf/httpd.conf # Sed '/ * # / d; / ^ * $ / d' / etc / httpd / conf / httpd.conf

This command reads the file /etc/httpd/conf/httpd.conf and filters out all the comments and extra white spaces, leaving just the active configuration settings. Šī komanda skan failu / etc / httpd / conf / httpd.conf un filtri visus komentārus un papildu baltās telpas, atstājot tikai aktīvās konfigurācijas uzstādījumus. This makes it very easy for me to look at the configuration file. Tāpēc ir ļoti viegli man apskatīt konfigurācijas failu.

If you want to just filter out the lines that begin with comments run the following command: Ja jūs vēlaties vienkārši izfiltrēt līnijas, kas sākas ar komentāriem palaist šādu komandu:

# sed '/ ^#/d; /^ *$/d' /etc/httpd/conf/httpd.conf # Sed '/ ^ # / d; / ^ * $ / d' / etc / httpd / conf / httpd.conf

It's pretty much the same command as earlier with a small change. Tas ir diezgan daudz pašu komandu, kā agrāk, nelielas izmaiņas. The first * is replaced by ^ , which is regex for beginning of line. Pirmā * aizstāj ^, kas ir regex uz sākuma līnijas.

Related Posts: Related Posts:
  • How to open and view .cbr and .cbz files Kā atvērt un apskatīt. CBR. CBZ faili
  • How to view the page source in a new tab using Firefox Kā lai apskatītu lapu avots jaunā cilnē, lietojot Firefox
  • Contact Kontaktpersona
  • How to create a symlink (shortcut) in Linux Kā izveidot saitēt (shortcut) in Linux
  • 10 more brightkite invites for Simple Help readers 10 vairāk brightkite aicina vienkāršām Help lasītājiem
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Get Simple Palīdzība konsultācijas tāpat kā šo vienu savā e-pastā ik dienas - bez maksas! Just enter your email address below: Vienkārši ievadiet savu e-pasta adresi:

    You can always opt out of this email subscription at any time. Jūs vienmēr varat atteikties no šīs e-pasta abonementu jebkurā laikā.

    { 1 trackback } (1 Trackback)

    Display files without commented-out lines « Linux & Stuff Display failus bez komentētās-out lines «Linux & Stuff
    05.31.09 at 3:51 am 05.31.09 at 3:51

    { 4 comments… read them below or (4 comments ... lasīt tos zem vai add one pievienot vienu } )

    1 1 paulfxh 05.30.09 at 3:20 pm paulfxh 05.30.09 at 3:20

    Your command to show a file without comments could be very useful for me. Savu komandu, lai parādītu failu bez komentāriem varētu būt ļoti noderīga mani.
    However, when I tried to run Taču, kad es centos palaist
    # sed '/ ^#/d; /^ *$/d' /boot/grub/menu.lst
    I get this error I get this error
    sed: -e expression #1, char 1: unknown command: ` '
    bash: /^: No such file or directory
    Note that I copied/pasted the command directly from your post. Jāatzīmē, ka es kopēt / ielīmēt komandu tieši no sava amata.
    I have a feeling this may be a HTML-related problem. Man ir sajūta, tas var būt HTML-saistītu problēmu.
    Any clues? Jebkurš clues?
    Thanks Pateicība
    Paul Paul

    2 2 paulfxh 05.31.09 at 3:16 am paulfxh 05.31.09 at 3:16

    Well, after a bit of searching around, I found that this command does what I want Nu, pēc meklēšanas ap bit, es atklāju, ka šī komanda nav tas, ko es gribu
    sed '/^#/ d' /boot/grub/menu.lst>/boot/grub/menu.new
    Still not sure exactly what's wrong with the command given in the article, but it might be that the HTML has somehow 'distorted' the first single quote mark Joprojām nav pārliecināts, ko tieši's wrong with komandu dots rakstā, bet tā varētu būt, ka HTML ir savā ziņā "izkropļots" pirmais singls citātu zīmes

    3 3 paulfxh 05.31.09 at 3:33 am paulfxh 05.31.09 at 3:33

    After a little more experimentation, I find that the command below does what the command in the article was intended to do Pēc nedaudz vairāk eksperimentu, es uzskatu, ka komanda zem dara komandu pantā bija paredzēts, lai do
    sed '/^#/d; /^*$/d' /path/to/file/

    4 4 lxtips lxtips 06.29.09 at 10:03 pm 06.29.09 at 10:03

    hi, is this the same as: hi, tas pats kā:

    grep -v '#' file grep-v '#' file

    Leave a Comment Leave Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> Jūs varat izmantot šos HTML tagus un atribūtus: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>