gnu-coreutils

In shell scripting, what does .[!.]* mean?

 ̄綄美尐妖づ 提交于 2019-12-19 08:00:06
问题 A command that prints a list of files and folders in the current directory along with their total sizes is du -sh * . That command alone doesn't, however, list hidden files or folders. I found a solution for a command that does correctly list the hidden files and folders along with the rest: du -sh .[!.]* * . Although it works perfectly, the solution was provided as-is, without any explanation. What is the meaning of .[!.]* , exactly? How does it work? 回答1: It's a globbing pattern that

How can I remove the extension of a filename in a shell script?

一曲冷凌霜 提交于 2019-12-17 03:23:58
问题 What's wrong with the following code? name='$filename | cut -f1 -d'.'' As is, I get the literal string $filename | cut -f1 -d'.' , but if I remove the quotes I don't get anything. Meanwhile typing "test.exe" | cut -f1 -d'.' in a shell gives me the output I want, test . I already know $filename has been assigned the right value. What I want to do is assign to a variable the filename without the extension. 回答1: You should be using the command substitution syntax $(command) when you want to

POSIX analog of coreutils “stat” command?

坚强是说给别人听的谎言 提交于 2019-12-14 03:58:42
问题 Coreutils stat have --format= switch which report different info about file (owner, size, etc) in easy form for readers. POSIX ls utility provide most of this info, but its output is hard to parse. Compare with one-liner: [ `stat -c '%U' $f` = $USER ] && echo "You own $f" || echo Error! Are there stat utility analog in POSIX? 回答1: The short answer is no , POSIX does not provide a simple way to get the same output as stat . However, you can usually get relevant bits using other tools. To get

Why my asm code can not link with clock_gettime and attr_copy_fd?

不问归期 提交于 2019-12-12 06:32:09
问题 I am trying to compile a asm code disassembled from GNU coreutils. In the asm code, I see this: extrn memchr@@GLIBC_2_0:near extrn clock_gettime@@GLIBC_2_0:near extrn attr_copy_fd@@ATTR_1_1:near and I declare externs like this: extern attr_copy_fd extern clock_gettime extern memchr then asm like this: nasm -f elf final.s -o final.o gcc -W -o final final.o And I got errors : final.o: In function `loc_804BD8D': final.s:(.text+0x2111): undefined reference to `attr_copy_fd' final.o: In function

Print duplicate count without removing duplicates in Terminal

瘦欲@ 提交于 2019-12-12 05:11:33
问题 I am new to working with the Terminal on mac and have a large .tsv file that consists of a list of items, and two values next to it. I would like to be able to print the number of duplicates next to the first occurrence of the item Without removing additional data. I am aware of cut -f 1 | sort | uniq -c but this removes a lot of valuable data I would like to keep for analysis. I'm reading about awk and grep but I think I could use a little help. This is an example of the file I'm trying to

tar: preserving only file names, contents and executable bit

拥有回忆 提交于 2019-12-11 04:39:01
问题 I want to use tar to preserve only file names, file contents, and the executable bit for the owner (and ignore the executable bit for group and other). The command I have come up with is tar -cf <name>.tar --numeric-owner --owner=0 --group=0 --mode="go-rwx,u-rw" <files> I would like the output <name>.tar not to change unless I change the file name, file contents, or owner's executable bit in one or more of <files> . Assume that the <files> are in sorted order by name. Will the command that I

top command's CPU usage calculation

送分小仙女□ 提交于 2019-12-10 13:56:44
问题 I am trying to use GNU coreutil top's formula for calculating CPU usages in percentage. But top is using some half_total, to calculate the percentage, which is adding 0.5 to the percentage. In utils.c of top's source, the following line (at 3.8 beta1, it is in line number: 459): - *out++ = (int)((*diffs++ * 1000 + half_total) / total_change); This translates to : ( (*diffs++ * 1000) / total_change ) + 1/2 So, it always gives a number, which is: "10 times the percentage, plus 0.5". So if the

GNU ls from Coreutils missing OS X ACL implementation

不羁岁月 提交于 2019-12-07 15:04:25
I'm using brew to retrieve and install common GNU versions of terminal commands and utils with brew install coreutils . Then in my .bash_profile I'm including their PATH with if [ -d $(brew --prefix coreutils)/libexec/gnubin ]; then PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH" fi so far so good, I can use use the GNU version of coreutils. The problem comes from ls . Apple implement ACL that is not implemented on GNU ls . I discovered this by banging my head many times and not understanding why (for example) ls -le@ would give me error ls: invalid option -- 'e' . So now I understood

Where are info document files in Mac or in Linux, and how can I install some missing info files?

半世苍凉 提交于 2019-12-06 09:24:08
I wanted read coreutils info, but I could not find it. Now, I wonder where the info documents in my computer (mac or linux). I want to know how I can install info files. Thank you, SangChul I suppose you entered info coreutils on the command line, which returned the info top directory instead of the coreutils info page? In that case, here is what I would do (on ubuntu 15.10, and probably on any GNU/Linux OS). Download the coreutils info document from the gnu project: wget http://www.gnu.org/software/coreutils/manual/coreutils.info.tar.gz Extract the (compressed) tar archive that you downloaded

How to get all fields in outer join with Unix join?

此生再无相见时 提交于 2019-12-04 11:13:08
问题 Suppose that I have two files, en.csv and sp.csv , each containing exactly two comma-separated records: en.csv : 1,dog,red,car 3,cat,white,boat sp.csv : 2,conejo,gris,tren 3,gato,blanco,bote If I execute join -t, -a 1 -a 2 -e MISSING en.csv sp.csv the output I get is: 1,dog,red,car 2,conejo,gris,tren 3,cat,white,boat,gato,blanco,bote Notice that all the missing fields have been collapsed. To get a "proper" full outer join, I need to specify a format; thus join -t, -a 1 -a 2 -e MISSING -o 0,1