Monday, May 10, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


How can I push to GitHub when it's blocked?

Posted: 10 May 2021 10:05 AM PDT

Right now, https://github.com is blocked with 127.0.0.1 github.com www.github.com in the /etc/hosts file. However, I need to push from git to GitHub. How can I achieve this without editing my hosts file?

grep -f works faster than grep without -f

Posted: 10 May 2021 09:40 AM PDT

Please advise why grep -f works faster than grepping multiple keywords indidiuvally on same file.

Some cases, both results are produced in seconds. On certain files, normal grep takes 15 mins and grep -f takes less than a minute.

grep -f <search_pattern_50keys_file.txt> <file_name>  grep search_key_1 <file_name>  grep search_key_1 <file_name>  ...  ...  grep search_key_50 <file_name>  

Regards, Veera

Truncate file that is opened in another procces

Posted: 10 May 2021 09:40 AM PDT

If I try truncate -s 0 log.log (:>log.log has same behavior) the displayd space on disk do become free but the size (ls -l) of file is still the same (tho du shows less). As far as I understand, it happens because the pointer is still "old".

This behavior causes that I cannot use cat ... | grep ... command: CLI says that file is binary. So the only way is to use less or another commands.

So, how do I truncate file, that is opened in write mode in another proccess and have correct file size after truncate? I need data in log.log to be truncated to another file, or just delete whole data in file without deleting the file itself

How to filter the highest value using awk command or other command [duplicate]

Posted: 10 May 2021 09:11 AM PDT

command |awk -F'|' '{print $4}' | sort -nrk1

Duration  300  300  1000  500  20  10  80  100  0  0  0  0  0  

I want to show the highest value using awk command like this, starting in 300 value

1000  500  300  300  

Not including the lower value.

How do you create a functionnal desktop folder after deleting it?

Posted: 10 May 2021 09:45 AM PDT

On Mate desktop I accidentally did a rm -rf * in home folder, now every file that I create inside this folder appears on the Desktop, I created a new Desktop folder but it's not enough to fix it.

CentOS Stream graphical package management tool / dnf frontend

Posted: 10 May 2021 10:07 AM PDT

I've just installed fresh and wet CentOS Stream.

Unfortunately yumex-dnf is no longer in the default repos.

Is it dead? What was it replaced by?

Readline Delay on `.` in Vi Mode

Posted: 10 May 2021 08:24 AM PDT

When I press . in Vi/command mode there is always a delay (half a second) before the last action gets repeated.

Repro:

  • In Bash insert mode enter foo bar foobar
  • press esc, type 0
  • enter dw to delete foo
  • press . to delete bar (there is a delay)
  • press . to delete foobar (there is a delay)

Is this normal/a bug or some option that waits for another key press?

Change language for one user on Fedora 34 w/ XFCE

Posted: 10 May 2021 08:23 AM PDT

I'm in a situation where I have to set the language for one user on Fedora 34 (with XFCE).

I found the settings to set the system language, but I can't figure out how to change the language for a user. The language locale in question is already installed (pl_PL.utf8), and I've set LANG=pl_PL.utf8 in ~/.config/locale.conf, but XFCE is still in english.

I read somewhere, that I should be able to select the locale while logging in, but it doesn't seem to work in Fedora. I'm not given the option to select a locale.

I cannot find it anywhere in the settings manager or in one of the hidden files in the user's home directory.

Just for clarification: I don't mean the system wide language! That one is quite easy to find, I mean the language for this one user, nothing else.

Why can't I connect to my remote desktop with rdesktop command?

Posted: 10 May 2021 08:52 AM PDT

I can connect remote desktop in remmina with RDP protocol. It encounters an error when I connect to the remote desktop with rdesktop command:

rdesktop  192.168.31.21  Invalid MIT-MAGIC-COOKIE-1 keyERROR: Failed to open display: :0  

How can I fix it?

How to remove spaces from specific column using awk

Posted: 10 May 2021 09:32 AM PDT

I just want to modify the second column "Name" and remove all the spaces from between the name and leave the rest of the txt file untouched and further, print it.

Here is my input (Tab separated fields):

Roll NO Name         RandomColumn1    RandomColumn2   1       Jason James  my value        my val 3    

My Desired output:

Roll NO Name        RandomColumn1  RandomColumn2   1       JasonJames  my value        my val 3  

Command that I had been using but been unsuccessful with:

 awk '{$3=$4;  print }' | sed "s/^ *//"  

Why does AWK print "0xffffffffbb6002e0" as "ffffffffbb600000" using printf?

Posted: 10 May 2021 09:13 AM PDT

I have been experimenting with hex numbers in AWK (gawk), but sometimes when I print them using e.g. printf, they are printed with some LSBs masked out, like in the following example:

