# howto: reorder your /etc/make.conf USE flags alphabetically

## libero

hi 

Objective:  USE flags get cluttered, hard to read, jumbled order.  Here is a way to clean them up.   Descriptions in /usr/portage/profiles/use.desc  and on the gentoo docs are alphabetized, so it's handy to scan and examine them.  

First the code: 

```

user@system% cat /etc/make.conf | grep "USE=" | grep -v "^#" | awk '{ for (i = NF; i >= 2; i-- )  print $i}' | grep -v '^"$' | sort | xargs echo

```

New [updated], the slightly improved code: 

```

user@system% cat /etc/make.conf | grep "USE=" | grep -v "^#" | awk '{ for (i = (NF -1); i >= 2; i-- )  print $i}' | sort | xargs echo 

```

Notes: 

Depending on where you put your ["] (quotation) marks around all the flags, you may need to tweak or hand-edit something.  In my case, the line looks like: 

```
USE=" some flag terms " 
```

so that the first quotation is contiguous with USE=  and the last one is separated by whitespace. 

If you are worried that something is redundant, you could add a |uniq | command before the "xargs echo" but I prefer to view any redundancies just in case they disagree in direction (+ vs. -) 

The second grep eliminates any commented-out lines, so you're sure to be only working with your real "USE" flags (on an uncommented line).  

The output is just the ordered USE flags themselves.  You'll need to cut-and-paste or otherwise insert them into /etc/make.conf  after [USE="]  and  followed by a final [ " ]  

[update] Added because you can take the final [ " ] quote mark out just by setting the awk params one item shorter, since we always know the order of the awk items.  

My USE flags going in:  

```

user@system% cat /etc/make.conf | grep "USE="                      1:50AM ~

USE=" -3dfx -3dnow X acl -acpi -aim -arts -apache2  berkdb -bluetooth canna cjk -doc dbm -divx4linux -dv -dvd -dvdr  -emacs -alsa expat -flac flatfile freewnn ftp -gb  gif iconv  -icq -ieee1394 -ipv6  java  javascript  jpeg kde -ldap -leim   libwww -motif mime  mozilla -mp3  mpeg mysql ncurses  nls -oci8  opengl -pcmcia  pdflib perl php png qt bindist python rage128 simplexml spl  tcltk tiff tokenizer truetype unicode -vcd -videos -vorbis -wifi  xml2 xsl -xvid  yahoo ssl -afs xv -msn -mule -oscar -matrox  -pda -gnome -gtk -cdr x86 "

# USE="X -gtk -gnome qt kde -dvd -alsa -cdr -emacs"

```

and then I run the command:  

```

user@system% cat /etc/make.conf | grep "USE=" | grep -v "^#" | awk '{ for (i = NF; i >= 2; i-- )  print $i}' | grep -v '^"$' | sort | xargs echo

-3dfx -3dnow acl -acpi -afs -aim -alsa -apache2 -arts berkdb bindist -bluetooth canna -cdr cjk dbm -divx4linux -doc -dv -dvd -dvdr -emacs expat -flac flatfile freewnn ftp -gb gif -gnome -gtk iconv -icq -ieee1394 -ipv6 java javascript jpeg kde -ldap -leim libwww -matrox mime -motif mozilla -mp3 mpeg -msn -mule mysql ncurses nls -oci8 opengl -oscar -pcmcia -pda pdflib perl php png python qt rage128 simplexml spl ssl tcltk tiff tokenizer truetype unicode -vcd -videos -vorbis -wifi X x86 xml2 xsl xv -xvid yahoo

```

have fun

LeoLast edited by libero on Sat Dec 03, 2005 2:26 pm; edited 1 time in total

----------

## Aries-Belgium

Thanks, just what I was looking for. Now I don't have to check eveytime if they are still in the good order.

----------

## Cintra

I ran ufed-0.40 instead

..it got rid of quite a few unnecessary flags, and left me with

```

USE="a52 aac cddb cdparanoia dvd dvdr dvdread hddtemp javascript live

     lm_sensors mmx network nptl ppds real rtc sse sse2 theora win32codecs

     -avi -fortran -gnome -gtk"

```

 :Wink: 

----------

## rojaro

Hi there,

nice idea, but here my little improved version with which you dont have to care about quotes and formatting :)

```
# echo $(source /etc/make.conf && echo $USE | awk '{ for(i=NF;i>0;i--) print $i }' | sort)
```

- rojaro -

----------

## thdrcat

thanks!

alternitivly you could emerge the program "ufed"

Ufed offers a terminal psuedo gui to make changes to your use flags. 

What I use it for a lot is to order use flags and remove extra use flags. i.e. it is in my make.conf AND is on by default.

----------

## libero

hi 

I realize they are only opinions, just like yours and mine, but the opinions of ufed on this site: 

http://www.gentoo-portage.com/app-portage/ufed

were less than positive.  

Maybe it is because ufed only considers the packages you have currently installed, and it's unable to consider the future packages you plan to install, for which you have already selected some USE flags.  

I agree ufed will probably be useful for some people, but for others who think about future USE flags, there are these cool tools  :Wink: 

L

----------

## revertex

Sweet!

My useflags are almost alfabetically orderer but files under /etc/portage/package.whatever is a big mess.

Ufed is nice, but not so usefull until it not handle local use flags.

----------

## Cintra

 *libero wrote:*   

> hi 
> 
> I realize they are only opinions, just like yours and mine, but the opinions of ufed on this site: 
> 
> http://www.gentoo-portage.com/app-portage/ufed
> ...

 

There have been versions with bugs, and I would certainly not use it without taking precautions based on earlier experience.. 

 :Wink: 

----------

## Arno

My /etc/make.conf USE flags start with USE="-* , which remove all flags set by default. I then don't need to a have lenghty list of - flags.

For instance:

```
USE="-* X 3dnow alsa ..."
```

I then add additional per package flags in /etc/portage/package.use.

----------

## destr0yr

```

* app-portage/flagedit

     Available versions:  0.0.2 [M]0.0.3 [M]0.0.4 0.0.5

     Installed:           0.0.5

     Homepage:            http://damz.net/flagedit/

     Description:         CLI use flags and keyword editor, for system wide or /etc/portage files

emerge flagedit

```

Great little app.  ufed rocks too.

----------

## libero

aha 

another twist.  According to the Gentoo Newsletter, of Jan 16, 2006, they are beginning to migrate away from the "auto-use" feature, in favor of manual control of USE flags.  An excerpt from the newsletter:  

 *Quote:*   

> 
> 
> The change will happen in one of the next Portage 2.1 releases - it is in the tree and marked ~ARCH on almost all arches. "Stable" users will stay unaffected for some time since Portage 2.0.x will not change its behaviour, but upgrades can and will change USE flags. If you just upgraded to a portage 2.1 release you will probably want to look at the "emerge -DuvpN world" output and add flags that you want to keep enabled to make.conf if they show up as "-foo*".
> 
> 

 

And a link to the full newsletter page (English):  http://www.gentoo.org/news/en/gwn/20060116-newsletter.xml

So more of the USE flag management tips in this thread will be of value to more of us.  

To summarize:  

-an awk-based flag handling script

-app-portage/flagedit

-app-portage/ufed

Leo

----------

## ilm

I just found this bit of code, but I've got a couple of problems/questions with it:

1) When I run it, it only outputs the interior flags of the first line, i.e.  it outputs:

 *Quote:*   

