Tag Info

New answers tagged

6

Many of the compressors take an an environment variable to accept options that cannot be passed on the command line. In your case GZIP_OPT=-9 sort --compress-program=/bin/gzip The same is true for xz with XZ_OPT and bzip2 with BZIP2


0

on my system, uniq has the option of skipping fields. history | uniq -f 1 gives me a unique listing of my history with line numbers my version: uniq (GNU coreutils) 8.15 However, this only omits concurrent duplicates, so I would actually sort the history output, then uniq it: history | sort -k 2 | uniq -f 1 | sort -n The last sort, is optional, it ...


0

You can parse .bash_history file, instead of using history command. Here's an example in awk: awk '!x[$0]++' .bash_history | nl But like @devnull's answer, you should use HISTCONTROL to avoid duplicated command and also command which start with spaces: HISTCONTROL=ignoreboth


2

You can say: history | awk '{$1=""; sub("^ ", "", $0)}1' | sort -u to get a list of unique entries in the history. However, you can also set HISTCONTROL to avoid duplicates in the history: HISTCONTROL=ignoredups:erasedups Quoting from the manual: HISTCONTROL A colon-separated list of values controlling how commands are saved on the history ...


1

find $DIR -depth -maxdepth 3 \ -type d -readable -printf \ 'printf "\\n%p\\n" ls -t --color=always "%p"\n' |\ . /dev/stdin 2>&- This avoids any argument list problems because the only argument ls will ever receive is the name of the directory you want listed. You can do this with anything you like. The shell just . sources the |pipe ...


1

To robustly list the filenames only using recent GNU tools: find . -printf '%A@ %p\0' | sort -nz | sed -z 's/^[^ ]* //' | tr '\0' '\n'


2

find -printf "%TY-%Tm-%Td %TT %p\n" | sort -n will give you something like 2014-03-31 04:10:54.8596422640 ./foo 2014-04-01 01:02:11.9635521720 ./bar


1

In bash, run shopt -s globstar first. In ksh93, run set -o globstar first. In zsh, you're already set. ls -dltr **/* This will return an error if you have so many files that the command line length limit on your system is exceeded. In zsh, you can use this instead: print -rl -- **/*(Om)


1

This one will list all files in <dir> with topmost being oldest modified find <dir> -type f -print0 | xargs -print0 ls -ltr And with this the latest modified is topmost find <dir> -type f -print0 | xargs -print ls -lt Note that this only works if the list of file names doesn't exceed the total command line length limit on your ...


3

If you want to flatten the directory structure (thus sorting by date over all files in all directories, ignoring what directory the files are in) the find-approach suggested by @yeti is the way to go. If you want to preserve directory structure, you might try $ ls -ltR /path/to/directory which sorts directory based.


3

Assuming you are usuig GNU find, try: find $SOMEPATH -exec stat -c '%Y %n' '{}' + | sort -n


6

Specify the sort keys separately with the criteria: sort -k1,1nr -k2,2 inputfile This specifies that the first key is sorted numerically in reverse order while the second is sorted as per the default sort order. Quoting from POSIX sort: -k keydef The keydef argument is a restricted sort key field definition. The format of this definition is: ...


1

You could always prepend a ./ and then remove it again. Eg: sed "/\// ! s:^Bundle[[:space:]][[:space:]]*':&./:" ~/.vimrc | sort -t "/" -k2,2 | sed "s:\(^Bundle[[:space:]][[:space:]]*\)'\./:\1:" Or with GNU sed, this can be shortened slightly with extended regular expressions: sed -r "/\// ! s:^Bundle[[:space:]]+:&./:" ~/.vimrc | sort -t "/" ...


5

Because the correct way to read a file into an array is: $ perl -e 'print sort <>;' < data Setting the input record separator to undef is only putting your whole file into a single scalar. Then sorting a single value array does not mean much. Array mode is already reading your whole file in one shot. Then sorting would be meaningful: $ perl -e ...


7

The problem is local $/ = undef. It causes perl to read entire file in to @ARGV array, meaning it contains only one element, so sort can not sort it (because you are sorting an array with only one element). I expect the output must be the same with your beginning data (I also use Ubuntu 12.04 LTS, perl version 5.14.2: $ perl -le 'local $/ = undef;print ++$i ...


6

Using the sort command will probably be the fastest option. But you'll probably want to fix the locale to C. sort -u doesn't report unique lines, but one of each set of lines that sort the same. In the C locale, 2 different lines necessarily don't sort the same, but that's not the case in most UTF-8 based locales. Also using the C locale avoid the ...


8

GNU sort (which is the default on most Linux systems), has a --parallel option. From http://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html: ā€˜--parallel=nā€™ Set the number of sorts run in parallel to n. By default, n is set to the number of available processors, but limited to 8, as there are diminishing performance gains after ...



Top 50 recent answers are included