awk 'BEGIN { x=0xffffffffbb6002e0; printf("%x\n", x); }'  ffffffffbb600000  

Why do I experience this behaviour and how can I correct it?

I'm using awk on a Debian system.

Substitute entire line while removing newline of that particular line

Posted: 10 May 2021 08:38 AM PDT

I'm trying to substitute (with sed) an entire line containing a specific word and the newline at the end. Here the testfile:

this # target for substitution  this is a test  another test?  

Now, I already posted here, and from the linked post, I understand how to do this in some way:

sed 's/^this$/test/g' testfile  

That works, or at least it seems so, because the newline at the end of the word this is still there:

test # target for substitution but newline is still there  this is a test  another test?  

Given the above, I'm also fully aware sed can't match the newline directly (although I do recall that I could use '\n' in certain version of sed, but that's beside the point).

I do know how to at least delete the entire word/line and the newline:

sed '/^this$/d' testfile  

Except I need to substitute it instead.

How can I do this? (with sed preferably)

Does Linux have their own keys?

Posted: 10 May 2021 09:55 AM PDT

I don't own a Linux computer, or even a Unix one, so I decided to ask.

In Windows, they have their own key named the Windows key (). On its own, it opens the start menu and pressing it with another key will perform a certain function.

In Apple's macOS, they have their own key named the command key (). It acts like Windows' Ctrl key. For Windows users, if they would use macOS, they can simply replace Ctrl with for most functions, if not all.

As for Linux, I have no idea what keys they have that others don't.

So does Linux have their own keys?

How to get shell TAB-completion to work when I redirect grep ag ack output to vim?

Posted: 10 May 2021 10:16 AM PDT

I define ag as bash function, to make usage relatively transparent

ag() { [ $# -gt 0 ] && vim -c silent\ SyntasticToggleMode -c copen -q <(/usr/bin/ag --silent --vimgrep --nogroup "$@") || /usr/bin/ag; }  

This works fine, but if I try to TAB-complete filename, vim gets executed immediately and it gets stuck with

$ [git:master] ag sense<TAB>  Vim: Warning: Output is not to a terminal  

Only way out is to kill stuck vim process from another shell.

What's going wrong here and how can this bash function be upgraded (or find some alternative) to make it TAB-completion compatible ?

EDIT ag doesn't ship any upstream completion

$ [git:master] complete -p ag  -bash: complete: ag: no completion specification  

How to install dwm in void linux

Posted: 10 May 2021 09:27 AM PDT

What is it, the dependencies for comiple dwm from scratch for install dwm (suckless windows manager) in arch linux , i need to install xorg and make and other

How to connect with wifi in void linux from scratch

Posted: 10 May 2021 09:20 AM PDT

The instalation of void linux , without desktop manager, it's come without Network-Manager package,

  • so i can't use nmtui and iwctl as arch linux.
  • also void linix it's not support system.d , it's runit system
  • what's the better why to connect to wifi in first time:

Why do all users start in /root instead of their home directories after su as root?

Posted: 10 May 2021 08:08 AM PDT

I feel like this should be straightforward but I've never seen anyone ask this that I can tell. The situation is pretty straight forward. Whenever I become a user, ie su user it always starts in /root directory instead of it's home directory. Let me show you.

[root@st-test2 ~]# grep "postgres" /etc/passwd  postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql/:/bin/bash  [root@st-test2 ~]# su postgres  bash-4.2$ pwd  /root  [root@st-test2 ~]# ls -lhart /var/lib |grep postgres  drwx------.  4 postgres postgres   86 May  5 16:07 pgsql  

So, you can see that the postgres user's home directory exists and that its set in /etc/passwd...but for some reason, they start in the root directory. This happens with every user that I have created and I have no idea why. I can't say that I've ever seen this happen before either.

Is there a light-weight version of X?

Posted: 10 May 2021 08:13 AM PDT

I am setting up a computer as a an older tablet "PC".

It will run Debian and a single application, without any window manager. No Internet is needed, nor is remote access.

To ensure it runs as fast as is possible, I wonder if there is a lightweight version of X, with lots of features removed, available on Debian?

Can I ignore certain irrelevant lines when creating/applying a patch with diff/patch?

Posted: 10 May 2021 09:31 AM PDT

File A

Apples  Bananas  Clementines  Dates  

File B

Apples  Blueberries  Cherries  Dates  

I want to diff A and B to generate a patch that when applied to C will change the line Clementines > Cherries but will ignore the second line (Blueberries/Blackcurrants/whatever).

File C (before patch)

Apples  Blackcurrants  Clementines  Dates  

File C (after patch)

Apples  Blackcurrants  Cherries  Dates  

Ideally I would like a patch with context, as this sequence is not guaranteed to always appear in the same place in the file. In my mind the context would contain some form of wildcard line after Apples and before Clementines.

I am open to manually editing the diff output if necessary, but if there's a repeatable command for creating a context-based diff with a wildcard in place of a specific regex match that would be great.

I would like to be able to send this patch to a friend who has file C and have them run a patch command without having to manually edit anything on their end.

How can this be done?

Vim set listchars to only show non-breakable spaces, not tabs

Posted: 10 May 2021 10:10 AM PDT

In vim, I'd like to set nbsp to ! or · . But I'm not concerned with tab.

In my .vimrc, I have :

 set listchars=nbsp:·   set list  

However, when I open a vim sesion, I still see tab showing as ^I.

Running

:set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<  

... it executes without error and I can see the changes.

If I run

:set listchars=nbsp:!,tab:>  

or

:set listchars=nbsp:!,tab:  

I get

E474: Argument invalide: listchars=nbsp:!,tab:>  

What is going on here? How can I set listchars so vim doesn't highlight tab and just nbsp?

Running VIM - Vi IMproved 7.4

Why does my window overlap when I using i3 windows manager and Nvidia integrated graphics?

Posted: 10 May 2021 08:51 AM PDT

Problem Description:

When I use the i3 windows manager for my desktop, the Xorg as background server, and with the Nvidia closed-source driver. I encounter the problem window overlap sometimes when I use the <$mod + mouse-left> to move it, which like below:

Problem picture

My graphic card:

I have two graphic card, Built-in graphics card and a Nvidia GTX 1660, but my motherboard only support one each time, below is my lspci information about the card:

$ lspci | grep -i vga  01:00.0 VGA compatible controller: NVIDIA Corporation TU116 [GeForce GTX 1660] (rev a1)                   

Question:

How do I fix the window overlap, without being prevented from using the Nvidia GPU?

What I tried

I googled my questions, which may be related to the file /etc/X11/xorg.conf, below is my piece about it:

# nvidia-xconfig: X configuration file generated by nvidia-xconfig  # nvidia-xconfig:  version 418.56    Section "ServerLayout"      Identifier     "Layout0"      Screen      0  "Screen0"      InputDevice    "Keyboard0" "CoreKeyboard"      InputDevice    "Mouse0" "CorePointer"  EndSection    Section "Files"  EndSection    Section "InputDevice"      # generated from default      Identifier     "Mouse0"      Driver         "mouse"      Option         "Protocol" "auto"      Option         "Device" "/dev/psaux"      Option         "Emulate3Buttons" "no"      Option         "ZAxisMapping" "4 5"  EndSection    Section "InputDevice"      # generated from default      Identifier     "Keyboard0"      Driver         "kbd"  EndSection    Section "Monitor"      Identifier     "Monitor0"      VendorName     "Unknown"      ModelName      "Unknown"      HorizSync       28.0 - 33.0      VertRefresh     43.0 - 72.0      Option         "DPMS"  EndSection    Section "Device"      Identifier     "Device0"      Driver         "nvidia"      VendorName     "NVIDIA Corporation"  EndSection    Section "Screen"      Identifier     "Screen0"      Device         "Device0"      Monitor        "Monitor0"      DefaultDepth    24      SubSection     "Display"          Depth       24      EndSubSection  EndSection  

Warm up ZFS cache - force file into l2arc

Posted: 10 May 2021 09:11 AM PDT

Currently I use:

while true; do     cat file >/dev/null    echo 3 | sudo tee /proc/sys/vm/drop_caches  done  

to warm up ZFS's l2arc. When I can see accesses are primarily coming from the cache disk, it is done.

But I feel pretty silly doing that.

Is there a way I can tell ZFS: "Hey, could you please put this file into l2arc?"

I do not want to lock the file in l2arc. I just want have it in l2arc the same way it is in l2arc after running the above.

how to check virtual memory page size without getconf

Posted: 10 May 2021 08:39 AM PDT

I need to check vm pagesize on an embedded device running linux. Do not have the getconf to check the same.

Is there a way to check the page size in linux without getconf, is it possible to derive it from some proc entries.

how to start a new terminal with agetty (not systemd)

Posted: 10 May 2021 09:35 AM PDT

For the sake of learning, I wanted to start a new terminal (let's say tty10) from the command prompt. I know I can just run sudo systemctl start getty@tty10.service, but I want to run it manually for now. I checked systemd service getty@ and it uses the following command line:

/sbin/agetty -o '-p -- \\u' --noclear %I $TERM  

So, trying to replicate that from a terminal (tty1) I ran this:

sudo /sbin/agetty -o '-p -- <username>' --noclear tty10 linux  

It indeed started a new login prompt at terminal 10, I enter the username but it never prompts for a password. Besides, when I go back to terminal 1 I see it logged out. What am I doing wrong?

GRUB boot loader not shown on system startup

Posted: 10 May 2021 09:02 AM PDT

I am using Windows 10 installed on SSD( 256 GB) and Kali Linux Installed on HDD(1 TB), After successful installation of Kali Linux, the GRUB bootloader is not displayed on startup. I am not getting an option to choose Kali Linux or Windows 10 during startup. The system directly boots to Windows 10 even though I already installed Kali Linux on the system.

How can I get option to choose Kali Linux or Windows 10 during startup?enter image description hereenter image description here

find and replace "tabs" using search and replace in nano

Posted: 10 May 2021 08:31 AM PDT

How can I search and replace horizontal-tabs in nano? I've been trying to use [\t] in regex mode, but this only matches every occurrence of the character t?

...just been using sed 's/\t//g' file which works fine, but I would still be interested in a nano solution.

Shell variable in <a href> tag

Posted: 10 May 2021 08:22 AM PDT

I wrote a simple bash script, those send mail with html link.

#!/bin/bash  ASS=10  sendmail kenny@gmail.com <<EOF  Subject: Simple title  <html>  <body>  this is just a link  URL: <a href="http://test.site/index?redirect=tail_$ASS_Tail\$1&noAUTO=1">Go to site</a>  </body>  </html>  EOF  

But when email arrived, $ASS not insert in link and i see the following http://test.site/index=tail_$1&noAUTO=1 How fix it?

Find files older than a given file - a few hours

Posted: 10 May 2021 10:07 AM PDT

I'm using the following to find all files that are older than a reference file...

find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt  

... which works as expected.

However, I want to add a bit of leniency to the time, so that it only finds files that are older than the reference file - a few hours.

For example, if I have a reference file with modification date May 26 11:26, I want to find files that are older than May 26 9:26 (ie, with a 2-hour leniency on the reference file).

In this example, the following would be correct matches...

May 26 7:00  Apr 15 14:00  

... and the following should not match...

Jun 13 9:00  May 26 10:00  

Ultimately I want to delete all the files that I find, so would love it if find was able to handle this requirement? Otherwise, are there any other alternatives that will allow me to delete these files without being too convoluted?

How do I remove a user from a group?

Posted: 10 May 2021 08:08 AM PDT

Which command should I use to remove a user from a group in Debian?

When adding a user to a group, it can be done with:

usermod -a -G group user  

However, I could not find a similar command (accepting a group and user as arguments) for removing the user from the group. The closest I could get is:

usermod -G all,existing,groups,except,for,group user  

Is there a command like usermod OPTION group user with OPTION an option to make usermod (or a similar program) remove the user from group?

How to strip multiple spaces to one using sed?

Posted: 10 May 2021 09:00 AM PDT

sed on AIX is not doing what I think it should. I'm trying to replace multiple spaces with a single space in the output of IOSTAT:

# iostat  System configuration: lcpu=4 drives=8 paths=2 vdisks=0    tty:      tin         tout    avg-cpu: % user % sys % idle % iowait            0.2         31.8                9.7   4.9   82.9      2.5    Disks:        % tm_act     Kbps      tps    Kb_read   Kb_wrtn  hdisk9           0.2      54.2       1.1   1073456960  436765896  hdisk7           0.2      54.1       1.1   1070600212  435678280  hdisk8           0.0       0.0       0.0          0         0  hdisk6           0.0       0.0       0.0          0         0  hdisk1           0.1       6.3       0.5   63344916  112429672  hdisk0           0.1       5.0       0.2   40967838  98574444  cd0              0.0       0.0       0.0          0         0  hdiskpower1      0.2     108.3       2.3   2144057172  872444176    # iostat | grep hdisk1  hdisk1           0.1       6.3       0.5   63345700  112431123    #iostat|grep "hdisk1"|sed -e"s/[ ]*/ /g"   h d i s k 1 0 . 1 6 . 3 0 . 5 6 3 3 4 5 8 8 0 1 1 2 4 3 2 3 5 4  

sed should search & replace (s) multiple spaces (/[ ]*/) with a single space (/ /) for the entire group (/g)... but it's not only doing that... its spacing each character.

What am I doing wrong? I know its got to be something simple... AIX 5300-06

edit: I have another computer that has 10+ hard drives. I'm using this as a parameter to another program for monitoring purposes.

The problem I ran into was that "awk '{print $5}' didn't work because I'm using $1, etc in the secondary stage and gave errors with the Print command. I was looking for a grep/sed/cut version. What seems to work is:

iostat | grep "hdisk1 " | sed -e's/  */ /g' | cut -d" " -f 5  

The []s were "0 or more" when I thought they meant "just one". Removing the brackets got it working. Three very good answers really quickly make it hard to choose the "answer".

No comments:

Post a Comment