22 votes
Accepted

scp many files without reentering password, all different paths

With OpenSSH you can use its "master mode", whereby you first run an ssh which will establish the connection, authenticate, and then place itself in the background while keeping its ...
LL3's user avatar
  • 5,428
20 votes

Can I run GUI programs without needing a desktop environment?

You can get apps that talk directly to the framebuffer (VLC or fbi), but IMHO, it's not worth the hassle. Just go for a lightweight window manager, like OpenBSD's cwm, dwm, i3, spectrwm... the list ...
Zé Loff's user avatar
  • 2,110
15 votes

Can I run GUI programs without needing a desktop environment?

A Window Manager (wm) is what you are thinking of. It's not a full-blown Desktop Environment (de), but can open apps/terminals with a keybinding and uses less resources. There are lists of window ...
killertofus's user avatar
13 votes
Accepted

How to check if a string ended with an Escape Sequence (\n)

You describe the last character of the string, not characters, so you're looking for a way to detect if it's the single-character \n (aka newline or, in ASCII, line feed). You are not looking to ...
Sotto Voce's user avatar
  • 4,131
13 votes
Accepted

Order of shell expansions: command substitution versus arithmetic expansion

Your book is not exactly correct. See man bash for the exact order: The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and ...
choroba's user avatar
  • 47.3k
12 votes
Accepted

How to convert all text into 1 except "0"s and first two fields in a csv file?

With awk you could do: awk 'BEGIN {FS=OFS=","} {for (i=3;i<=NF;i++) {$i==0?1:$i=1}} 1' test.csv BEGIN {FS=OFS=","} - set in- and output separator to comma for (i=3;i<=NF;i++)...
FelixJN's user avatar
  • 13.6k
12 votes
Accepted

Grep for lines starting with strings from a pattern file

You could prepend ^ to all lines in PATERN_FILE to pass to grep -f: paste -d '^' /dev/null PATTERN_FILE | grep -f - SEARCH_FILE Or sed 's/^/^/' PATTERN_FILE instead of paste. Now, if the lines in ...
Stéphane Chazelas's user avatar
11 votes

What does >&- do in a unix / linux terminal?

Quoting the POSIX specification for the sh language: 2.7.6 Duplicating an Output File Descriptor The redirection operator: [n]>&word shall duplicate one output file descriptor from another, or ...
Stéphane Chazelas's user avatar
11 votes
Accepted

How does sort -n command know what it needs to sort by in a file that contains both numbers and text?

Many options affect how sort compares lines That's from info coreutils sort invocation which explains how sort works: A pair of lines is compared as follows: sort compares each pair of fields (see --...
don_crissti's user avatar
  • 82.9k
11 votes
Accepted

Combine two files as part of a command line parameter

Assuming you want the command to see a "filename" that gives the contents of both files when read, then process substitution and cat are what you want: csvgrep -f <(cat list1.txt list2....
ilkkachu's user avatar
  • 139k
10 votes

scp many files without reentering password, all different paths

With the SSH suite, if you want to avoid typing password multiple times, you should use ssh keys. They are generated by ssh-keygen, can be sent to the other host with ssh-copy-id (only the public key ...
Frédéric Loyer's user avatar
10 votes
Accepted

Command(s) to know If the current RAM installed by slot is ECC/Non-ECC and Buffered/Unbuffered

Run dmidecode -t memory. Handle 0x001A, DMI type 17, 40 bytes Memory Device Array Handle: 0x0019 Error Information Handle: Not Provided Total Width: 64 bits Data Width: 64 bits ...
tink's user avatar
  • 6,764
10 votes
Accepted

What free tool does Nautilus use to extract RAR files?

Nautilus uses libarchive to process archives; this supports some RAR formats without any external helpers. bsdtar is a command-line tool using the same library; in Debian it’s packaged as libarchive-...
Stephen Kitt's user avatar
10 votes
Accepted

Alternatives to file polling?

You could create a named pipe with mkfifo instead, and read that. Reads will block until something has written to the pipe, no manual polling required. Something like: tmp_input=$(mktemp -d ./...
muru's user avatar
  • 73k
9 votes

How to check if a string ended with an Escape Sequence (\n)

In any POSIX shell: case "$string" in (*' ') echo The string ends in a newline character;; (*) echo It does not;; esac In shells including bash that support the $'...' form of quote ...
Stéphane Chazelas's user avatar
8 votes

I want to copy files that do not have a number in their name

With zsh: set -o extendedglob cp -- ^*<->*(D^/) /path/to/destination/ Or cp -- ^*[0-9]*(D^/) destination/, <-> matching any sequence of one or more ASCII decimal digits (a form of <x-y&...
Stéphane Chazelas's user avatar
8 votes

Can I run GUI programs without needing a desktop environment?

Yes, this is perfectly possible; I used to do this all the time. A bit of background: What we talk about under the name 'X Windows' is in fact 'the X Window System', which encompasses a network ...
j4nd3r53n's user avatar
  • 715
7 votes
Accepted

filter lines based on some criteria

Here's a perl way: $ perl -F'\t' -lane ' if(/^#/){ print; next }; $F[7] =~ /\bSVLEN=(\d+)/; $svlen=$1; $F[7] =~ /\bSVCALLERS=([^;]+)/; @callers=split(/,/,$1); print if $svlen > 100 ...
terdon's user avatar
  • 242k
7 votes
Accepted

Extract data which is inside square brackets and separated by comma

You could just remove the leading [', trailing '] and replace all ', ' with a newline, and delete a [] or @as [] line which I see gsettings using to represent empty lists of strings (where the @as ...
Stéphane Chazelas's user avatar
7 votes
Accepted

Process CSV file through command line: Remove only middle rows between consecutive row entries if consecutive entries have the same 2nd column value

Using awk: BEGIN { FS = "," } /^[*]/ { print; next } { if (NR > 1 && $2 == word) { tail = $0 ++count } else { if (...
Kusalananda's user avatar
  • 335k
6 votes
Accepted

How to wait for the first command but not the second, where the two are joined by the && operator

A bit more verbose, but this should work: for file in *.mp4; do if command1 "${file}"; then command2 "${file}" & fi done
muru's user avatar
  • 73k
6 votes

Combine two files as part of a command line parameter

Many programs allow - to be used as a filename to represent standard input or output (depending on whether it's an input or output file). So you can try piping to csvgrep and using -f -. cat list1.txt ...
Barmar's user avatar
  • 9,947
5 votes
Accepted

Which xdg-desktop-portal am I currently using?

There isn’t one portal that’s currently in use: portals generally handle a subset of the available interfaces. Thus on my system, gnome-keyring.portal says that it should be used for GNOME, and ...
Stephen Kitt's user avatar
5 votes

How to convert all text into 1 except "0"s and first two fields in a csv file?

using perl: $ perl -F, -lne 'my @out = map { /^0$/ ? 0 : 1 } splice @F,2; unshift @out, @F; print join(",",@out)' Test.csv Iss1,1,0,0,1,0,0,0,1,0,0 Iss1,11,...
cas's user avatar
  • 78.7k
5 votes
Accepted

Bash script with command line options gets stuck and doesn't set default values for variables

Generally it's easier to help if there's a "minimum verifiable example" of code - something just sufficient to demonstrate the problem. However, here I think I can see the problem. When ...
Chris Davies's user avatar
5 votes

Using the command line, multiply all entries within a column to a fixed number, but only if the line is not a comment

Maybe just use awk to do the whole thing: awk ' ( FNR==1 ) { print "0 0 0" } # add a first line containing "0 0 0" /^[0-9]/ { $1 *= 6.2832 } /^[a-zA-Z]/ { $0="* " $0 ...
Olivier Dulac's user avatar
5 votes
Accepted

Using the command line, multiply all entries within a column to a fixed number, but only if the line is not a comment

Using any POSIX awk: $ cat tst.awk NR == 1 { CONVFMT = "%.17g" pi = atan2(0, -1) two_pi = 2 * pi print 0, 0, 0 } { if ( $1 ~ /^[0-9]/ ) { $1 *= two_pi } ...
Ed Morton's user avatar
  • 31.7k
5 votes

Can I run GUI programs without needing a desktop environment?

It sounds like you want an X11 (or Wayland) window server running for graphical applications. I suggest you install and configure a minimal window manager (I recall that pekwm doesn't get much in your ...
Toby Speight's user avatar
  • 8,676
5 votes

Alternatives to file polling?

Have you heard of inotifywait? It sounds like what you want. (I often use entr to execute on file changes - but I think you can achieve your goal with inotifywait.)
Popup's user avatar
  • 544
5 votes

How to place my own code snippets on command line à la history?

A quick and dirty contraption for interactive Bash (my bash --version prints 5.2.15): Put your desired (single-line) commands in ~/.commands. Define the following helper function: _get_command () { ...
Kamil Maciorowski's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible