InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Linux/Unix Command Line tutorials

  • Awk
  • Curl
  • Edit a file without changing its timestamp on Linux
  • Find which process is listening on a port on Linux
  • Get file size in bytes on Linux
  • How to delete files starting with dash/hyphen
  • How to kill unresponsive ssh session using escape sequence
  • How to show environment variable for a process id (pid)
  • How to sort using a specific field on Linux
  • How to specify environment variable for a command on Linux
  • How to zip/unzip a directory with password
  • ImageMagick
  • Impact on LC_ALL on Linux sort
  • Linux - find listening ports
  • Linux - find top directories by used disk size (excluding size of subdirectories)
  • Linux - how to run a command as different user
  • Linux - list only directories
  • Linux - providing sudo access to a users - some best practices
  • Linux - sending mail from command using mailutils
  • Linux file timestamps
  • Linux how to modify a user using usermod
  • Linux ping a port using netcat
  • Linux replace comma with newline
  • Linux screen - quick start guide
  • Linux what package provides a file
  • Linux/Unix - How to go to previous directory
  • Linux/Unix - find inode number of a file
  • Linux/Unix - truncate a large log file without deleting it
  • Linux/Unix history with date and time
  • Memcache - how to dump all keys and values on command line
  • Mongo - cli quick start guide
  • Perl command line - replace multi line comments
  • Python/Perl/Unix one liners
  • Rsync
  • Ruby gem - handy reference
  • SSH
  • Some handy linux gnu date commands
  • Use watch to monitor a command at some frequency on Linux
  • bower - installation and quick start guide
  • csvkit - parse csv file and data on Linux command line
  • ffmpeg
  • grep without regex (fixed string)
  • redis cli quick start tutorial
  • wget handy commands

Linux find

  • Find recently modified files on Linux
  • Linux - find and delete files older than 30 days
  • Linux - find files containing specific text
  • Linux find - ignore case in name
  • find - exclude directory or file pattern
 
  • Home
  • > Tutorials
  • > Linux/Unix Command Line

Impact on LC_ALL on Linux sort

By admin on Oct 24, 2015

Linux sort is a handy Linux command line tool to sort text files. It can sort fairly large files without consuming too much memory. The sorting behaviour can change depending upon the localisation setting set using LC_ALL environment variable.

Find/change sorting rule on Linux

To find the sorting rule set on your Linux system run the following:

$ echo 1 | sort --debug
sort: using ‘en_US.UTF-8’ sorting rules
1
_

sort in debug mode tells us which sorting rule is being used. Above result may vary on your system depending upon the environment variables set.

Now run the following to set LC_ALL=C and then see the sorting rule used by sort:

$ LC_ALL=C; echo 1 | sort --debug
sort: using simple byte comparison
1
_

Here are some examples with different LC_ALL localisation values:

Traditional sort using byte values

To do the tradition sort set LC_ALL=C before sort. Here is an example using this:

$ LC_ALL=C; printf "a 4\na3\n" | sort
a 4
a3

Here since space comes before number 3 in simple byte camparison, The output has “a 4” before “a3”.

sort using en_US.UTF-8

This is usually default value of LC_ALL on Ubuntu Linux. So you may end up doing sort using this. But we’ll set it explicitly.

$ LC_ALL=en_US.UTF-8; printf "a 4\na3\n" | sort
a3
a 4

Notice the different outcome this time. Using en_US.UTF-8 causes sort to ignore spaces. For this reason sort treats “a 4” as “a4” and hence the above outcome.

It is a good idea to review what sorting rule sort is using on your system before using it to avoid surprises.

Suggested posts:

  1. How to clear default app on android
  2. Python/Perl/Unix one liners
  3. How to show environment variable for a process id (pid)
  4. Perl command line – replace multi line comments
  5. Linux replace comma with newline
  6. How to use pm2 to manage node.js application in production
  7. WordPress – customize facebook plugin opengraph meta tags
  8. Linux – how to create swap partition
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Linux/Unix Command Line, Tutorials, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress