Hot answers tagged

39

The syntax you used is wrong. cmd &2>1 >file will be split down as cmd & 2>1 >file This will Run cmd as a background job with no redirections In a seperate process (without a command!) will redirect stderr to a file literally called 1 and redirect stdout to file The syntax you want is cmd >file 2>&1 The order of ...


9

There are two problems. The first one is that the order matters, the second one is /dev/tty. Let's use this script as an example script that we want to capture output from: test.sh: #!/bin/bash echo dada echo edada 1>&2 echo ttdada >/dev/tty Now let's see the outputs of the commands: ./testmyscript.sh 2>&1 >/dev/null: edada ...


7

With awk: awk 'BEGIN { t["AA"] = 2 t["AB"] = t["BA"] = 1 t["BB"] = 0 } $3 ~ /^[AB][AB]$/ { $3 = t[$3] } 1' data.txt


7

One way or another, you would need X running. But you can get something like what you're asking with a tiling window manager. One of the earlier ones was "ion" (not as popular now). Further reading (no specific recommendations, of course: that would introduce opinion): Comparison of tiling window managers (Arch wiki) Why You Should Try a Tiling Window ...


6

If one space at the end of the line doesn't hurt you much: $ awk '{for(i=1;i<=NF;i++) if(i==2 || $i~"hello") printf $i" ";print ""}' file ID23 hello1 ID47 hello2 ID49 hello3 hello4 ID53 This doesn't assume anything about the position of the "hello" string.


6

Technically, all you need to run GUI programs is the X server. You can run just a terminal emulator and run all programs from that. However life without a window manager is not comfortable at all: there's no interface to switch between, raise, resize, move, hide, close, and otherwise manipulate windows. So what you need is a window manager, probably without ...


5

Not really. The library checks if it's running in "xterm" (by checking the TERM variable), and if so, just assumes that the application knows how to work with the xterm mouse protocol. With ncurses, gpm is something of a nuisance outside of its use in the Linux console. There are few applications which use it in a terminal emulator. Further reading: ...


5

sed -i.bak -r 's/ AA$/ 2/;s/ (AB|BA)$/ 1/;s/ BB$/ 0/' input -i.bak in place editing and create a backup of original file as input.bak -r extended regex syntax s/ AA$/ 2/ replace ending character sequence of ' AA' with 2 (AB|BA) either AB or BA ; separates the different substitute operations


5

If you want to pursue your attempted perl solution, one way would be to use a hash as a simple lookup table e.g. %table = ("AA" => 2,"AB" => 1,"BA" => 1,"BB" => 0) and then use the value of @F[2] as the key. So for example perl -alne ' %table = ("AA" => 2,"AB" => 1,"BA" => 1,"BB" => 0); print $.==1? $_ : join " ", @F[0,1], $...


4

You have three options: press controlS to stop output, controlQ to resume (this is called XON/XOFF) redirect your output to a pager such as less, e.g., strace date | less redirect your output to a file, e.g., strace -o foo date, and browse it later.


4

1.) Yes, although there is more to it. ttys000 is also a character device sitting in /dev, a user that has permissions to write to the tty group (most users have) can pipe characters into that device and they will appear on the corresponding terminal. ttys* are not real teletypes though, they're emulated ttys, emulated by your (appropriately named) ...


4

What your terminal is doing The "rectangles with the numbers in [them]" are the way that your terminal emulator is displaying a terminal control sequence to you, because it doesn't recognize that sequence. Specifically: There is an ECMA-48 control character (in the C1 group, for the technical) named Operating System Command, abbreviated OSC. It has the ...


4

I don't think this will be possible using simple tools like cut. Or, at least, not easily. Here's a Perl solution: $ perl -lane '$k=join " ",grep{/hello/}@F; print "$F[1] $k" if $k' file ID23 hello1 ID47 hello2 ID49 hello3 hello4 Which you could simplify by using grep first: $ grep hello file | perl -lane 'print "$F[1] ", join(" ", grep{/hello/}@F)' ...


4

Banshee (the animal) is not the same thing as banshee (the package name). These package names are case sensitive, and Debian packages have not been allowed to use upper case letters in their names since over fifteen years. Also, the lines beginning with deb are not commands; they are URIs that should be entered into the apt configuration file for that ...


4

You could use tput to move the cursor to a given line in the screen, e.g., tput cup 11 0 to move it to the twelfth line (values count from zero). Along the same lines, you could use tput to clear from that position to the end of the screen, using the ed capability. Combining, tput cup 11 0 && tput ed might be what was wanted. If you want to ...


