date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,501,772,142,000
I can use the following command to get a list of directories and their sizes and sort them from largest to smallest (in the example I renamed the directories to numbers to make this easier to understand). $: du -sk [a-z]* 2>/dev/null | sort -nr 413096 one 106572 two 97452 three 76428 four 55052 five 45068 si...
If you are confident that the directory names do not contain whitespace, then it is simple to get all the directory names on one line: du -sk [a-z]*/ 2>/dev/null | sort -nr | awk '{printf $2" "}' Getting the information into python If you want to capture that output in a python program and make it into a list. Using...
Listing directories based on size from largest to smallest on single line
1,501,772,142,000
I need to compare a command output with a string. This is the scenario: pvs_var=$(pvs | grep "sdb1") so pvs var is: /dev/sdb1 vg_name lvm2 a-- 100.00g 0 if [[ $($pvs_var | awk '{ print $2 }') = vg_name ]]; then do something fi The issue is that the output of the if statement is -bash: /dev/sdb1: Permission den...
You are attempting to execute the contents of $pvs_var as a command, rather than passing the string to awk. To fix this, add an echo or printf in your if statement: if [[ $(echo "$pvs_var" | awk '{ print $2 }') = vg_name ]]; then do something fi
How to treat a command output as text
1,501,772,142,000
I was trying to export the Python environment requirements and this is what I intended to do: conda list -e > requirements.txt However I mistakenly typed this instead: conda list -e -> requirements.txt It still works, but the file is having fewer lines in the content. I want to know what exactly happened. I searched...
The -e option doesn't take any argument after it, so the - is just a regular argument to list. The first and only positional argument conda list has is a regular expression, which causes it to List only packages matching this regular expression. In your case, it will have listed only packages matching - (so, contain...
What's going on with this dash '-' thing?
1,501,772,142,000
I want to modify my output in bash for better view of output. Simply put \n before this. How can I change it in .bashrc? For example: It's default: root@comp:$ abc bash: abc: command not found I want this: root@comp:$ abc bash: abc: command not found
You can trap the DEBUG signal: trap 'printf "\n"' DEBUG DEBUG trapped command printf "\n" will be run before the command is executed unlike PROMPT_COMMAND which will be run after the command is executed. You can add this to your ~/.bashrc to make it permanent. Example: $ abc No command 'abc' found, did you mean: .......
Newline ("\n") before output in bash
1,501,772,142,000
I want to run a command, then show the output on the screen as well as output it to a log file, currently I use tee -a, but the problem is tee doesn't preserve colours, and currently I have not been able to find a way to do that.
tee doesn't know anything about colors. But some applications produce colored output only when their output goes to a terminal, not when it goes to a regular file or to a pipe. In such cases, check if the application can be told to produce colored output anyway. For example, under OSX, for ls, you need to set the envi...
Show output on terminal and output to log file, without using tee
1,501,772,142,000
I often use dpkg or aptitude combined with grep when I want to list certain packages available or installed on my system, but I noticed that when I add | grep, the output lines look a little bit different. Here's a pure dpkg output, the first command was typed when the terminal was smaller, the second one when the ter...
It is not grep changing the output. It is dpkg and aptitude. They check whether the output goes to a terminal or to some other command. If it is a terminal they adapt their own output width to match the terminal size. If the output does not go to a terminal, the command has no idea what column size would be appropriat...
Why does grep change the length of output lines?
1,501,772,142,000
I have a python script. It has a SimpleLogger with sys.stdout as output_stream. logger = SimpleLogger(level=LogLevel.DEBUG) When I run it in console, I get the logs properly, but whenever I redirect the output to a file, nothing is found in the target. I tried multiple ways: python server.py > /tmp/x.log 2>&1 pyth...
This is probably just due to buffering. You will only see something in the file when enough output has been accumulated. You can try using python -u to ask for unbuffered output, or set environment variable PYTHONUNBUFFERED= to any non-empty string, as documented in the Python command line documentation, or add a .fl...
python script output won't be directed to file
1,501,772,142,000
I understand that set -x gets a Bash user into debug mode and I feel that working full time in debug mode will help me handle possible problems better in Bash. I experience a problem when working with set -x: When I try to use the native tab completion of my distro (Ubuntu 16.04) to complete a directory's name, I get ...
This is due to the programmable completion feature of the shell that you are using. If you're happy with basic tab completion for commands and filenames in bash, then running complete -r in your ~/.bashrc will remove any "fancy" (programmable) completion that involves calling functions etc. in the current shell's env...
set -x: tab completion results in messy output when working in debug mode
1,501,772,142,000
If you redirect the nohup application as: nohup bash -c "printf \"command\n\"" &> /dev/null The nohup.out file is not created, however the terminal I ran the command also do not get any output. How to keep the terminal output from the command but not create the nohup.out file?
Try this, To get the STDOUT and STDERR both on console and in a nohup.out file, execute the following before executing your nohup command. exec > >(awk '{ print $0; fflush();}' | tee -a nohup.out) exec 2> >(awk '{ print $0; fflush();}' | tee -a nohup.out >&2) nohup bash -c "printf \"command\n\"" & EDIT: If you want...
How to not create the nohup.out file, but keep the terminal output?
1,501,772,142,000
I split a gz file using gunzip piped to split: time gunzip -c file.gz | split -l 500 -d -a 4 - pref_ Which generates the following files: pref_0000 pref_0001 I'd like to pipe those files to zip them again. I tried the following: gunzip -c file.gz | split -l 500 -d -a 4 - pref_ | echo "file produced:" - # Nothing g...
You could use the --filter option of split to invoke zip on each split file gunzip -c file.gz | split -l 500 -d -a 4 - pref_ --filter='zip $FILE'
redirect split output
1,501,772,142,000
I'm learning a bit of Bash by using xargs to list whois records for a bunch of IP addresses. The command used is: echo "$1" | tr "\n" "\0" | xargs -0 -n 1 -t -P 3 -I % sh -c 'echo "\n 44rBegin whois record -- \n"; whois -h whois.arin.net % ; echo "\n 44rEnd whois record -- \n"' The executed commands are: sh -c echo ...
Any time you have multiple processes outputting to the same terminal (or file) in parallel, you run the risk of their output getting interspersed (unless you arrange to do some sort of locking or use low-level system calls like write to files opened in append-only mode). As a first step, you can minimize, but not tota...
Is the output mixed like this because of xargs and how can I fix it?
1,501,772,142,000
I want to implement something like this Q/A but for a sub-shell. Here is a minimal example of what I'm trying: (subshell=$BASHPID (kill $subshell & wait $subshell 2>/dev/null) & sleep 600) echo subshell done How can I make it so only subshell done returns instead of: ./test.sh: line 4: 5439 Terminated ...
Note: wait $subshell won't work as $subshell is not a child of the process you're running wait in. Anyway, you'd not waiting for the process doing the wait so it doesn't matter much. kill $subshell is going to kill the subshell but not sleep if the subshell had managed to start it by the time kill was run. You could ...
Silently kill subshell?
1,501,772,142,000
What stream does the perf command use!? I've been trying to capture it with (perf stat -x, -ecache-misses ./a.out>/dev/null) 2> results following https://stackoverflow.com/q/13232889/50305, but to no avail. Why can I not capture the input... it's like letting some fish get away!!
Older versions of perf ~2.6.x I'm using perf version: 2.6.35.14-106. Capture all the output I don't have the -x switch on my Fedora 14 system so I'm not sure if that's your actual problem or not. I'll investigate on a newer Ubuntu 12.10 system later on but this worked for me: $ (perf stat -ecache-misses ls ) > stat.lo...
What stream does perf use?
1,501,772,142,000
How would you change the output of the time command from: real 0m12.304s user 0m10.187s sys 0m1.699s To: 12.30s EDIT: Using bash (OSX)
Put this in .bashrc: export TIMEFORMAT=%Rs Then source ~/.bashrc. Run type time to find out that time is a shell keyword. Then, run man bash (as bash is your shell) and search for "time".
How to change output of time command?
1,501,772,142,000
FILE-A has 100,000 lines. FILE-B is 50 search terms. I'm looking to complete the search of FILE-A (CSV or TXT) with the various terms from FILE-B (CSV or TXT) AND -- here is the kicker -- save the results in individual TXT files based off the search terms from FILE-B. Example: FILE-A 123 45678 1239870 2349878 39742...
Grep + Xargs xargs -d '\n' sh -c ' for term; do grep "$term" fileA > "$term.txt"; done ' xargs-sh < fileB Improved by cas. Grep + Shell Generally using shell loops to read a file is bad practice, but here fileB is much smaller than fileA so it won't significantly hurt performance. while IFS= read -r term; do ...
Search File A with Terms from File B and save output to individual TXT files based off search term from File B
1,501,772,142,000
I'm quite new at bash and I am trying to learn it by creating some small scripts. I created a small script to look up the DNS entry for multiple domains at the same time. The domains are given as attributes. COUNTER=0 DOMAINS=() for domain in "$@" do WOUT_WWW=$(dig "$domain" +short) if (( $(grep -c . <<<"$WOU...
Using perl's Text::ASCIITable module (also supports multi-line cells): print_table() { perl -MText::ASCIITable -e ' $t = Text::ASCIITable->new({drawRowLine => 1}); while (defined($c = shift @ARGV) and $c ne "--") { push @header, $c; $cols++ } $t->setCols(@header); $rows = @ARGV / $col...
Bash output array in table
1,501,772,142,000
I haven't had much luck finding an answer to my problem, but maybe I'm not asking for it correctly. I have a process I startup like the following: nohup ping 127.0.0.1 > log.txt >2>&1 & Pretty simple command, send all the stdout to log.txt. Only problem is that the command I'm running sends data every nth second to l...
Here is a quick and dirty solution to only keep the last line of output in the log file: ping localhost | while IFS= read -r line; do printf '%s\n' "$line" > log.txt; done Beware that you now probably have all kinds of race conditions when trying to access the file for reading. "Locking" the file from mutu...
Limit stdout from a continuously running process
1,501,772,142,000
When I play music on vlc or cvlc in terminal or console there is always this (shown below) non-stopping output that prevents me from issuing commands by pressing ENTER key. I want to disable it, I tried to start vlc with vlc -q switch in quite mode but it only gets rid of [ ] bracket parts, the rest still remains and ...
You should be able to get rid of the output of the libraries by piping stderr away cvlc -q mymedia 2> /dev/null As for the commands, I'm not sure vlc accepts commands from plain stdin, but it sounds like the rc interface might be what you're looking for. cvlc -q -Irc mymedia 2> /dev/null
How to disable VLC output in command-line mode?
1,501,772,142,000
I want to get vsftpd version into shell variable. I can get it to console with ease: # vsftpd -version vsftpd: version 2.2.2 Also I can get a lot of other info into variable: # i=`bash --version 2>&1 | head -n1`; echo "=$i="; =GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)= (please note output is betwe...
Interestingly enough, my vsftpd writes the versino string to stdin. So you probably need to do a rather unusual redirection of stdin to stdout: i=`/usr/sbin/vsftpd -version 0>&1` How to find this out: run it in strace (you'll need to do it as root) and check for the string. In my case the log ends like this: $ strace...
How can I get vsftpd version into shell variable?
1,501,772,142,000
How to see from which file descriptor output is coming? $ echo hello hello $ echo hello 1>&2 hello all are going to /dev/pts/0 but there are 3 file descriptors 0,1,2
Ordinary output happens on file descriptor 1 (standard output). Diagnostic output, as well as user interaction (prompts etc.), happens on file descriptor 2 (standard error), and input comes into the program on file descriptor 0 (standard input). Example of output on standard output/error: echo 'This goes to stdout' e...
How to see from which file descriptor output is coming?
1,501,772,142,000
I would like to send to the stdout entire file + extra line. How to do this nicely? So far I did: for LINE in $(cat $INPUT_FILE) do echo $LINE done echo $EXTRA_LINE How to do this bash way (for real)?
How about cat -- "$INPUT_FILE" echo "$EXTRA_LINE"
How to concat file and a line on-fly?
1,501,772,142,000
In the past, I've used bash consistently, because it's everywhere. But recently I started to try zsh. I don't want to give up updating my .bashrc fil which is rsync'ed to all my servers . So, in my .zshrc, I sourced my old .bashrc using the command source ~/.bashrc. Everything goes well, except every time I open a new...
emulate -R ksh -c 'source ~/.bashrc' This tells zsh to emulate ksh while it's loading .bashrc, so it'll by and large apply ksh parsing rules. Zsh doesn't have a bash emulation mode, ksh is as close as it gets. Furthermore when a function defined in .bashrc is executed, ksh emulation mode will be enabled during the ev...
Source .bashrc in zsh without printing any output
1,501,772,142,000
Unlike the answer to this question (Can a bash script be hooked to a file?) I want to be able to see content of files that haven't been created yet as or after they are created. I don't know when they will be created or what they will be named. That solution is for a specific file and actually mentions in the quest...
If on Linux, something like this should do what you are looking for: inotifywait -m -e close_write --format %w%f -r /watch/dir | while IFS= read -r file do cat < "$file" done
Is there a way to cat files as they are created? [duplicate]
1,501,772,142,000
I saw this line while reading a blog on IFS that is : for i in $(<test.txt) And thought that $(<test.txt) prints the file contents to STDOUT. I maybe wrong in this, but out of curiosity I tried to do it on shell. So picked up a random file named array having random data and First did a cat array that gave me this : a...
The $(command) syntax executes command in a subshell environment and replaces itself with the standard output of command. And, as Bash Manual says, $(< file) is just a faster equivalent of $(cat file) (that's not a POSIX feature, though). So when you run $(<array), Bash performs that substitution, then it uses the fir...
Why is shell treating a part of the output of $(<file) as a command?
1,501,772,142,000
I'm using find -mtime -2 to find files modified in the past 24 hours or less. The output looks like this. /home/user/logs/file-2014-08-22.log /home/user/logs/file-2014-08-23.log I need to save the first line of the output to a variable and then save the second line to a separate variable. I can't just pipe it. I kno...
Assuming that there are no spaces or the like in any of your filenames, there are a couple of ways of doing this. One is just to use an array: files=( $(find -mtime -2) ) a=${files[1]} b=${files[2]} files will be an array of all the paths output by find in order, indexed from zero. You can get whichever lines you wan...
Saving individual output lines into variables
1,501,772,142,000
Scenario; I have SSH'ed to a machine, opened a new screen session, and fired off a script. Some days later I SSH back to that machine, re-attach the screen session and look at the output that has been generated, however; I can't scroll back through the output. From what I can see, screen stores one "screens worth" of...
Screen does keep a log of past output lines; it's called the “scrollback history buffer” in the Screen documentation. To navigate through the scrollback, press C-a ESC (copy). You can use the arrow and PgUp/PgDn keys to navigate, as well as other keys to search and copy text. Press ESC to exit scrollback/copy mode. By...
Leave remote command running storing output
1,501,772,142,000
I know that there is a possibility to use tee to copy the contents of output to a file and still output it to the console. However, I can't seem to find a way, to prepare shell scripts (like a fixed template) without using tee for either each command in the script or to execute the script using a pipe to tee. Thus, I ...
You could wrap the contents of your script in a function and pipe the functions output to tee: #!/bin/bash { echo "example script" } | tee -a /logfile.txt
Prepare shell script for output to file and console
1,501,772,142,000
It would appear that the output from hping is fully buffered when piped to perl for further line-by-line processing, so piping hping to perl doesn't work. hping --icmp-ts example.ca | perl -ne 'if (/Originate=(\d+) Receive=(\d+) Transmit=(\d+)/) { ($o, $r, $t) = ($1, $2, $3); } if (/tsrtt=(\d+)/) { print $r - $o, " "...
There are two common solutions, stdbuf and unbuffer. stdbuf is from GNU coreutils, it was added in version 7.5 in 2009 so it has made its way to all current non-embedded Linux systems apart from CentOS 5. It is also in FreeBSD since version 8.4. No other unix variant has adopted it yet that I know of, and in particula...
turn off buffering for `hping` in OpenBSD
1,501,772,142,000
I am modifying the text following tail -f. I have the following program that monitors a file: tail -vf -c5 /tmp/index \ | cat -n \ | sed s/^[^0-9]*\\\([0-9]\\\)/__\\\1__/g - \ ; The sed successfully changes tail's output. From another terminal i ...
I wrote a little script years ago that adds colors based on an input regular expression. I have posted it before here. If you paste that script into a file named color in a directory in your $PATH and make it executable, you can do: tail -vf -c5 /tmp/index | cat -n | color -l '^\s*\d+' Or, more manually: tail -...
Tail -f | sed. Modify text for color
1,501,772,142,000
I want to enter the current date (ideally in the form YYYY-MM-DD hh:mm) as an option in a bash script: I tried /usr/local/bin/growlnotify -t "PMK" -m date but then the variable -m inserts the string "date" in the output. How can I tell the script that it has to use the output value of the "date" command? (I'm using ...
writing date as an argument to another command will not get you the output of that command, just the string you typed. In bash you can insert the result from a command by including it in $( ). That leaves that you need to specify form (format) that you want to get from date, and that can be deduced from man date (FOR...
How to enter date as an option in a bash command? [duplicate]
1,648,150,879,000
So I have 2 different Linux installations. One of them is Ubuntu and the second one is Kali. When I run date command with no options/arguments on my Ubuntu install I get: michal@ubuntu:~$ date Thu 24 Mar 2022 07:56:23 PM CET When I run date command with no options/arguments on my Kali install I get: ┌──(michal㉿kali)-...
You can tell date how it should format its output: %% a literal % %a locale's abbreviated weekday name (e.g., Sun) %A locale's full weekday name (e.g., Sunday) %b locale's abbreviated month name (e.g., Jan) %B locale's full month name (e.g., January) %c locale's date and time (e.g., Thu Mar 3 23...
PERMANENTLY change the output format of the 'date' command in my Kali Linux
1,648,150,879,000
This: Save all the terminal output to a file Except after the fact. Meaning that instead of preparing to record or pipe all output to a file, I am dealing with output that has already taken place, and that I omitted to record to a file. Rather than to spend minutes scrolling up 7000 lines of output, copying and pastin...
With konsole, File->Save output as works as does CTRL-SHIFT-S, but you will only save what is in the buffer.
Save all terminal output to a file, after the fact
1,648,150,879,000
I have a command running for a long time, which I don't want to disturb. However, I would like to keep check on the process (most of the time remotely). I am constantly monitoring the process via commands like top, iotop, stat etc. The process is a terminal based process which wasn't started via screen or tmux or simi...
I would use strace for that: strace -qfp PID -e trace=write -e write=1,2 That will trace all write(2) system calls of PID and its child processes, and hexdump the data written to file descriptors 1 and 2. Of course, that won't let you see what the process has already written to the tty, but will start monitoring all ...
Get latest output of a running command
1,648,150,879,000
When my computer is slowing down, I usually run ps aux --sort -rss to find out which process consumes too much memory. There may be a lot of processes. How to see only a few ones?
You can tell ps to sort its output. But this seems to be a use case for top or htop. Press M to sort processes by memory and P to sort by CPU time.
How to decrease ps aux output to a few lines?
1,648,150,879,000
For an automated mailing and to notify user, respective members of a specific group, I am looking for commands or a single command line which provides a list of email addresses and which can be used further. Currently I am able to look up the directory in a way like: ldapsearch -h dc.example.com -p 389 -D "EXAMPLE\a...
After some research I've found the paste command. So adding | paste -sd ";" made it working in the way I was looking for. The final command line I'am using now is ldapsearch -h dc.example.com -p 389 -D "EXAMPLE\admin" -x -w "password" -b "DC=example,DC=com" -s sub "(&(objectCategory=person)(objectClass=user)(sAMAcc...
How to create a list of email addresses from ldapsearch result for further processing?
1,648,150,879,000
I have a process running on a Linux machine that I would like to access the output from. It's in it's own container that I'm using docker exec to su into. With ps I can see: UID PID PPID C STIME TTY TIME CMD root 1 0 0 18:45 ? 00:00:00 python ./manage.py runserver I thought I cou...
Use docker logs <yourcontainer> on the host to read its stdout. Add --follow to keep the output going.
Getting output from a running process
1,648,150,879,000
I have a command that outputs the following: READY Listening.... HELLO READY Listening.... TEST It is speech recognition from pocketsphinx_continuous. I need that output redirected to a file, and it does not seem to be comming from stdout or stderr because I have tried adding 1>log.txt and 2>log.txt and every time th...
The hideous command: script -q -f -c "pocketsphinx_continuous -samprate 48000 -nfft 2048 -hmm /usr/local/share/pocketsphinx/model/en-us/en-us -lm 9745.lm -dict 9745.dic -inmic yes -logfn /dev/null" words.txt & works for me, it logs: READY.... Listening... HELLO to the file, and it is easy to weed out the unwanted st...
Output is in console but not part of stdout or stderr
1,648,150,879,000
My Script is having 2 command-line arguments and then just couple of questions, after these questions the script will run for itself, I'm able to pass the command-line argument by just doing, -bash-3.2$ nohup ./Script.sh 21 7 nohup: appending output to `nohup.out' -bash-3.2$ Anyway to add the answers of these to-be-...
Instead of using nohup, you could have your script ask these questions interactively and then background and disown the remainder of whatever else it has to do. Example $ more a.bash #!/bin/bash read a echo "1st arg: $a" read b echo "2nd arg: $b" ( echo "I'm starting" sleep 10 echo "I'm done" ) & disown Sample ru...
How do I Nohup an interactive shell-script?
1,648,150,879,000
The program seems cool, but giving it a red color really makes it look like my computer is on fire. I think using grep or similar piping command can do the trick, but I see that it prints ASCII escape codes for colors and removes the special formatting of the output that makes it look like fire.
cacafire ASCII fire (aafire) was created with the now dead libaa. That may actually predate terminal color codes (I don't remember). However, the newer varient is the still maintained libcaca which provides cacafire.
Is it possible to color the output of `aafire`?
1,648,150,879,000
I’m fairly new to scripting and I have a high-level question of how to do something. I want to design a simple game similar to space invaders, with these two main features for now: Bullets drop down from the top of the screen every second. The user can move the home ship around at the bottom line of the screen and do...
I found a solution. Basically, you run the update loop in the background and have the main loop in the foreground. They can communicate with each other using trap/kill commands. I uploaded a .sh file to github to give a full example. Here's a modified outline of how it works though: Note: you have to use ctrl-c to esc...
Is there a way to execute commands while getting user input?
1,648,150,879,000
I am outputting results from an android shell command to a file, with MS-windows cmd via ADB.exe. It outputs the correct results, but I am getting an extra line between each result. It looks normal in interactive cmd (without extra lines), but when it is saved to a file the additional lines show up. I am using Note...
Try adb shell -T "ls -l" > test.log or, if it complains that error: device only supports allocating a pty: adb shell "ls -l >/data/local/tmp/list"; adb pull /data/local/tmp/list test.log Not all the devices support the ssh inspired -t and -T options, even if your adb client program does. This isn't Windows-specific:...
Remove extra blank lines from CMD adb shell, when redirected to file
1,648,150,879,000
I would like to save a Ruby program coloured terminal output into a png file, output doesn't fit into the screen height, so it is scrollable. Is it possible to save the whole or part of the scrollable terminal window area (not only the visible part of course, but scrolling a bit upwards) into a png file?
You don't have to use a real screen of limited size. Create a virtual screen of the size needed to show all your output at once, then dump that screen or terminal. For example: $ Xvfb :1 -screen 0 100x4000x24 -noreset & $ xterm -geometry 10x200 -display :1 -e \ sh -c 'echo $WINDOWID >/tmp/id;ls -l /etc;sleep 99' & ...
How can I save a scrollable terminal window (RoxTerm) into a png image?
1,648,150,879,000
I am on a Debian 8 System trying to determine the processes and their respective runtime of a certain user: $ ps -u <user> PID TTY TIME CMD 26038 ? 00:00:00 php5-fpm 26052 ? 00:00:00 php5-fpm 26950 ? 00:00:00 php5-fpm 27344 ? 00:00:00 php5-fpm 28292 ? 00:00:00 php5-fpm 286...
Despite the column name, the output you’re looking for is comm rather than cmd: ps -o comm= -o etime= -u <user> cmd is a non-standard alias for args and shows the command with all its arguments, including any modifications the process has made. comm is the process name which on Linux by default is the first 15 bytes ...
ps: get short command name and elapsed time
1,648,150,879,000
I have a bash script that reads filenames, takes a selection of data, build a table, and then adds the header. Unfortunately, at the point to add the header and give the output file, I have the following error message: ./big_table_rcp.sh: line 153: /tmp/out: Permission denied It is linked with the following line: | c...
You may be getting permission errors because you don't have permissions to access /tmp/out or the /tmp directory. Before the offending line, include somehting like ls -l /tmp | grep out to see what permissions the /tmp/out file has. In addition, instead of using /tmp/out, use mktemp. tmpfile=`mktemp` your code here | ...
Permission denied on file under /tmp
1,648,150,879,000
All I wanted is to grep for specific lines in an ongoing log and re-direct it to some file.. tailf log | grep "some words" Now, I want the above command output to get re-directed to some file in on-going basis.... I tried, tailf log | grep "some words" >> file But that doesn't seem to work. What am I missing?
The issue is buffering. Use the --line-buffered option to force grep to flush the buffer after every line: tailf log | grep --line-buffered "some words" >> file
how do i redirect output from tailf & grep to a file [duplicate]
1,648,150,879,000
I have the following in an expect script spawn cat version expect -re 5.*.* set VERSION $expect_out(0,string) spawn rpm --addsign dist/foo-$VERSION-1.i686.rpm The cat command is getting the version correctly however it appears to be adding a new line. Since I expect the output to be the following: dist/foo-5.x.x-1.i6...
TCL can read a file directly without the complication of spawn cat: #!/usr/bin/env expect # open a (read) filehandle to the "version" file... (will blow up if the file # is not found) set fh [open version] # and this call handily discards the newline for us, and since we only need # a single line, the first line, we'...
Cat in expect script adds new line to end of string
1,648,150,879,000
I often use thelast command to check my systems for unauthorized logins, this command: last -Fd gives me the logins where I have remote logins showing with ip. From man last: -F Print full login and logout times and dates. -d For non-local logins, Linux stores not only the host name of the remote host but its...
It is likely that logrotate has archived the log(s) of interest and opened a new one. If you have older wtmp files, specify one of those, as for example: last -f /var/log/wtmp-20141001
last command only shows few days worth of logins
1,648,150,879,000
I have the following simple script: echo "-------------------------- SOA --------------------------------" echo " " echo -n " ---------> "; dig soa "$1" +short | awk '{print $3}' The output is something like this: -------------------------- SOA -------------------------------- ---------> 2019072905 Now my question...
I would do the whole thing in printf instead: #!/bin/sh header='-------------------------- SOA --------------------------' headerLength=$(awk '{print length()}' <<<"$header") value=$(dig soa "$1" +short | awk '{print $3}') valueString="-----------> $value <-------------" valueLength=$(awk '{print length()}' <<<"$...
Next command output on the same line? Bash script
1,648,150,879,000
I would like to do something similar to the following: which someapplciation | cd outputfrompreviouscommand The command which provides a directory and I would like to be able to make that output my current working directory without using a programming language i.e. awk, bash, perl, etc. and to only use the pipe comm...
You can't use a pipe if the second command you are running doesn't read from its standard input. However, you can do something like cd $(which someapplication) or, since you need a directory name for cd and not an executable name: cd $(dirname $(which someapplication)) The $(...) shell operator executes the command ...
Pipe output from one command to another command's non standard input [duplicate]
1,648,150,879,000
In many cases after I find a file using the find command I then want to open the file or cat it or maybe print it. How can I operate on the result from find? For example, : find . -name "myfile.txt" ./docs/myfile.txt : find . -name "myfile.txt" | less does not work because it feeds the string "./docs/myfile.txt" to...
Similar to @coffeeMug, this is the more up-to-date way to doing this as it is apparently faster: find . -name "*.log" -exec ls -l '{}' + I'll also point you to CommandLineFu, which is always helpful with these things.
Access a file located with find
1,648,150,879,000
When I run a command like tail ~/SOMEFILE I get, for example: testenv@vps_1:~# tail ~/SOMEFILE This is the content of SOMEFILE. But what if I want to have a carriage return between: testenv@vps_1:~# and the output of: This is the content of SOMEFILE. So the final result would be like this: testenv@vps_1:~# tail ~...
The simplest option would be printing manually those extra newlines, something like: printf '\n\n\n'; tail ~/SOMEFILE But if you want to: Do this just for tail Not write extra commands with every tail invocation Have a simple yet full control over the quantity of newlines then I recommend you to add a function to y...
Display console output 1 or more lines below
1,648,150,879,000
I have a bash script that is rsyncing a large directory and the --progress function is great, but is it possible to show all this output on a single line? ie. as the files transfer, just spit it the --progress output onto the same line as the last, so that I can watch the progress without the screen scrolling?
Wrapper script Here is a draft of a wrapper script, written in Perl, that will emulate a PTY (so rsync should behave exactly as it would in a terminal), and parses the output so it can keep a running two-line display of the filename and transfer status. It looks like this: src/test.c 142 100% 0.19kB/s 0:0...
Is it possible to show rsync output on a single line?
1,648,150,879,000
I tried to put the output of my program into a text file. It appends the echo commands to the file properly, but the imagemagick "compare" command is not appended to the file. It just STOUD's the "PSNR value", which is returned by compare method into terminal. Is there a way to append this commands output to the textf...
Various imagemagick command output to STDERR instead of STDOUT. You can redirect STDERR to STDOUT to capture the output: compare -metric PSNR .... >> psnrdiff.txt 2>&1
Shell Script Output not written to file properly
1,648,150,879,000
How can I use the output of sed in another script? For example (this doesn't work): sed -n "$COUNTER",1p /domains.csv | wget or sed -n "$COUNTER",1p /domains.csv > /myScript.sh As far as I know > lets me take the output and put it in a file, I'm just unsure of how to use this output as an argument in another script...
The | takes output and redirects it into stdin. wget needs a command line argument, not stdin so you want to pipe to xargs which will build a command line from stdin. sed -n "$COUNTER",1p /domains.csv | xargs wget Alternatively you can tell wget to take input on stdin sed -n "$COUNTER",1p /domains.csv | wget -i -
Using sed output in another script or command
1,648,150,879,000
How can I terminate a process upon specific output from that process? For example, running a Java program with java -jar xyz.jar, I want to terminate the process once the line "Started server on port 8000" appears on stdout.
That can be accomplished with the following script considering that grep -m1 doesn't work for you: #!/bin/bash java -jar xyz.jar &> "/tmp/yourscriptlog.txt" & processnumber=$! tail -F "/tmp/yourscriptlog.txt" | awk '/Started server on port 8000/ { system("kill '$processnumber'") }' Basically, this script redirects ...
Terminate process upon specific output
1,648,150,879,000
I use the command varioutput=$(awk '{print $j}' OFS=, data/damper.test_temp1.csv) because I want to extract the j th value of a line of many values seperated by , . But when I want to use $varioutput it gives me always the whole line. What am I doing wrong? Actually I want to use for ((j=1; j<=20; j++)); do ...
You’re specifying the output field separator, not the input field separator; use this instead: varioutput=$(awk -F, '{print $j}' data/damper.test_temp1.csv) (or set FS instead of OFS). I’m also assuming that j is a placeholder above, and that you’re replacing it statically with the appropriate value (for example, pri...
awk save value as variable
1,648,150,879,000
I'm running a process and I'm counting the number of threads with ps huH p <PID_OF_U_PROCESS> | wc -l I can run this thread with watch like this; watch -n 1 ps huH p <PID_OF_U_PROCESS> | wc -l This will output the number of threads the process is running, but usually that number doesn't change. How can I only print th...
You could just pipe to uniq: while ps -o nlwp= -p "$pid"; do sleep 1; done | uniq
Watch: Only print to screen if output has changed since last output
1,648,150,879,000
I would like to echo a list all in one line, TAB separated (like ls does with files in one folder) for i in one two some_are_very_long_stuff b c; do echo $i; done will print one line per word: one two some_are_very_long_stuff b c instead I would like to break it, like ls without options does: mkdir /tmp/test cd /tm...
You could use the columns command from GNU autogen. $ seq 60 | columns 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 With zsh, you can use print -C: $ print -C4 {1..20} 1 6 11 16 ...
How do I echo a line with linebreak at the end at window border? [duplicate]
1,648,150,879,000
I currently have 2 bash command line strings I use to gather data needed for a certain task. I was trying to simplify and have only one command used to gather the data without using a script. First I cat a file and pipe into a grep command and only display the integer value. I then copy and paste that value into an eq...
Here it is as one command: echo $(( (2147483633 - $(grep -i isrs /proc/zem0 | grep -Eo '[0-9]+$') )/5184000 )) How the simplification was done First consider this pipeline: cat /proc/zem0 |grep -i isrs` This can be simplified to: grep -i isrs /proc/zem0 Thus, the whole of the first command becomes: grep -i isrs /pr...
Using the output of `grep` as variable in second command
1,389,251,246,000
I want to run a command (rsync -av) and only display 10 lines of output at any time. I have found a similar post, but I don't want to redirect it to a file. I want the output to be displayed simultaneously, but only 10 lines at most should be visible. For example: The output has 100 lines, when its finished. At the be...
I've done such tricks in the build system of an embedded Linux distro. In my case, it was a little different. The build script restricted the scrolling region (via VT100 escape sequences) so that the log was shown in the top N-4 lines of the terminal. The bottom four lines were turned into a static area that was updat...
Show a sliding window of output from a program
1,389,251,246,000
Scenario: $ cat libs.txt lib.a lib1.a $ cat t1a.sh f1() { local lib=$1 stdbuf -o0 printf "job for $lib started\n" sleep 2 stdbuf -o0 printf "job for $lib done\n" } export -f f1 cat libs.txt | SHELL=$(type -p bash) parallel --jobs 2 f1 Invocation and output: $ time bash t1a.sh job for ...
From the man pages of GNU parallel: --group Group output. Output from each job is grouped together and is only printed when the command is finished. Stdout (standard output) first followed by stderr (standard error). This takes in the order of 0.5ms CPU time per job and depends on the speed of your disk for larger ou...
GNU parallel: why does diagnostic output look like sequential execution rather than parallel execution?
1,389,251,246,000
I'm using gfind running on MacOS, to find text files. I am trying to see the filenames only and the birthdate of my gfind results, and then sorting them by date, and paging them. Is this achievable? For the moment I am trying gfind . -name "*.txt" -printf "%f \t\t %Bc\n" But the results are the following: todo.txt ...
Here, you can use: gfind . -name '*.txt' -printf '%-40f %Bc\n' or gfind . -name '*.txt' -printf '%40f %Bc\n' To print the file name left-aligned or right-aligned padded with spaces to a length of 40 bytes (not characters, nor columns unfortunately). That would align them as long as file names don't contain control, ...
Properly tabulating 'find's output with printf and sorting them by date
1,389,251,246,000
I am running a MySQL script file from a shell script in Linux (CentOS 7). While I can capture the result in a file, I am not able to capture result metadata. Example: My test.sql file looks like this: USE dbname; SELECT * FROM `test`; INSERT INTO test values (3,'Test'); My test.sh script looks like this: #!/bin/bash ...
You can increase verbosity. This should be enough: -vv Reason: It check for isatty and if it find it is not printing to a terminal enters batch mode. The verbosity from man and --help: --verbose -v Verbose mode. Produce more output about what the program does. This option can be given multiple times...
How capture MySQL result metadata in a file when run from shell script
1,389,251,246,000
When I run ras-mc-ctl --summary I get the following output: No Memory errors. No PCIe AER errors. No Extlog errors. No devlink errors. Disk errors summary: 0:0 has 15356 errors 0:2064 has 4669 errors 0:2816 has 594 errors No MCE errors. Now, I'm not particularly concerned about there errors given that ...
lsblk will give you MAJ:MIN numbers To calculate the equivalent for ras-mc-ctl, do: d = (MAJ * 256) + MIN To go from ras-mc-ctl to lsblk, do: MAJ=int(d/256) MIN=d % 256 For your case: MAJ=(2064/256)=8 MIN=(2064%256)=16
Interpret disk errors output from ras-mc-ctl --summary
1,389,251,246,000
I'm extracting daily backup archives. I want to see only the new files since the last day. The archives contain lot of already existing files, which I don't want to overwrite, so I use the --skip-old-files option, which is fine. But I'd like to list only those files that were actually extracted and omit those that we...
If this is the only process writing to the directory then you could create a temporary file, extract the files not in verbose mode, then look at those with a change time newer than the temp file e.g. MYTMP=$(mktemp) tar --skip-old-files --extract --file=2019-02-10.tar.gz find . -cnewer $MYTMP rm $MYTMP
Show only the really extracted (non-skipped) files using tar
1,389,251,246,000
I'm using a piped command to migrate a big production DB from one host to another using this command: mysqldump <someparams> | pv | mysql <someparams> And I need to extract the line 23 (or let's say the first X lines) (saved as file or simply in bash output) from the SQL passing from one server to another. What I've t...
With zsh mysqldump <someparams> | pv > >(sed '22,24!d' > saved-lines-22-to-24.txt) | mysql <someparams> With bash (or zsh): mysqldump <someparams> | pv | tee >(sed '22,24!d' > saved-lines-22-to-24.txt) | mysql <someparams> (though beware that as bash doesn't wait for that sed process, it's not guaranteed t...
Get first N lines of output from a pipe operation
1,389,251,246,000
I have a Debian on beaglebone without an X server and I need to get rid of any console output to the framebuffer device. I was trying few things I found, like console=null or kernel argument vga=0, but without luck. Any advice?
You do not have a vga in your BeagleBone. In my Lamobo R1 (ARM like the BB) I am passing to the kernel the parameters sunxi_ve_mem_reserve=0 sunxi_g2d_mem_reserve=0 sunxi_fb_mem_reserve=0 console=ttyS1,115200n8 and took out the ones: console=tty1 disp.screen0_output_mode=1920x1080p60 Why this parameters: sunxi_ve_m...
Turning off console output?
1,389,251,246,000
I want to get the result of time command into a text file but it's not working it only put blank space in the text file. I already tried this commands, A- $ x=`time` $ echo $x > log.txt $ cat log.txt $ B- $ time > log.txt real 0m0.000s user 0m0.000s sys 0m0.000s $ cat log.txt $ C- $ time > log.txt 2>&...
Use the external time command instead of the builtin: /usr/bin/time -po log.txt true \time -po log.txt true # simpler way For example: $ \time -po log.txt true $ cat log.txt real 0.00 user 0.00 sys 0.00
Sending `time` command into text file [duplicate]
1,389,251,246,000
I would like to be able to write the output of Portage commands, along with other commands, that I perform in tty (that is, the screen-wide terminals started with Ctrl+Alt+Fn where n represents an integer between 1 and 6. These terminals are started using the getty command, to my knowledge) where there is no clipboard...
You're on the right track. In Unix/Linux there's also an error stream. Every command gets standard input, standard output, and standard error. You've been working with standard output. To also capture the standard error stream from the command use 2>. For example: emerge dev-qt/qtwayland > emerge.out 2> emerge.err...
How do I write the output of Portage to a txt file?
1,389,251,246,000
how do I set it so clear command clears the output that was stored in ram from my understanding, konsole keeps screen output in ram. I want to clear that when I clear the visible part of the screen with the clear command.
Clearing the ram used by whatever running process is a facility rarely offered to the user. More over, unless you precisely know the code the process is running, it is just impossible to know what is being stored where. The visible part of the screen as well as some variable amount of lines that were previously displ...
have clear screen clear konsole ram
1,389,251,246,000
I have a daemon that prints some information on to the terminal. I can see these informations by typing: systemctl status bot.service, this is working well, but this command doesn't listen to the new output, so if I want to see the new output, generated, then I need to retype the command. Is there a way to always lis...
There are two ways. You need elevated powers for both (eg. use sudo, or be a member of the systemd-journal group). Use journalctl: journalctl -fu bot Find the log the output goes to and tail -f it. Very likely it's /var/log/syslog. Then do: tail -f /var/log/syslog There will be other entries intermixed though.
How to listen to a daemon output?
1,389,251,246,000
I'm writing a script that shuts down the Apache service, performs a function, and turns it back on. I'd like to get some type of interactive confirmation for each process. I'm not familiar with printf, but I believe it would be required for what I want to do. Here's a portion of the script below. As I turn off the ser...
In bash, you can use the -n option of echo not to print the end of line. echo -n Shutting down Apache service: or, use printf printf '%s' 'Shutting down Apache service' To include the newline in printf, put \n into the template printf '%s\n' 'NOT OK!'
Interactive bash script
1,389,251,246,000
I have a professor who stores homework assignments in many files spread across different sub-directories in a lecture folder with the header "TODO:" I'd like to output all these todo's to a single text file in nano instead of navigating from one assignment file to another. I tried to make an alias for this command, s...
I figured it out, thanks for the pointers guys. The problem here was that grep was recursively searching for "TODO:" in the todo.txt file and then writing those results back to the todo.txt file. When I opened todo.txt it was filled with the same text looped over and over again. Evidently, I should have used the --exc...
Grep alias piped to nano. Nothing happens when command is issued
1,389,251,246,000
This is a follow up to Replace one entire column in one file with a single value from another file combined with R Pass Variable from R to Unix I am running several scripts (Perl, python and R) in one Unix script and need to pass outputs of these scripts to Unix and combine information from different files these scrip...
You're trying to pass $counter into the awk script, so you need to use double-quotes rather than single-quotes. Single-quotes are for literal strings, double-quotes are for strings with variables in them. Because you're using double-quotes here, that means you have to escape $2 as \$2 in the awk script so that the sh...
combining output from different scripts into different files in a loop
1,389,251,246,000
I calling an url using wget. This url gives me a response, its a Message id. I want to write the logs to a log file, with the message id as well. Also the log should be appended each time. I trying to do it in my shell script. Is it possible to do this? If so how can i do it.
wget -O - $url --append-output=logfile >> logfile Specifying - as filename for -O writes the output to stdout. My shell does not hate using logfile for both append operations. It might work for you as well.
wget, logging the output and the response
1,389,251,246,000
I found these ways, for example, to output colored text in a simple way to the screen: RED="\033[0;31m" # Red color (via ANSI escape code); NC='\033[0m' # No color (via ANSI escape code); echo -e "${RED}This text is red. ${NC}" # -e flag allows backslash escapes; or: printf '\e[1;34m%-6s\e[m' "This is blue text" I a...
Codes (ANSI colour codes) The codes are not distro dependent. They are terminal dependent. Some terminals will not support them. However they are probably supported by most. Names Use variables to give names e.g. red="$(tput setaf 1)" echo "${red}hello" note: don't use capitals for shell variables, capitals should be...
Output colored text in all major distros without using non-word color codes (like \033[0;31m)
1,389,251,246,000
grep include /etc/nginx/nginx.conf output: include /etc/nginx/modules-enabled/*.conf; include mime.types; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; desired output: include /etc/nginx/modules-enabled/*.conf; include mime.types; include /etc/nginx/conf.d/*.co...
awk '/include/ {$1 = $1; print}' < your-file Would do that. By assigning something to $1, that forces awk to rebuild the record by joining the fields (which by default are separated by whitespace (at least space and tab, possibly others depending on locale and awk implementation)) with OFS (space by default). A sed e...
How to remove multiple white spaces between words?
1,389,251,246,000
I'm doing some hands on pen testing and following some guides to get an understanding of the tools of the trade. I'm following along with the guide here and I understand everything except for the last page. I need assistance understanding sudo -l below. I know that it details what the current user can do. However, wha...
For your first question, the indicated lines of output are telling you that you are permitted to run /bin/tar and /usr/bin/zip via sudo as the root user without even needing to provide zico's password. For your second question, we get the answer from zip's manual page: --unzip-command cmd Use command cmd ...
Understanding sudo and possible exploit
1,389,251,246,000
I'd like to make fixed height output from any command using piping: some_command | magic_command -40 If, for example, some_command prints 3 lines, magic_command should add 37 newlines, or if some_command prints 50 lines, magic_command should cut extra lines (like head -40)
POSIXly: { command; while :; do echo; done; } | head -n 40 On GNU system: { command; yes ""; } | head -n 40
Padding output with newlines
1,389,251,246,000
i'd like to display the output of lsb_release -ds in my Conky display. ftr, in my current installation that would output Linux Mint 18.3 Sylvia. i had thought of assigning the output of that command to a local variable but it seems Conky doesn't do local vars. maybe assigning the output of that command to a global (sy...
You should prefer the execi version of exec, with an interval, where you can give the number of seconds before repeating: ${execi 999999 lsb_release -ds}
how to display lsb_release info in Conky?
1,389,251,246,000
I work in Maxima a lot (start it on the terminal with "rlwrap .../maxima" and sometimes I want to save a few (several) screens worth (scrolling) of calculations. I realize I can use xmaxima, a variant that can then save it to a text file - that works. But I also sometimes use scipy/python in the terminal, or even oth...
This is what the script tool is for. It will save an entire terminal session - inputs and outputs: $ script sessionlog.txt [ do stuff ] $ exit $ ls sessionlog.txt
save several bash screens of program input/output
1,389,251,246,000
I just ran fsck on my newly bought SD card for my Raspberry Pi and it shows the following output: fsck from util-linux 2.25.2 fsck.fat 3.0.27 (2014-11-12) /dev/mmcblk0p1: 75 files, 2539/7673 clusters It doesn't say clean anywhere and exists with error code 1333 (if I do echo $! after running fsck). Is this bad or not...
The return status is in $?. $! holds the PID of the last background process.
Don't know if fsck failed or not
1,389,251,246,000
I searched a lot and finally came here to ask my question. Recently my screen got damaged and now has some rows of dead pixels. They are located at the very top of the screen and making it very difficult to read for example the url of a website. So I wondered if it would be possible to set the output from 1680x1050 to...
No, you cannot just select the pixels that are undamaged, stem reworks don't work like that, unfortunately. If you change the resolution it will reduce the quality of the entire screen's display itself. But the screen can be replaced if it is a flat monitor or a laptop.
Trim monitor output (because of dead pixels)
1,389,251,246,000
I have fired an ls -1 command that runs and displays a long list of values. When the command ends I can not see the output which is outside the screen vertical length. How can I see those previous entries ? Is there a way to see the output progressively like : Display first 15 rows User hits a keystroke. Then displa...
You can pipe the output of ls to pipe as follows $ ls | less Then you are able to use less to browse the output, for example with Page Up and Page Down. You can exit less by pressing q. Type man less to find out more ways to scroll the output.
How can I see output from a command progressively?
1,389,251,246,000
completely new to bash so any assistance is much appreciated. I'm looking for a script to do the following, its a pretty simple script but I cant seem to get it: I want to run a command, this command will return either successful or some other string in the output. if the output does not contain the word successful I...
You could do something like: #!/bin/bash output= count=0 until [[ $output =~ successful ]]; do output=$(somecommand 2>&1) ((count++)) sleep 300 done printf '\n%s\n' "Command completed successfully after $count attempts." This will check if output contains successful, if you want to check that the outpu...
poll for the right output of a command
1,389,251,246,000
In a case where I write a query for dpkg-query to list me some package, I would like it to return me the package name if it finds something. If it doesn't find anything, I don't want it to output: no package found matching {package-name} I would like it to output nothing at all. The reason for this is because my query...
You can redirect dpkg-query's stderr to /dev/null to silence the error message, as in dpkg-query --list <package> 2>/dev/null.
How to ignore warnings from dpkg-query when it doesn't find anything?
1,389,251,246,000
I'd like to be able to export the output (and error messages) of my cygwin terminal in a file, especially since I have to click a lot of buttons in order to "mark" the stuff in the cygwin terminal (and it's desirable to minimize the amount of clicking I do).
The stderr output of an executable can be redirected to a file with the following syntax: mycommand 2> error.txt If you want to redirect stdout (i.e. the regular program output) to the file, the command should be: mycommand > output.txt To redirect both the stderr and stdout output to the same file (similar to as se...
For cygwin, how do I export the output in a terminal into a file?
1,389,251,246,000
I want to save the output from a script so I can view it later. However, when I save the output to a file (script > some/file) and view it later, there's no color, even though script originally outputs in several colors to make the output easier to read. It makes sense that the color isn't saved since the resulting fi...
Some programs (including whatever you put in your script) detect whether the output is a terminal or a file, and turn off colors for that case. If you run your script using the program script, that avoids this problem, by capturing all of the characters into a file named typescript, e.g., script -c script (where the ...
Maintain color from script output for later viewing
1,389,251,246,000
Let's say I am calling ls -la, which produces a very long output. Is there any key/command which lets my console scroll up to the first line of the output?
If the output is very long you could use the less command like below: your_command_here | less And then scroll all the way down by pressing keys like Enter, Space etc. For more see the less manpage. You could even use more you_command_here | more more works like less but uses different key combinations to page throu...
Go to first line of console output of a command
1,380,717,179,000
I am running a java program from a OS X 10.8 bash terminal, and are trying to rederect the output it is producing. However, when either running this throug a pipe, or rederecting it to a file, the output is blank, however I see the output in the terminal. To illustrate this: > java program.java 13/10/02 14:18:30 WARN ...
There are three standard files open for each program, stdin (standard input), stdout(standard output), and stderr (standard error). Writes to both stdout and stderr is output in the terminal by default. It is a common convention to write errors and log messages to stderr instead of stdout in order to not mix log or er...
Pipe not picking up stdout
1,380,717,179,000
Environment: aptitude called in a script. I'm having problems with this command: aptitude search '?virtual' |grep ^v |grep -v i386|sort|uniq In particular if I do: aptitude search '?virtual' |grep ^v |grep -v i386|sort|uniq|grep adblock I get (as one of the results): v adblock-plus-element-hiding-hel - inst...
You need to tell aptitude not do do any special column formatting. --disable-columns This option causes aptitude search and aptitude versions to output their results without any special formatting. In particular: normally aptitude will add whitespace or truncate search results in an attempt to fit its results i...
Have aptitude search print full package name
1,380,717,179,000
I know that you can connect to various background processes to watch their console output, but is there a way to view the output of all processes at once? Likely it would scroll quickly and be hard to read, but is it possible?
Well, you can spawn several processes in your shell in the background and then (if they all use their stdout or stderr) you can get lots of information intermingled in the console - and by intermingled I mean it can possibly even mix data from several processes in the middle of a line. What you are probably looking fo...
How to view output for ALL processes simultaneously?
1,380,717,179,000
I am working on vxlan tunneling between Linux - commercial routers. I need to debug some interface settings. The command sudo ip -d link show DEV gives me a great output but the output format is like a long single line as below. katabey@leaf-1:mgmt:~$ sudo ip -d link show vxlan_10 11: vxlan_10: <BROADCAST,MULTICAST,UP...
try: your-command |grep -Eo '(vxlan id|srcport|dstport) [0-9]+|local [0-9.]+'
Formatting command output that is a long single line
1,380,717,179,000
Below command outputs a table of space delimited text, is there a tool to remove the unnecessary spacing here while still keeping the columns aligned? $ sudo ss -ltpn State Recv-Q Send-Q Local Address:Port ...
Turns out that ss can do this for you if you just pipe the output or redirect it to a file. For example, on my system, without piping, I get this: $ sudo ss -ltpn State Recv-Q Send-Q Local Address:Port Peer Address:Port Proces...
How to remove unneccessary spaces from table output in shell while still keeping columns aligned?
1,380,717,179,000
Task: I'm using grep to search some text files, piping the results from one grep (excluding some lines) to another (matching some lines) + displaying some context using the -C parameter as shown below: grep -v "Chapter" *.txt | grep -nE -C1 " leaves? " Problem: This works very well when printing the results, but pr...
Try changing the directory where you're writing out.txt. For example change this command to this: $ grep -v "Chapter" *.txt | grep -nE -C1 " leaves? " > /tmp/out.txt Example Here you can see what's happening when you enable verbose output in your Bash shell. $ set -x $ grep -v "Chapter" *.txt | grep -nE -C1 " leave...
Outputting context (-C) for grep produces massive files
1,380,717,179,000
Say I've got a text file file.txt and program program.rb. program.rb writes stuff to file.txt as program.rb finds it. How can I view the population of the text file from the terminal?
This is commonly done with tail -f: $ tail -f file.txt The tail utility outputs the tail of a file or stream, i.e. the last part of it (the 10 last lines by default). With the -f flag, it will not exit once it has arrived at the end, but continue polling the file or stream for new data and output it whenever it arri...
How can I view the file output of a program in a text file as it's being populated?
1,380,717,179,000
I'm using Amazon Linux and writing a script in bash. I want to output both stderr / stdout (preferably in the order that they occur) to a file as well as the console. However, this command isn't working ... node test.js 2>&1 >> /tmp/output | tee --append /tmp/output The output gets sent to the file, but it is not g...
The >> /tmp/output already sends all output to the file, leaving nothing to be sent to tee. So the command should read node test.js 2>&1 | tee --append /tmp/output.
How do I output stderr/stdout of my script to both a file and the console?
1,380,717,179,000
I wanted to capture to a file the errors being returned on the command line from grep. For example, grep foo.lookup No such file in directory I want to output that to a log file. This is my shell script: lookUpVal=1 var1=$(grep $lookUpVal foo.lookup) >>lookup.log 2>$1 It creates the file lookup.log but doesn't write...
If I understand it correct, you want to capture the output of grep into a variable and append any error to the logfile. You could say: var1=$(grep $lookUpVal foo.lookup 2>>lookup.log) The $(...) syntax denotes command substitution, i.e. outputs the result of the command into a variable. By default it would capture t...
Redirect grep error output to file
1,380,717,179,000
I have a very simple ksh script and at certain points I want to write to a log file. I use the following commands in two places... print "Directory listing 1:\n" > ${LogFile} ll >> ${LogFile} (Note: The second time this command is used print Directory listing 2) My problem is, when I view the log file afterwards, onl...
Whenever you do a redirection with > (your first line), the ${LogFile} is truncated to 0 and then written. If I understand right, you do the above twice, the first stuff is overwritten by the second. What you have to do is along the lines: > ${LogFile} # This just truncates if there was anything there, writes nothi...
Unsure about the behaviour of my script when writing to log file
1,380,717,179,000
Say, for example that after running a number of commands: $ cd /opt/something $ find . -name *aa | grep 11 $ clear $ <more commands go here> there was a part of the output that was needed but not saved; the command which produced it as well as the arguments might not be recalled entirely. Is there a way to search ...
stdout is transient, or ephemeral. Unless you take some action to save it, it's gone and inaccessible as soon as it's output. If you want to re-use the output of a command multiple times, then you need to save it somewhere - a scalar variable (e.g. with command substitution), an array variable (e.g. with readarray/ma...
How to search for strings in the output of previously run commands