It is possible to print the result of 2 commands side by side...
Something like this
something `ls -l /a` `cat bla.txt`
result:
total 24 #while [ 1 = 1 ]; do
-rw-r--r-- 1 wolfy wolfy 194 Aug 13 08:50 c.in # echo "bla"
-rwxr-xr-x 1 wolfy wolfy 52 Sep 24 11:48 bla.sh #done
-rwxr-xr-x 1 wolfy wolfy 38 Sep 24 11:48 bla1.sh echo "bla"
-rwxr-xr-x 1 wolfy wolfy 147 Sep 24 11:54 ble.sh
I know that pr can do something like this with files, but I didn't find a way to do this for commands...
You can use process substitution
pr -m <(cmd1) <(cmd2)
though in your case, since you have one command and one file:
ls -l | pr -m - bla.txt
Related
I've just built my first proper q/kdb+ database with splayed and partitioned tables. Everything is going fine, but I just noticed that my symbol s column file size is unusually large. Here is what I can see from the OS and from inside q:
# ls -latr 2017.10.30/ngbarx
total 532
-rw-r--r-- 1 root root 24992 Apr 17 20:53 vunadj
-rw-r--r-- 1 root root 24992 Apr 17 20:53 v
-rw-r--r-- 1 root root 300664 Apr 17 20:53 s
...
q)meta ngbarx
c | t f a
------| -----
date | d
s | s p
v | e
vunadj| e
...
q)get `:2017.10.30/ngbarx/s
`p#`sym$`A`AA`AACG`AADI`AADR`AAIC`AAIC-B`AAL`AAM-A`AAMC`AAME`AAOI`AAON`AAP`AA..
q)-22!get `:2017.10.30/ngbarx/v
24990
q)-22!get `:2017.10.30/ngbarx/s
28678
q)all (get `:2017.10.30/ngbarx/s) in sym
1b
q)count sym
62136
So comparing the real-type v column with the symbol-type s column, I see from ls that the symbol column is more than 10x the size, even though the internal size in bytes is similar and everything seems properly encoded in the sym file.
Is this expected behavior? Or am I doing something wrong that could be fixed?
UPDATE: I have not used compression, and have written the files using the magical function .Q.dcfgnt, which can be viewed here. Well, a slightly modified version, I noticed that this function as is also saved a date file in the directory, even though the column should be virtual, so I did some hacking in k (I'm not very good at it) and updated the inner function .Q.dpfgnt to this ...
k){[d;p;f;g;n;t]if[~&/qm'r:+en[d]t;'`unmappable];
{[d;g;t;i;x]#[d;x;g;t[x]i]}[d:par[d;p;n];g;r;<r f]'{x#&~x=`date}(!r);
#[;f;`p#]#[d;`.d;:;f,r#&~f=r:{x#&~x=`date}(!r)];n}
Applying the parted attribute is not free and requires storage. It is usually not that costly but looking at your sample output of s, it doesn't look suitable for parting as does not contain repeating values:
q)get `:2017.10.30/ngbarx/s
`p#`sym$`A`AA`AACG`AADI`AADR`AAIC`AAIC-B`AAL`AAM-A`AAMC`AAME`AAOI`AAON`AAP`AA..
See below tables created to illustrate the issue:
/ no part - 16 distinct syms
t1:([]s:100000?`1;v:100000?2e)
/ part - 16 distinct syms
t2:update `p#s from `s xasc ([]s:100000?`1;v:100000?2e)
/ no part - 99999 distinct syms
t3:([]s:100000?`8;v:100000?2e)
/ part - 99999 distinct syms
t4:update `p#s from `s xasc ([]s:100000?`8;v:100000?2e)
The difference in size is insignificant between t1 and t2 with the parted attribute(804096 -> 804664). However, when the number of distinct syms / parts becomes very large, the storage cost is very large. (804096 -> 4749872)
ls | xargs ls -latr
t1:
total 1180
-rw-r--r-- 1 matmoore matmoore 12 Apr 19 10:28 .d
-rw-r--r-- 1 matmoore matmoore 804096 Apr 19 10:28 s
-rw-r--r-- 1 matmoore matmoore 400016 Apr 19 10:28 v
drwxr-xr-x 1 matmoore matmoore 4096 Apr 19 10:28 .
drwxr-xr-x 1 matmoore matmoore 4096 Apr 19 10:28 ..
t2:
total 1180
-rw-r--r-- 1 matmoore matmoore 12 Apr 19 10:28 .d
-rw-r--r-- 1 matmoore matmoore 804664 Apr 19 10:28 s
-rw-r--r-- 1 matmoore matmoore 400016 Apr 19 10:28 v
drwxr-xr-x 1 matmoore matmoore 4096 Apr 19 10:28 .
drwxr-xr-x 1 matmoore matmoore 4096 Apr 19 10:28 ..
t3:
total 1180
-rw-r--r-- 1 matmoore matmoore 12 Apr 19 10:28 .d
-rw-r--r-- 1 matmoore matmoore 804096 Apr 19 10:28 s
-rw-r--r-- 1 matmoore matmoore 400016 Apr 19 10:28 v
drwxr-xr-x 1 matmoore matmoore 4096 Apr 19 10:28 .
drwxr-xr-x 1 matmoore matmoore 4096 Apr 19 10:28 ..
t4:
total 5032
-rw-r--r-- 1 matmoore matmoore 12 Apr 19 10:28 .d
drwxr-xr-x 1 matmoore matmoore 4096 Apr 19 10:28 ..
-rw-r--r-- 1 matmoore matmoore 4749872 Apr 19 10:28 s
-rw-r--r-- 1 matmoore matmoore 400016 Apr 19 10:28 v
drwxr-xr-x 1 matmoore matmoore 4096 Apr 19 10:28 .
I would also question if this column should be a symbol. If 62k is the size of your sym file with just one date created then you should be careful that you are going to end up creating a bloated sym file. If you have a full history from 2017.10.30 and the sym file is still 62k, then it's fine but if you are adding that many new symbols each day, the sym file will quickly spiral out of control.
Suppose the following linker script is used to layout an executable file.
SECTIONS
{
. = 0x10000;
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) }
}
OUTPUT_FORMAT(ELF)
My questions are:
I think such layout info must be stored in the output ELF file so the loader can load the executable based on that info. Right?
If 1 is true, how to view such layout info in a ELF? objdump?
I think such layout info must be stored in the output ELF file so the loader can load the executable based on that info. Right?
ELF stands for executable and linking format.
The .text, .data etc. are part of the linking format. While they usually are present in the fully-linked binary, they can be stripped.
The info that the loader needs to load the executable is stored as a table of segments (Elf{36,64}_Phdr[]).
If 1 is true, how to view such layout info in a ELF? objdump?
You can examine segments (and, if the optional section table is present, the mapping of sections to segments) with readelf -Wl a.out.
You can deduce the information from the linker command script by taking a look at the output of the -S option in readelf.
$ readelf -S $(which ls)
There are 28 section headers, starting at offset 0x1f6f8:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .interp PROGBITS 0000000000400238 00000238
000000000000001c 0000000000000000 A 0 0 1
[ 2] .note.ABI-tag NOTE 0000000000400254 00000254
0000000000000020 0000000000000000 A 0 0 4
[ 3] .note.gnu.build-i NOTE 0000000000400274 00000274
0000000000000024 0000000000000000 A 0 0 4
[ 4] .gnu.hash GNU_HASH 0000000000400298 00000298
0000000000000104 0000000000000000 A 5 0 8
[ 5] .dynsym DYNSYM 00000000004003a0 000003a0
0000000000000c48 0000000000000018 A 6 1 8
[ 6] .dynstr STRTAB 0000000000400fe8 00000fe8
0000000000000582 0000000000000000 A 0 0 1
[ 7] .gnu.version VERSYM 000000000040156a 0000156a
...
If you want to know where this comes from, take a look at the default linker command scripts for your toolchain; this default is used if you did not explicitly create your own. I think there may be some inheritance between them as well, but I can't say for certain.
$ ls -l /usr/lib/ldscripts/ | grep elf
-rw-r--r-- 1 root root 9027 Mar 22 04:05 elf32_x86_64.x
-rw-r--r-- 1 root root 8880 Mar 22 04:05 elf32_x86_64.xbn
-rw-r--r-- 1 root root 8706 Mar 22 04:05 elf32_x86_64.xc
-rw-r--r-- 1 root root 9024 Mar 22 04:05 elf32_x86_64.xd
-rw-r--r-- 1 root root 8720 Mar 22 04:05 elf32_x86_64.xdc
-rw-r--r-- 1 root root 8680 Mar 22 04:05 elf32_x86_64.xdw
-rw-r--r-- 1 root root 9027 Mar 22 04:05 elf32_x86_64.xn
-rw-r--r-- 1 root root 5443 Mar 22 04:05 elf32_x86_64.xr
-rw-r--r-- 1 root root 8551 Mar 22 04:05 elf32_x86_64.xs
-rw-r--r-- 1 root root 8247 Mar 22 04:05 elf32_x86_64.xsc
-rw-r--r-- 1 root root 8207 Mar 22 04:05 elf32_x86_64.xsw
-rw-r--r-- 1 root root 5489 Mar 22 04:05 elf32_x86_64.xu
-rw-r--r-- 1 root root 8666 Mar 22 04:05 elf32_x86_64.xw
-rw-r--r-- 1 root root 8396 Mar 22 04:05 elf_i386.x
-rw-r--r-- 1 root root 8249 Mar 22 04:05 elf_i386.xbn
-rw-r--r-- 1 root root 8209 Mar 22 04:05 elf_i386.xc
-rw-r--r-- 1 root root 8389 Mar 22 04:05 elf_i386.xd
-rw-r--r-- 1 root root 8219 Mar 22 04:05 elf_i386.xdc
...
I searched a bit and found something.
For 1. According ELF format on wikipedia, there are program headers that record the address layout info.
For 2. readelf is a promising tool.
I have Postgresql 9.5 server on Freebsd. I try to install PGlogical (http://2ndquadrant.com/en/resources/pglogical/) from sources. But when I downloaded tarball and unpacked it, I saw only these files:
pglogical-1.0.1 ls -la
total 480
drwxr-xr-x 6 root wheel 1536 Mar 24 11:51 .
drwxrwxrwt 16 root wheel 1024 Mar 24 15:42 ..
-rw-rw-r-- 1 1000 1000 8 Jan 19 15:39 .distgitrev
-rw-rw-r-- 1 1000 1000 11 Jan 19 15:39 .distgittag
-rw-rw-r-- 1 1000 1000 169 Dec 31 12:33 .gitignore
-rw-rw-r-- 1 1000 1000 216 Dec 27 15:59 .gitmodules
-rw-rw-r-- 1 1000 1000 6240 Jan 18 06:42 Makefile
-rw-rw-r-- 1 1000 1000 23965 Jan 18 06:42 README.md
drwxrwxr-x 4 1000 1000 512 Jan 18 06:42 compat
drwxrwxr-x 2 1000 1000 512 Jan 19 14:39 expected
-rw-rw-r-- 1 1000 1000 893 Jan 19 14:39 pglogical--1.0.0--1.0.1.sql
-rw-rw-r-- 1 1000 1000 9496 Jan 18 06:42 pglogical--1.0.0.sql
-rw-rw-r-- 1 1000 1000 9504 Jan 18 06:42 pglogical--1.0.1.sql
-rw-rw-r-- 1 1000 1000 12670 Jan 18 06:42 pglogical.c
-rw-rw-r-- 1 1000 1000 184 Dec 22 15:27 pglogical.control.in
-rw-rw-r-- 1 1000 1000 1796 Jan 18 06:42 pglogical.h
-rw-rw-r-- 1 1000 1000 43489 Jan 18 06:42 pglogical_apply.c
-rw-rw-r-- 1 1000 1000 13960 Jan 18 06:42 pglogical_conflict.c
-rw-rw-r-- 1 1000 1000 2038 Dec 19 13:27 pglogical_conflict.h
-rw-rw-r-- 1 1000 1000 38525 Jan 18 06:42 pglogical_create_subscriber.c
drwxrwxr-x 2 1000 1000 1024 Jan 18 07:32 pglogical_dump
-rw-rw-r-- 1 1000 1000 1367 Dec 19 13:27 pglogical_fe.c
-rw-rw-r-- 1 1000 1000 533 Dec 1 09:35 pglogical_fe.h
-rw-rw-r-- 1 1000 1000 41913 Jan 18 06:42 pglogical_functions.c
-rw-rw-r-- 1 1000 1000 8748 Dec 19 13:27 pglogical_hooks.c
-rw-rw-r-- 1 1000 1000 4126 Dec 19 13:27 pglogical_manager.c
-rw-rw-r-- 1 1000 1000 23212 Jan 18 06:42 pglogical_node.c
-rw-rw-r-- 1 1000 1000 1992 Dec 19 13:27 pglogical_node.h
-rw-rw-r-- 1 1000 1000 9323 Dec 19 13:27 pglogical_proto.c
-rw-rw-r-- 1 1000 1000 1431 Sep 30 07:51 pglogical_proto.h
-rw-rw-r-- 1 1000 1000 5493 Dec 19 13:27 pglogical_queue.c
-rw-rw-r-- 1 1000 1000 1026 Dec 19 13:27 pglogical_queue.h
-rw-rw-r-- 1 1000 1000 4832 Jan 18 06:42 pglogical_relcache.c
-rw-rw-r-- 1 1000 1000 1147 Dec 19 13:27 pglogical_relcache.h
-rw-rw-r-- 1 1000 1000 24719 Dec 19 13:27 pglogical_repset.c
-rw-rw-r-- 1 1000 1000 2770 Jan 18 06:42 pglogical_repset.h
-rw-rw-r-- 1 1000 1000 4126 Dec 19 13:27 pglogical_rpc.c
-rw-rw-r-- 1 1000 1000 711 Dec 1 09:35 pglogical_rpc.h
-rw-rw-r-- 1 1000 1000 34577 Jan 18 06:42 pglogical_sync.c
-rw-rw-r-- 1 1000 1000 2472 Dec 19 13:27 pglogical_sync.h
-rw-rw-r-- 1 1000 1000 9808 Jan 18 06:42 pglogical_worker.c
-rw-rw-r-- 1 1000 1000 2898 Dec 19 13:27 pglogical_worker.h
-rw-rw-r-- 1 1000 1000 4667 Oct 28 08:21 regress-pg_hba.conf
-rw-rw-r-- 1 1000 1000 602 Jan 18 06:42 regress-postgresql.conf
drwxrwxr-x 2 1000 1000 512 Jan 19 14:39 sql
And I didn't see configure file and other. How to install this tarball? OS - Freebsd 10.2
You can install pglogical from sources only using PostgreSQL sources:
Download sources of PostgreSQL of necessary version.
You also need pglogical_output extension and its sources. You can read about it in the documentation. Download it from GitHub.
Configure PostgreSQL. More about it in the documentation.
Copy downloaded sources of pglogical and pglogical_output to directories contrib/pglogical and contrib/pglogical_output.
Execute commands:
cd <path-to-postgres-sources>/contrib/pglogical
make install
cd <path-to-postgres-sources>/contrib/pglogical_output
make install
Read the documentation to setup pglogical.
Did you read the README file? It will probably tell you to use make, as there is a Makefile
I have gone through a bunch of questions to find the best way to get the names of the files from a directory. However, I have a peculiar scenario and need some help.
The files in my direcotry are as follows
-rw-rw-r-- 1 root 55000 53916 Apr 12 2013 Update_2013-04-12_02-17-55.txt
-rw-rw-r-- 1 root 55000 53916 Apr 12 2013 UpdateCIMS_2013-04-12_03-20-30.txt
-rw-rw-r-- 1 root 55000 53763 Apr 15 2013 UpdateCIMSFlag_2013-04-15_05-47-41.txt
-rw-rw-r-- 1 root 55000 91981 Apr 23 2013 UserManagementService_2013-04-23_03-55-52.txt
-rw-rw-r-- 1 root 55000 92076 Apr 23 2013 UserManagementService_2013-04-23_04-34-42.txt
-rw-rw-r-- 1 root 55000 92086 Apr 23 2013 UserManagementService_2013-04-23_23-55-10.txt
-rw-rw-r-- 1 root 55000 91971 Apr 24 2013 UserManagementService_2013-04-24_02-23-20.txt
-rw-rw-r-- 1 root 55000 59441 Apr 24 2013 SecuredService_2013-04-24_02-29-08.txt
-rw-rw-r-- 1 root 55000 42240 May 20 2013 UpdateCIMSFlag_2013-05-20_04-24-19.txt
-rw-rw-r-- 1 root 55000 40547 May 20 2013 UpdateCIMSFlag_2013-05-20_05-31-29.txt
-rw-rw-r-- 1 root 55000 42238 May 20 2013 UpdateCIMSFlag_2013-05-20_05-43-54.txt
-rw-rw-r-- 1 root 55000 59493 May 21 2013 SecuredService_2013-05-21_04-25-32.txt
-rw-rw-r-- 1 root 55000 88374 May 21 2013 RegistrationService_2013-05-21_23-55-33.txt
-rw-rw-r-- 1 root 55000 88426 May 22 2013 RegistrationService_2013-05-22_00-20-04.txt
-rw-rw-r-- 1 root 55000 60014 Jul 31 04:16 SecuredService_2013-07-31_04-16-56.txt
-rw-rw-r-- 1 root 55000 91636 Sep 2 06:11 AdminServices_2013-09-02_06-11-17.txt
-rw-rw-r-- 1 root 55000 91649 Sep 3 05:37 AdminServices_2013-09-03_05-37-54.txt
-rw-rw-r-- 1 root 55000 133629 Sep 3 05:43 UserManagementService2_2013-09-03_05-43-56.txt
-rw-rw-r-- 1 root 55000 556 Sep 9 08:26 Test_2013-09-09_08-26-23.txt
-rw-rw-r-- 1 root 55000 556 Sep 9 08:37 Test_2013-09-09_08-37-20.txt
-rw-rw-r-- 1 root 55000 133708 Sep 13 02:28 UserManagementService2_2013-09-13_02-28-49.txt
-rw-rw-r-- 1 root 55000 60107 Sep 13 02:30 SecuredService_2013-09-13_02-30-43.txt
-rw-rw-r-- 1 root 55000 133743 Sep 13 04:44 UserManagementService2_2013-09-13_04-44-29.txt
-rw-rw-r-- 1 root 55000 100886 Sep 16 04:27 AdminServices_2013-09-16_04-27-33.txt
-rw-rw-r-- 1 root 55000 556 Sep 20 06:40 Test_2013-09-20_06-40-16.txt
-rw-rw-r-- 1 root 55000 110236 Nov 25 02:35 AdminServices_2013-11-25_02-35-37.txt
-rw-rw-r-- 1 root 55000 142357 Dec 18 03:13 UserManagementService2_2013-12-18_03-13-20.txt
As you can see, i have similar files with different timestamps and different files. So i need the file names which are similar excluding the timestamp and the latest file from them. I want my end result to display the latest, unique filenames with the timestamp.
I am trying opendir but am not seeing any result.
#!/usr/bin/perl
use File::stat;
my $DIR = "/home/DIR";
opendir(my $DH, $DIR) or die "Error opening the dir";
my %files = map { $_ => (stat("$DIR/$_"))[9] } grep(! /^\.\.?$/, readdir($DH));
closedir($DH);
my #sorted_files = sort { $files{$b} <=> $files{$a} } (keys %files);
print $_;
Please help.
The output I am expecting is
AdminServices_2013-11-25_02-35-37.txt
UserManagementService2_2013-12-18_03-13-20.txt
SecuredService_2013-09-13_02-30-43.txt
RegistrationService_2013-05-22_00-20-04.txt
etc...
For a start, opendir isn't the problem. You aren't using the print statement correctly.
foreach(#sorted_files)
{ print $_ . "\n"; }
That outputs the file names. This is only a start to get you some output. I didn't finish the problem.
#!/usr/bin/perl
my $DIR = "/home/DIR";
opendir(my $DH, $DIR) or die $!;
my %files;
while (my $f = readdir($DH)) {
next if $f =~ /^\.\.?$/;
my ($key, $t) = split /_/, $f, 2;
# #{ $files{$key} }{ "t","f" } = ($t, $f)
# if !$files{$key} or $files{$key}{t} lt $t;
my $h = $files{$key} ||= {};
if (! %$h or $h->{t} lt $t) {
$h->{t} = $t;
$h->{f} = $f;
}
}
print "$files{$_}{f}\n" for sort keys %files;
You could use glob:
my $filespec = "/tmp/test*";
my %files;
while (my $file = glob("$filespec") ){
next if $file eq '.' or $file eq '..';
next if ! -f $file;
my $datestamp = (stat($file))[9];
#remove timestamp
my $filename = $file;
$filename =~ s!_\d{4}-\d{2}-\d{2}_\d{4}-\d{4}-\d{4}\.\W{3}\z!!is;
if (! exists $files{$filename} || $files{$filename}<$datestamp){
$files{$filename} = $datestamp;
$files{$filename} = $datestamp;
}
}
foreach my $key (sort { $files{$b} <=> $files{$a} } (keys %files)){
print "$key\t$files{$key}\n";
}
I want to copy specific file done last changes in Oct 16-17,file type is java.
shia#ubuntu:~/code$ ls -alxo
total 96
drwx------ 2 shia 4096 Oct 20 18:54 .
drwxr-xr-x 61 shia 12288 Oct 20 19:24 ..
-rw------- 1 shia 12288 Oct 16 21:52 .Reuse.java.swp
-rw-rw-r-- 1 shia 746 Oct 20 11:16 Argus.class
-rw-rw-r-- 1 shia 302 Oct 20 11:16 Argus.java
-rw------- 1 shia 310 Oct 16 21:30 Call.java
-rw-rw-r-- 1 shia 417 Oct 17 15:20 Ordinary.class
-rw-rw-r-- 1 shia 298 Oct 17 14:57 Overriding.java
-rw-rw-r-- 1 shia 562 Oct 19 21:27 Package.class
-rw-rw-r-- 1 shia 430 Oct 19 21:27 Package.java
-rw------- 1 shia 729 Oct 17 13:50 Reuse.java
-rw------- 1 shia 424 Oct 17 13:47 Room.java
-rw------- 1 shia 321 Oct 16 21:22 Simpleobject.java
-rw-rw-r-- 1 shia 1187 Oct 17 00:04 Static.java
-rw-rw-r-- 1 shia 686 Oct 17 15:20 Super.class
-rw-rw-r-- 1 shia 1010 Oct 17 15:20 Super.java
-rw------- 1 shia 843 Oct 17 14:20 This.java
-rw-rw-r-- 1 shia 521 Oct 17 14:51 b.java
-rw-rw-r-- 1 shia 90 Oct 20 18:54 cp.awk
-rw-rw-r-- 1 shia 105 Oct 20 17:19 file.txt
I try to specific them but i don't know how to copy them.
shia#ubuntu:~/code$ ls -alxo|grep 'Oct 1[67].*java$'|awk '{print $8}'
Call.java
Overriding.java
Reuse.java
Room.java
Simpleobject.java
Static.java
Super.java
This.java
b.java
Any help,thanks a lot!
One way using find:
find . -maxdepth 1 -type f -name "*.java" -newermt 2012-10-16 ! -newermt 2012-10-18 -exec cp '{}' /home/user/dstFolder/ \;
You can use xargs to copy the files found:
...| xargs -i cp '{}' /home/user/dstFolder/
This will copy all the files found to the folder /home/user/dstFolder/.