New answers tagged

1

Using node.js you can start a single thread that executes the bash script every 200 milliseconds no matter how long the response takes to come back because the response comes throug a callback function. var util = require('util') exec = require('child_process').exec setInterval(function(){ child = exec('fullpath to bash script', ...


2

Simplistically, if your command lasts less than 1 second you can just start 5 commands each second. Obviously, this is very bursty. while sleep 1 do for i in {1..5} do mycmd & done done If your command might take more than 1 second and you want to spread out the commands you can try while : do for i in {0..4} do sleep ...


1

With a C program, You can for example use a thread which sleeps for 0.2 seconds into a while #include<stdio.h> #include<string.h> #include<pthread.h> #include<stdlib.h> #include<unistd.h> pthread_t tid; void* doSomeThing() { While(1){ //execute my command sleep(0.2) } } int main(void) { int ...


8

On a GNU system and if you have pv, you could do: cmd=' that command | to execute && as shell code' yes | pv -qL10 | xargs -n1 -P20 sh -c "$cmd" sh The -P20 is to execute at most 20 $cmd at the same time. -L10 limits the rate to 10 bytes per second, so 5 lines per second. Example: $ cmd='date +%T.%N; exec sleep 2' $ yes | pv -qL10 | ...


0

Below stuff may help : var=$(pgrep process_name_here); top -b -p "$var" | awk -v var=$var '$1~var{print $10}' You might even think of writing a script and passing the process name as argument Note: This solution will not work if you change the default layout for the top command. In that case you need to replace $10 with appropriate field number


2

I was able to solve this problem by following commands : mv /var/lib/dpkg/info/coturn.* /tmp/ dpkg --remove --force-remove-reinstreq coturn This worked. And I installed coturn again, then it worked.


2

It looks as though some of your commands have been modified/removed outside of yum. You need to reinstall the missing commands like so: yum reinstall which You can give multiple packages as you identify them: yum reinstall which clear If you find that lots of commands have been removed, it may be easier to reinstall your whole system.


0

I would try to search for the missing command by its name. find / -name which Assuming 'which' is the missing command, then you can add it to you PATH.


1

The two main reasons to run a program directly without calling the shell are: Performance: Most programs that you would call from your C program are likely much smaller than the shell, which makes them start much more quickly. Environment control: Dealing with an additional layer of environment variables to deal with can be more complex to configure and ...


0

I just tested this in a docker container with an image of debian stretch. https://packages.debian.org/source/stretch/clamav The current stable version of Clamav for Linux is 0.99.1. Source: https://www.clamav.net/ clamscan does not have such an option, I checked the manpage. It seems that this option exists in the Windows version only.


2

Another common remedy for this problem is to type Ctrl-VCtrl-O at the shell prompt. The first puts the shell into "literal" mode so that it won't modify the following character, which is the terminal reset command understood by almost all common terminal types. You might need to echo this instead, on some terminals.


3

That happened because the output you produced included codes that your terminal interface interpreted as control codes. This is normally resolved with either reset or stty sane.


2

You can use the commande file e,g: file images.jpg the output is something like : images.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 342x147, frames 3 OR rdjpgcom -verbose images.jpg sample output JPEG image is 342w * 147h, 3 color components, 8 bits per sample JPEG process: ...


1

With recent[1] versions of GNU findutils and coreutils: find /home/jeremy/source -print0 | tail -z -n 1000 | xargs -0 -r mv -t /home/jeremy/dest/ The -print0, -z, and -0 options tell all three tools to use a NUL character as the filename/record separator. This makes it safe to use this pipeline with filenames containing ANY character. If your ...


1

If your command would work if the commandline would not become too long then you can use (the tricky) xargs this way: ls /home/jeremy/source | tail -1000 | xargs mv -t /home/jeremy/dest This assumes there are no newlines and other special characters in the filenames (or the path) otherwise tail will not work properly and xargs will get split filenames ...


4

I can only address the first part of your question: You can view the dimensions of an image on the command line by the using the identify tool, part of the the imagemagick package. (To install imagemagick on a Debian box, provided you have sudo privileges, you can run sudo apt-get install imagemagick ). For example, in a directory with image file rose.jpg, ...


2

There are number of tools that will do this: identify from ImageMagick jhead jpeginfo some versions of the file command If these programs are not installed, note that both jhead and jpeginfo are quite simple and presuming a compiler is available will be easy to build in your own user account.


1

It's what it says on the tin: “Maximum length of command we could actually use” is the maximum possible command line length, given the limit on the platform where xargs is running and the space taken up by the environment. This value only depends on the platform configuration and the environment. “Size of command buffer we are actually using” is the size ...


0

The shell running in the terminal receives the script that you're pasting on its standard input, and your script itself reads from standard input. There's a conflict here: your script will end up reading a bit of itself. If you don't get a sudo prompt, then what happens is: The shell reads whole lines until it has a complete command. The first line starts ...


1

You can use find to find all of the files in a directory structure that you want to run through your dos2unix command find /path/to/the/files -type f -exec dos2unix {} \; Take a look at the man pages for find, there are a lot of options that you can use to specify what gets evaluated


2

find /path -type f -print0 | xargs -0 dos2unix --


0

Use a wildcard. Like this: (If you're in the folder) dos2unix * or if you're outside of the folder do: dos2unix /path/to/folder/*


0

If your ping does not support a useful SIGQUIT (AIX, Solaris), here's one workaround -- an infinite ping loop where each ping only fires off (e.g.) 10 pings, so that you can see intermediate results. while :; do ping -c 10 $HOST; done To stop it, Control-C may only kill the ping command; you may need to suspend and then kill the job (Control-z; kill %). ...


30

There is a way better way of achieving this: less +F <file> It'll show you the whole file, has the full power of less and will wait for new input. If you want to stop waiting for input, and read a specific part, you can stop it with ^C and resume with F. The F command is always available in less, if you decide to watch for changes while having a ...


3

In addition to /u/Anthon's answer, you can do something like: { cat filename; tail -0f filename; } That -0 option to tail is equivalent to -n 0, meaning: dispaly 0 lines. But the -f will display new lines. You don't need the braces { }. I used them because sometimes you want to redirect the filedescriptors in some way. For instance: { cat ; tail -0f -; ...


1

watch command should do that for you. You can also try less +FG You will have more options with less command to scroll through your file as you say it's a large file.


29

tail lets you add -n to specify the number of lines to display from the end, which can be used in conjunction with -f. If the argument for -n starts with + that is the count of lines from the beginning (0 and 1 displaying the whole file, 2 indicating skip the first line, as indicated by @Ben). So just do: tail -f -n +0 filename If your log files get ...


0

Also, if you just want to exclude some lines ahead of a given marker, you could use: awk -v nlines=2 '/Exception/ {for (i=0; i<nlines; i++) {getline}; next} 1' (glenn jackman at http://stackoverflow.com/a/1492538 ) By piping some commands you can get the before/after behaivour: awk -v nlines_after=5 '/EXCEPTION/ {for (i=0; i<nlines_after; i++) ...


1

You can reach a good-enough result by using temporary files: my_file=file.txt #or =$1 if in a script #create a file with all the lines to discard, numbered grep -n -B1 -A5 TBD "$my_file" |cut -d\ -f1|tr -d ':-'|sort > /tmp/___"$my_file"_unpair #number all the lines nl -nln "$my_file"|cut -d\ -f1|tr -d ':-'|sort > /tmp/___"$my_file"_all #join the ...


0

lets give stat a try: stat -c "%F %n" /etc/P* | grep "regular file" | cut -d' ' -f 3-


2

If you want to find all regular files beginning with P, you can use: find /etc -type f -name 'P*' If you want to no recurse into subdirectories: find /etc -maxdepth 1 -type f -name 'P*'


0

I’m using zsh and this function works well for me: function grep1() { tee > >(head -n 1) > >(tail -n +2 | grep $*) } The main advantage of this approach is that you have full control over the grep command, so you can pass the usual flags like -i, -E, etc. Usage example: $ ps -rcA | grep1 databases PID TTY TIME CMD $ ps -rcA ...


1

You can fix the file using awk like this: awk '/^>/{if(x)t=$0;else print"\n"$0} !/^>/{printf"%s",$0;if(t)print"\n"t} /^>COSN229024/{x=1}' < wrong.fasta > good.fasta After this you will probably also need to fix the beginning and the end of the file manually.


0

Did you mean to do something like this? It's the only way i can think of to make sense of your script. awk -v OFS=$'\t' ' FNR == 1 { $5 = "sdev" ; print } FNR > 1 { a = $4 # field 4 is 'avg' n = NF-1 # exclude the 'avg' field from the ss calculations. for (i=1; i <= n; i++) { ss += ($i - a)^2 } $5 = ...


0

You can check with: ls -l | grep -v ^l | wc -l


2

Where is "n"? You write: sd = sqrt(ss/n) but where in your code did you assign the variable "n"? The way awk sees it, "n" is zero. Also, where is column 5 in a=$5 (and, third issue, why is this assignment in the END section)? Your example contains only 4 columns.


0

Here is a solution with Awk and FFmpeg: #!/bin/sh if [ "$#" != 1 ] then echo 'ff-split.sh [cue file]' exit fi awk ' $1 == "FILE" { split($0, i, /"/) file = i[2] } $1 == "TRACK" { tracks[++j] = $2 } $1 == "TITLE" && j { split($0, i, /"/) titles[j] = i[2] } $1 == "INDEX" && $2 { split($3, i, ":") indexes[j] = ...


0

You can list other networks in cli using nmcli. nmcli con show or nmcli d Then you need to copy your UUID for further connect to the ones-needed interface. nmcli c up uuid <paste uuid here> or nmcli -p con up "my-eth1" ifname eth1 About resources: you can get acquainted at first with this: nmcli, than you can go further and use this ...


0

What about using the Automatic RPi Image Downsizer? You can as well take a look at the code to see what is going on. if [[ ! $(whoami) =~ "root" ]]; then echo "" echo "**********************************" echo "*** This should be run as root ***" echo "**********************************" echo "" exit fi if [[ -z $1 ]]; then echo "Usage: ./autosizer.sh " ...


4

Your GUI explorer is using information from the avahi daemon which is listening for services on the local network. You can do the same from the cli with avahi-browse -rat


1

I can confirm you are in the right track shrinking that filesystem; fdisk/parted is next. The tricky part is getting it right next to the size of the new filesystem,do your math or leak a hundred KB more just to be safe. You can adjust it later on the new card if need be. The order is normally: umount, resize, fdisk/parted, partprobe, fsck, and mount to ...


1

Once the output of ls is on the terminal, it stays colored. But if you run ls again, whether the output is colored depends on the options you pass to ls this time. The ls command doesn't remember settings from one time to the next. If you want to have default settings for a command, define an alias for it. For bash, the file where aliases are defined is ...


1

There are two main reasons for using cat as in your first example: As a place-holder for some other command or long and complicated pipeline of commands. e.g. if you're writing a script or one-liner to process a huge file, or data from a psql/mysql or wget or jq etc query, you might save (some of) the input to a sample file and use cat sample as input ...


0

On Linux, the network devices are listed in /sys/class/net/. Each device has an entry there and its type is given by /sys/class/net/$finame/type. The types are defined in if_arp.h: #define ARPHRD_IEEE80211 801 /* IEEE 802.11 You should be able to find all devices of a given type with: find_by_type() { ( cd /sys/class/net/ || return 1 ...


6

In your first example cat f.txt | grep "someText" grep doesn't get a filename argument, only a string to search for. In that case grep will read the text to search from standard input. In this case that standard input is piped in from the output of cat f.txt, which outputs the content of the file not the filename. What you also could have done to make ...


0

Enhancing Nate's answer to have PDF output and to plot lines (requires the rsvg-convert): | gnuplot -p -e 'set term svg; set output "|rsvg-convert -f pdf -o out.pdf /dev/stdin"; plot "/dev/stdin" with lines'


1

I do scene extracting from videos using vlc for linux. If you don't have it, use apt-get install vlc to install it. Once installed, you can use a variance of the following command line to extract frame(s) out of your video. The default image format is png and it is good for my purpose. If you insist on gif images, I suggest installing imagemagick for ...


1

Use POSIX ex. Yes, it's intended for file editing, but it will work in a pipeline. printf %s\\n 111 222 333 444 555 | ex -sc '1,2m$|%p|q!' /dev/stdin This can have any arbitrary commands added at the beginning or end of the pipeline and will work the same. Better yet, given the presence of /dev/stdin, it's POSIX compliant. (I don't know if /dev/stdin ...


0

If you only want the text in between ] and apal, perl is a good choice perl -lne '/(?<=\])(.+?)(?=apal)/ and print $1' file If you have GNU grep installed (via homebrew for example), you can grep -Po '(?<=\]).+?(?=apal)' file


0

If you can store the entire output in memory: data=$(some command) n=42 # or whatever { tail -n +$((n+1)) <<<"$data"; head -n $n <<<"$data"; } > outputfile



Top 50 recent answers are included