> a52 aac aalib acpi audiofile bash-completion bcmath bidi

 

whilst the first line of USE flags in make.conf is:

 *Quote:*   

> Xaw3d a52 aac aalib acpi audiofile bash-completion bcmath bidi bindist

 

2) How can I set this up to use for an alias or shell script?  Whenever I do something like that, it thinks the output is a series of commands and tries to run them.

Otherwise, thanks for this!!!  My USE flags were getting a bit out of control (I'm slowly pruning them down as I work out what they do and what I need).

----------

## Akkara

It appears to be sensitive to whether there is space between the double-quotes and the use flags.

Here's a somewhat shorter script that I think avoids that problem:

```
sed -n 's/^USE=" *\(.*\) *"/\1/p' </etc/make.conf | tr ' ' '\n' | sort | xargs echo
```

----------

## ilm

Akkara: I can't seem to get your script to do anything.

I find that the problem with these scripts is that they work only if USE is defined on the one line, but after running the first one, it got split up onto multiple lines, so it will no longer work.

Edit: Rojaro's script works with the entire USE variable, but only outputs the result to the terminal, not back to /etc/make.conf

----------

## ppurka

 *ilm wrote:*   

> Edit: Rojaro's script works with the entire USE variable, but only outputs the result to the terminal, not back to /etc/make.conf

 Yes, it works.  But you just need to copy and paste   :Rolling Eyes: 

----------

## ilm

Well, Libero's script (the second one at least) changed the make.conf file ordering of the USE flags (without me knowing about it...), so I was wondering what would be required to do the same with Rojaro's.

----------

## ppurka

 *ilm wrote:*   

> Well, Libero's script (the second one at least) changed the make.conf file ordering of the USE flags (without me knowing about it...), so I was wondering what would be required to do the same with Rojaro's.

 You sure? I don't see any of the commands in the original post writing back to /etc/make.conf

----------

## ilm

 *ppurka wrote:*   

> You sure? I don't see any of the commands in the original post writing back to /etc/make.conf

 

Neither did I, and that's what confused me for a bit as well  :Wink: .  However, I know that I originally had all my USE flags in one big long line, and after running that set of commands it was on multiple lines, and some of the ordering had changed (e.g. placing Xaw3d up the front, all the - flags at the end).

----------

## ppurka

 *ilm wrote:*   

>  *ppurka wrote:*   You sure? I don't see any of the commands in the original post writing back to /etc/make.conf 
> 
> Neither did I, and that's what confused me for a bit as well .  However, I know that I originally had all my USE flags in one big long line, and after running that set of commands it was on multiple lines, and some of the ordering had changed (e.g. placing Xaw3d up the front, all the - flags at the end).

 I think you ran ufed at some point, which rearranged all the USE flags.  The scripts in the original post will not rearrange the -flags to the end.

----------

## ilm

Ahhh, yes, that must have been it  :Wink: 

----------

## Non_E

Something probably went wrong: 

```
radek@linwood ~ $ cat /etc/make.conf | grep "USE=" | grep -v "^#" | awk '{ for (i = (NF -1); i >= 2; i-- )  print $i}' | sort | xargs echo |  wc -w

75

radek@linwood ~ $ cat /etc/make.conf | grep "USE=" | wc -w

77
```

Rojaro's script returns 77 use flags which is the same as in original. I suggest using his script.

----------

## GimmeFuel

I like it much better if you pass -d to sort. This causes sort to ignore to - in front of disabled flags, and puts them in true dictionary order.

```
~ # cat /etc/make.conf | grep "USE=" | grep -v "^#" | awk '{ for (i = (NF -1); i >= 2; i-- )  print $i}' | sort | xargs echo

-apache -apm -arts -berkdb -curl -eds -emboss -esd -fam -firefox -gcj -gdbm -gnome -gstreamer -ipv6 -kde -ldap -motif -nls -oss -qt -qt3 -qt4 X aac aalib acpi alsa apache2 audacious bash-completion bzip2 cdr crypt cups dvd dvdr dvdread encode fbcon ffmpeg flac foomaticdb gimpprint glut gmp gtk gtk2 imagemagick java joystick libcaca logrotate matroska mikmod mmx mmxext mozilla mplayer msn mysql nptl nptlonly nsplugin offensive ogg oggvorbis pcre php pic ppds real ruby samba seamonkey session silc speex sqlite sse startup-notification tcltk theora tiff usb vorbis win32codecs x264 xslt

~ # cat /etc/make.conf | grep "USE=" | grep -v "^#" | awk '{ for (i = (NF -1); i >= 2; i-- )  print $i}' | sort -d | xargs echo

X aac aalib acpi alsa -apache apache2 -apm -arts audacious bash-completion -berkdb bzip2 cdr crypt cups -curl dvd dvdr dvdread -eds -emboss encode -esd -fam fbcon ffmpeg -firefox flac foomaticdb -gcj -gdbm gimpprint glut gmp -gnome -gstreamer gtk gtk2 imagemagick -ipv6 java joystick -kde -ldap libcaca logrotate matroska mikmod mmx mmxext -motif mozilla mplayer msn mysql -nls nptl nptlonly nsplugin offensive ogg oggvorbis -oss pcre php pic ppds -qt -qt3 -qt4 real ruby samba seamonkey session silc speex sqlite sse startup-notification tcltk theora tiff usb vorbis win32codecs x264 xslt
```

----------

## libero

hi everybody, 

thanks for the feedback and enhancements. 

Couple of notes:  

- the original scripts have an unfortunate dependency on whitespace surrounding the " [quote marks] around the actual USE flags.  If you get 2 fewer items in your list than you should have, it's because the first and last in the line are being discarded along with the quote marks.  Just make sure each quote mark is separated by whitespace from any flags.  Or try Akkara's or rojaro's script.   Yeah I should fix my original script sometime.   :Wink: 

- GimmeFuel's point is a good one.  But to get the same results as his "sort -d" I don't need anything:  just default "sort" works that way already on my box.  So remember that your mileage may vary:  even awk is known to be slightly different here and there.

- the original scripts do *not* attempt to re-write the /etc/make.conf file itself.  To do that usually requires root, and is slightly more dangerous than I intended.  My recommendation:  run the script, view the output, make any tweaks you want, run the script again if you need, then paste back to /etc/make.conf and save.

----------

## libero

more USE flags tips just posted here:  

https://forums.gentoo.org/viewtopic-t-669944-start-0-postdays-0-postorder-asc-highlight-.html

I like this one, posted by PopeJohnPaulII who says to organize by groups to remember what was for what in USE flags:  

```

# Use Flags

USE="" # Not needed, just added to look neater.

USE="$USE -gnome" # Disable GNOME

USE="$USE -qt3 -qt4 -kde -arts" # Disable KDE

USE="$USE -ipv6" # Disable IPv6

USE="$USE symlink" # Kernel

USE="$USE lm_sensors mmx pmu sse sse2" # CPU

USE="$USE acpi apm" # Battery/Power Managment

USE="$USE aac alsa dts esd flac lame mp3 ogg vorbis wavpack" # Audio

USE="$USE exif gif imagemagick jpeg png svg tiff" # Image

USE="$USE cups pdf spell truetype unicode" # Text/Fonts/Printing

USE="$USE fbcon gpm mplayer opengl" # Video

USE="$USE encode ffmpeg matroska mpeg quicktime win32codecs xvid" # Video Codecs

USE="$USE ftp imap samba ssl vnc" # Internet Protocols

USE="$USE avahi wifi zeroconf" # Wireless

USE="$USE joystick pcmcia usb" # Misc Hardware

USE="$USE X" # Xorg

USE="$USE bzip2 cracklib crypt" # Encryption/Decryption/Compression/Decompression

USE="$USE java javascript" # Programing Languages

USE="$USE firefox thunderbird" # Mozilla

USE="$USE bash-completion branding cdr dbus dvd dvdr gtk hal libnotify xscreensaver" # Linux

```

this however would defeat the purpose of this posting's script.  So a variation would be to just put #Comments in your make.conf  after the main line of USE, which just shows why each flag is set.

----------

## SeaTiger

Personally I use profuse to manage USE flag. Like ufed, it will always arrange flag alphabetically.

However I do very much prefer to arrange them in group like the previous post.

----------

## Dralnu

You can seperate USE-flags using \'s.

Example:

USE="X alsa \

foo bar"

I don't know if you can add a comment to the end of the line doing this, though.

----------

## ok

I would do:

```
. /etc/make.conf && echo $USE | tr ' ' '\n' | sort | tr '\n' ' ' 
```

----------

## ZyX I

What about this code (USE flags with explanations):

```
USEDESCLIST=$(slocate .desc | grep -P '/use\.([^/]+\.)?desc' || find /usr -name 'use.*desc') ; echo "$(source /etc/make.conf && echo $USE | awk '{ for(i=NF;i>0;i--) print $i }' | sort)" | while read i ; do echo -ne "USE=\"\${USE} $i\" # " ; cat $USEDESCLIST | grep -P "^$(echo $i | sed 's/^-//')[[:blank:]]" || echo "" ; done
```

By the way, I have my USE flags written like that:

```
USE="X alsa

foo bar"
```

(without backslash before newline) and it works. However, I put almost all flags in /etc/portage/package.use

----------

