• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

sort

Bash Sort Files

April 10, 2023

How to sort files in Bash.

Display contents

$ cat file.txt
bbb
aaa
ccc
kkk
uuu
ppp

$ cat file.txt bbb aaa ccc kkk uuu ppp

Sort

$ sort file.txt
aaa
bbb
ccc
kkk
ppp
uuu

$ sort file.txt aaa bbb ccc kkk ppp uuu

Sort in place

$ sort -o file.txt file.txt
$ cat file.txt
aaa
bbb
ccc
kkk
ppp
uuu

$ sort -o file.txt file.txt $ cat file.txt aaa bbb ccc kkk ppp uuu

Filed Under: Linux Tagged With: bash, file, sort

Find the Biggest File

April 1, 2019

Find the biggest files in the current directory. Sort by from large to small. Display only the top 20. Display in human readable format.

find -type f -exec du -Sh {} + | sort -rh | head -n 20

find -type f -exec du -Sh {} + | sort -rh | head -n 20

Filed Under: Linux Tagged With: big, du, file, find, sort

WP_Query Reverse Sort

March 25, 2019

Here’s how to reverse sort WP_Query. Order by ID. Reverse sort by ASC intead of DESC.

  $args = array (
    'cat' => 8, 
    'year' => $year, 
    'orderby' => 'ID',
    'order' => 'ASC', 
    'posts_per_page' => -1, 
    'paged' => $paged, 
    's' => $searchterm 
  );
  $category_posts = new WP_Query($args);

$args = array ( 'cat' => 8, 'year' => $year, 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => -1, 'paged' => $paged, 's' => $searchterm ); $category_posts = new WP_Query($args);

Filed Under: WP Tagged With: id, post, reverse, sort, wp_query

  • Home
  • About
  • Search

Copyright © 2023