{"id":245,"date":"2009-04-20T01:00:19","date_gmt":"2009-04-20T06:00:19","guid":{"rendered":"http:\/\/yourlinuxguy.com\/?p=245"},"modified":"2009-04-21T13:48:31","modified_gmt":"2009-04-21T18:48:31","slug":"why-arent-my-files-listed-in-order","status":"publish","type":"post","link":"https:\/\/yourLinuxGuy.com\/?p=245","title":{"rendered":"Why aren&#8217;t my files listed in order?"},"content":{"rendered":"<p>A friend of mine was looking for a file using Nautilus while logged in as root on a SLE server.\u00a0 He was looking for a particular file that started with a capital &#8220;S&#8221;, and simply could not seem to find it.\u00a0 He thought he was losing his mind, because he was certain it was there when logged in earlier (as his regular user).<\/p>\n<p>Ah-hah!\u00a0 Some of you have already solved this riddle&#8230;\u00a0 but do you know the underlying reasons why this is the case?\u00a0 I&#8217;ll explain how it applies to bash on Suse, but it&#8217;s pretty much the same for other shells (and can be made to be the same on other distros).<\/p>\n<p>You see, when you log in as regular user (meaning with a regular user profile) and do a file listing with Nautilus or <code>ls<\/code>, you see the files listed in alphabetical order, regardless of case.\u00a0 When you are logged in as root, you see files listed in ASCII-like text order;\u00a0 meaning all uppercase letters completely precede the lowercase letters.\u00a0 It&#8217;s important to understand that these symptoms are not directly *caused* by Nautilus, <code>ls<\/code>, or their options;\u00a0 in fact, these tools are simply responding to the order in which they see the files.<\/p>\n<p>The magic is actually done by the &#8220;<code>LANG<\/code>&#8221; (language) variable of the current user session.\u00a0 This is because for the root user, the <code>LANG<\/code> value defaults to &#8220;<code>POSIX<\/code>&#8221; (which honors the ASCII style listing), and for regular users it is set to &#8220;<code>en_US.UTF-8<\/code>&#8221; (for English US, at least; obviously yours might be a different variant of <code>UTF-8<\/code>), which is more human-style.\u00a0 Check it yourself with:<\/p>\n<p><code>echo $LANG<\/code><\/p>\n<p>&#8230;which is set in <code>\/etc\/sysconfig\/language<\/code>.\u00a0 From that very file, I think the comment section explains it best:<\/p>\n<p><code># Local users will get RC_LANG as their default language, i.e. the<br \/>\n# environment variable $LANG . $LANG is the default of all $LC_*-variables,<br \/>\n# as long as $LC_ALL is not set, which overrides all $LC_-variables.<br \/>\n# Root uses this variable only if ROOT_USES_LANG is set to \"yes\".<\/code><\/p>\n<p>So now it is all clear.\u00a0 You get to choose the order in which you want to see the files.\u00a0 But in the end, the standard behavior for the root user&#8217;s Nautilus or <code>ls<\/code> listing results is probably the way most sysadmins prefer (for scripts, regex, and such), and the pretty alphabetical method is probably best for regular users (more like windows).<\/p>\n<p>On a side note, as a bash user, you get a set of\u00a0 options for ls called <code>LS_OPTIONS<\/code> in <code>\/etc\/bash.bashrc<\/code>.\u00a0 This file basically decides whether or not you are the root user, and if so, set the &#8220;<code>-A<\/code>&#8221; option to show &#8220;Amost All&#8221; of the files (basically all except &#8220;.&#8221; and &#8220;..&#8221;). Just wanted to mention that in case you were wondering where all your so-called &#8220;hidden&#8221; files went, too&#8230;<\/p>\n<p>\ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A friend of mine was looking for a file using Nautilus while logged in as root on a SLE server.\u00a0 He was looking for a particular file that started with a capital &#8220;S&#8221;, and simply could not seem to find&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/yourLinuxGuy.com\/?p=245\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[10,65,66,15],"tags":[],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-introductory","category-ls","category-nautilus","category-suse"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnjn1-3X","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=245"}],"version-history":[{"count":2,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":247,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions\/247"}],"wp:attachment":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}