3

The cat utility concatenates all its inputs into one data stream. Giving it two files, it produces output consisting of the complete contents of the first file, followed by the complete contents of the second file, in that order. In your case: $ cat file1 file2 >file-1-and-2


3

You can put literal escape characters into /etc/issue as suggested in a comment (Red Hat does this, sometimes). In a quick test, that works, but only colors the text. The background is uncolored. In vi, the text might look like ^[]P7000000^[]P0F0F0F0\S Kernel \r on an \m and the result like this: If you clear the screen, then the colors fill the ...


3

A few keys are used as modifiers (shift, control are the most used). Terminal emulators receive a series of X events, which you can see with xev. The terminal emulator combines some of those events such as shifta using X libraries to get A. For other cases such as function-keys and cursor-keys (called "special keys") there is no predefined transformation ...


3

In a terminal, you generally cannot get all combinations of control- and shift-modifiers to be different values: the basis for control and shift is from US-ASCII (and similar) schemes which defines control and shift for the alphabetic characters plus a few punctuation characters. the combination control+shift usually has no effect, except for special keys. ...


3

You might need to specify the subnet mask to use. The command above is likely assuming that the subnet mask is 255.255.255.255, which is for a point-to-point network. The following might work: sudo ifconfig wlp3s0 down sudo ifconfig wlp3s0 192.168.1.12/255.255.255.0 sudo ifconfig wlp3s0 up (Also check to see that a default route is present, using the ip ...


3

So, you can have the output appear in the other terminal—though I doubt you really want to. To do so: Find the tty of the terminal you'd like the output to go to; the easiest way is to run tty. This should print something like: /dev/pts/42. In the other terminal, run: command > /dev/pts/42 &. If you want to do stderr as well as stdout: command > /...


3

You are likely (attempting) to redirect the output of your shell to a file, e.g., something like bash -i | tee foo $ vim Vim: Warning: Output is not to a terminal While you can read (most) commands from the keyboard via that approach, the output is no longer a terminal. You can recover by closing that shell and capturing output in a different way: the ...


2

If your goal is to monitor the system, you want pam_tty_audit. As the name implies, pam_tty_audit is a pam module which when configured properly, is invoked any time a user opens a session (and gets a TTY). The module records all input & output, and sends everything it records to the auditd daemon. You can then execute queries against the auditd daemon ...


2

If you really want to, you could make a program (or shell script) which calls script writing to a timestamped "typescript" file (and in turn calling your real shell) and make that program your default shell in /etc/passwd. There are a few pitfalls: you may have to add this program to /etc/shells doing this sets the SHELL environment variable, which is ...


2

The interface between the terminal and the application sends bytes, not keys. Printable characters are interpreted as the byte sequence corresponding to the character encoding of the terminal. Function keys are encoded as escape sequences. There are common conventions for those escape sequences but they aren't completely standardized. For more general ...


2

The i3 environment isn't usable in the case described because there's no way to get to a shell. This is a graphical environment (X also known as X11) running in one of Linux's virtual consoles. To switch to a text environment and get a shell, use controlalt together with a function-key for the number of the virtual console that you want to switch to. Most ...


2

If you have a terminal whose description "looks" like xterm, screen assumes it does everything like xterm. For whatever reason, it equates xterm-titles and xterm-mouse features: in termcap.c, it checks if either the TERM environment variable contains the string "xterm" or "rxvt" — or it checks if there is a key definition for kM with the xterm-style ...


2

The problem occurs because some programs do not cleanup properly when they are interrupted. The usual fix would be to use reset (you'll get less satisfactory results using stty sane): resetcontrolJ sends a newline even when your settings are messed up. Further reading: tset, reset - terminal initialization


2

bash has the built-in ability to call an external editor to edit the current command line you're working on. Mouse support depends on the editor used. If you're using bash's emacs-like mode, use Ctrl-XCtrl-E to access the editor. If you're using vi-like keybindings, use ESCv You can also use the built-in fc command to edit any previous line. $ help ...


2

Recent versions of Mac OS X have what's known as System Integrity Protection, aka "SIP", aka "Rootless". It basically makes parts of the file system read-only to everybody, including root. You may have bumped into that. https://en.wikipedia.org/wiki/System_Integrity_Protection The intent is to prevent mistakes and malware from modifying your base operating ...



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