Menu
  • HOME
  • TAGS

series of commands using nohup [duplicate]

shell,unix,nohup

nohup command1 && command2 && command3 ... The nohup will apply only to command1. When it finishes (assuming it doesn't fail), command2 will be executed without nohup, and will be vulnerable to a hangup signal. nohup command1 && nohup command2 && nohup command3 ... I don't think this would work....

Random password generate in shell script with one special character

bash,shell,unix,random,passwords

#! /bin/bash chars='@#$%&_+=' { </dev/urandom LC_ALL=C grep -ao '[A-Za-z0-9]' \ | head -n$((RANDOM % 8 + 9)) echo ${chars:$((RANDOM % ${#chars})):1} # Random special char. } \ | shuf \ | tr -d '\n' LC_ALL=C prevents characters like ř from appearing. grep -o outputs just the matching substring, i.e. a...

search value and count number from log file

linux,bash,perl,shell,unix

I would do something like this: cat log | grep -o "number\=[0-9]\+" | cut -d= -f2 | sort | uniq -c The output for your example is: 7 1193046 6 466000000 ...

^M behind operating system version?

linux,windows,unix,operating-system

vi and familiars (you're probably actually using vim) display the the return character as ^M. Since line endings in unix and windows are different, you get this displayed instead of an actual line break.

Modern-day Unix tools are written in what programming language? [closed]

c,linux,bash,unix,grep

Unix tools are written in a number of languages. Most of the classic tools are written in languages such as C and C++, but Perl and Python are also popular choices. C is still the dominant language, but it seems that Go might find some use in writing Unix command-line...

How to replace newlines/linebreaks with a single space, but only if they are inside of start/end regexes?

regex,linux,shell,unix,replace

You can do it using awk as: awk '/\[x/{f=1} {if(f)printf "%s",$0; else print $0;} /y\]/{print ""; f=0}' Output: [x data1 data2 data3 data4 y] [a data5 data 6 data7 data 8 b> [x data y] You can also simplify to: awk '/\[x/,/y\]/{ORS=""; if(/y\]/) ORS="\n";}{print}' Output: [x data1 data2 data3 data4...

find numbers divisible by 3 in csv file using shell script

bash,shell,unix,awk

awk -F'|' '{for(i=1;i<=NF;i++)if(!($i%3))print $i}' file this awk one-liner shoud do. With your example, the cmd outputs: 3 6 9 ...

nano: Move forwards/backwards one word with META+Left / META+Right

unix,terminal,nano

According to the manual page for nanorc, you cannot do this. It does not accept bindings for special keys modified by meta. This is what it says regarding M- (the meta-modifier): M- followed by a printable character or the word "Space". Example: M-C A similar question was asked in Bind...

Send alert for 80% threshold comparing two values from Disk partition

linux,unix,ubuntu,storage,diskspace

Here's an awk script I wrote years ago to do this very thing. Just put it in cron to run at a specified schedule. #!/bin/sh /bin/df | \ /usr/bin/awk '{if($5 ~ "%" && $6 !~ "proc") {used=$5} else {used=""}; \ sub(/%/, "", used); \ if(used > 80) print $6 "...

What does mean the @ (at) on unix access right?

php,unix,web,ls,access-rights

The @ symbol which you get from ll command (alias of ls -l) indicates which the file has extended attributes. Wikipedia: Extended file attributes are file system features that enables users to associate computer files with metadata not interpreted by the filesystem, whereas regular attributes have a purpose strictly defined...

How to convert following text in required format in unix?

unix,awk

If your file is called test.txt, you can do xargs -L 2 < test.txt ...

Join Statement omitting entries

unix,join,hidden-characters

I tried this out, and I noticed a couple things. First: this is minor, but I think you're missing a comma in your -o specifier. I changed it to -o 1.1,2.1. But then, running it on just the fragments you posted, I got only three lines of output: 1|1 3|3...

how to check a directory exist and can write file

oracle,shell,unix,sql-loader

For Checking Diretory is present if [ -d "$YOUR_DIRECTORY" ] then #Operation when directory is present else #Operation when directory is not present fi For checking if directory is writeable if [ -w "$YOUR_DIRECTORY"] then #Operation when directory is writeable else #Operation when directory is not writeable fi Regarding Oracle...

C++ Compile error on NetBSD '::system' has not been declared

c++,unix,boost,g++,netbsd

I do not know exactly why you are facing this problem, but I can provide you with some next steps to try. Notice that the first error is that pthread_detach is missing. The system header files will typically make sure whatever headers they need are included, but you can try...

Mounting GEOM_ELI Encrypted ZFS Pool as root

unix,encryption,freebsd,boot,zfs

Turns out I was correct. The daXp4.eli files are necessary as it's the metadata of each disk. A reference point if you will. By performing: geli backup /dev/daXp4 /boot/daXp4.eli It create the meta files required for geom to attempt a decryption at boot time. I hope this helps someone else...

Redirect Outward of unix os commands to html page

linux,unix,command

Try something like this (using command ls): # start the html file echo "<html lang="en"><head><title>Command Output</title></head><body><table>" > output.html # get the data needed to a file for processing ls -lah >> output.html # escape html entities with PHP (optional but recommended) cat output.html | php -R 'echo html_entity_decode($argn);' > output2.html...

Replace a double backslash followed by quote (\\') using sed?

regex,shell,unix,sed

$ sed "s/\\\\\\\'/\\\'/g" file 'one', 'two \'change', 'three \'unchanged' Here is a discussion on why sed needs 3 backslashes for one...

Unix: Where does “ls -l” get comma-separated values in size field for devices?

c,unix,ls

From the POSIX specification for ls: If the file is a character special or block special file, the size of the file may be replaced with implementation-defined information associated with the device in question. In this particular case, you almost certainly have an implementation printing the major and minor device...

A unix system programming project on windows?

c,unix,posix,system

Just do the project in Ubuntu. You're going to have a hard enough time learning about signals and process handling without having to worry about various differences between Cygwin and actual unix/linux. Another option is to install virtualbox and run Ubuntu within that. There should be no differences there. https://www.virtualbox.org/wiki/Downloads...

Unix - Tail Utility would open the file or not

unix,logic,tail

As per the source code of tail utility, it is opening the file in read mode not in write mode. So the answer is, I would say TAIL is opening the file for checks. But along with that i would like to answer one more question, since it is opening...

Identifying when a file is changed- Bash

bash,shell,unix

I would store the output of find, and if non-empty, echo the line break: found=$(find . -name "${myarray[i]}") if [[ -n $found ]]; then { echo "$found"; echo "<br>"; } >> "$tmp" fi ...

apache with virtual hosts: 403 forbidden

osx,apache,unix

You need to change ServerName from scripts to page in second section in httpd-vhosts.conf.

How to extract single-/multiline regex-matching items from an unpredictably formatted file and put each one in a single line into output file?

linux,shell,unix,replace,grep

Assuming that your document is well-formed, i.e. <b> opening tags always match with a </b> closing tag, then this may be what you need: sed '[email protected]<[/]\?b>@\n&\[email protected]' path/to/input.txt | awk 'BEGIN {buf=""} /<b>/ {Y=1; buf=""} /<\/b>/ {Y=0; print buf"</b>"} Y {buf = buf$0} ' | tr -s ' ' Output: <b>data1</b>...

Blocking in pthread_join()

c,multithreading,unix,pthreads

Yes - the main thread blocked on thrs[0] will not get the result from thrs[2] until after thrs[[0] and thrs[1] have also exited. If you need more flexibility one option is to do something like having the threads post their results in a queue or signal in some other way...

What does signal(SIGPIPE, SIG_IGN); do?

c,unix,signals

signal(SIGPIPE, SIG_IGN); simply ignores the signal SIGPIPE. Passing SIG_IGN as handler ignores a given signal ignores it (except the signals SIGKILL and SIGSTOP which can't caught or ignored)....

Redirect output from file to stdout

bash,shell,unix,stdout

Many tools interpret a - as stdin/stdout depending on the context of its usage. Though, this is not part of the shell and therefore depends on the program used. In your case the following could solve your problem: myprog -o - input_file ...

how to ssh run a tail and then send data to a mysql database

linux,bash,unix,ubuntu,ssh

If insertPerfmon.sh is: #!/bin/bash mydata=$(cat) echo $mydata # process & send $mydata to database The following should work: <your_ssh_command> | bash insertPerfmon.sh ...

awk if statement with simple math

unix,awk,gawk

There's no need to force awk to recompile every record (by assigning to $4), just print the current record followed by the result of your calculation: awk 'BEGIN{FS=OFS=","; OFMT="%.2f"} {print $0, $3*($3>1336?0.03:0.05)}' file ...

Scala Process for Linux is stuck

scala,unix,process,cat

I preformed the concatination in the same comend without creating new file and it's work fine: val copyCommand = Seq("bash", "-c", "cat \"" + headerPath + "\" \"" + FilePath + "\">FileWithHeader") Process(copyCommand).#! ...

Can not connect to an abstract unix socket in python

python,c++,sockets,unix,unix-domain-sockets

Your C++ doesn't do quite what you think it does. This line: strncpy(addr.sun_path, UD_SOCKET_PATH, sizeof(addr.sun_path)-1); Copies a single null character '\0' into addr.sun_path. Note this line in the manpage for strncpy(): If the length of src is less than n, strncpy() writes additional null bytes to dest to ensure that...

Running custom program located in /bin

linux,unix,path,bin

You can do it through your .bashrc, for example, like this: PATH=${PATH}:$(find ~/bin -type d | tr '\n' ':' | sed 's/:$//') Explanation: we search only for directories newlines get separated with : last : is stripped Aside from solutions like this, PATH doesn't understand pretty much anything other than...

storing 'du' result in a variable [duplicate]

bash,unix,putty

Like so FOO="$(du -m myfile.csv)" echo "$FOO" Output 1.25 myfile.csv ...

Why can I view some Unix executable files in Mac OS X and not others?

git,bash,shell,unix,binary

Executable files may be scripts (in which case you can read the text), or binaries (which are ELF formatted machine code). Your shell script is a script; git is an ELF binary. You can use the file command to see more detail. For example, on my nearest Linux system: $...

Extracting columns within a range AWK

unix,awk

You want to test for 0.75-0.8 but wrote code to test for 0.7-0.75 and you forgot to specify what to test in the second part of your condition. Do this: awk '$2 >= 0.75 && $2 <= 0.8' Also note that you want a numeric comparison not a string comparison...

Converting values from for loop to json format

linux,unix

Observe that each line except the first begins with ",\n". dir="myfiles/test/" prefix="" echo "[" >> test.json for dir in "${array[@]}"; do #reverse the result of comparisons file=$(find "$dir" -maxdepth 1 -type f -iname '*.txt' | awk "NR==$i") [[ -n $file ]] && printf '%b{ "filepath": "%s" }' $prefix "$file" >>...

Enumerating executable files in C

c,unix,directory,ansi

ep->d_name contains only relative pathname of the directory entry. So you should change the Current Working Directory to /tmp/hi before calling stat(2) if (chdir("/bin") != 0) { perror("chdir()"); exit(EXIT_FAILURE); } /* ... */ if (stat(ep->d_name, &sb) == -1) { perror("stat()"); exit(EXIT_FAILURE); } As noted in the comments by @Andrew Medico,...

Why is Unix/Terminal faster than R?

r,bash,shell,unix,terminal

I'm not sure what operations you're talking about, but in general, more complex processing systems like R use more complex internal data structures to represent the data being manipulated, and constructing these data structures can be a big bottleneck, significantly slower than the simple lines, words, and characters that Unix...

Find the maximum values in 2nd column for each distinct values in 1st column using Linux

linux,bash,unix,awk

awk seems a prime candidate for this task. Simply traverse your input file and keep an array indexed by the first column values and storing a value of column 2 if it is larger than the currently stored value. At the end of the traversal iterate over the array to...

Bash - Script that reads .txt file and stores the info in variables to be used later

bash,shell,unix,network-programming,network-interface

This is how would I handle the problem: #!/bin/bash if [[ $# != 2 ]]; then echo "ERROR: Usage is ./$0 eth-name profile-name" exit 1 fi eth=$1 profile=$2 if [[ ! -f "$profile.txt" ]]; then echo "ERROR: $profile.txt file not found!" exit 1 fi # TODO: validate $eth ip=$(awk '{print...

C programming bi directional communication

c,unix,multiprocessing,ipc,inter-process-communicat

Pipes are uni-directional and using sockets seems painful for a little ipc thing. I recommend you to use socketpair(). You can consider them as bi-directional pipes. Here is an example where the parent sends a character to its child.Then child makes it uppercase and sends it back to the parent.(It...

searching through text file in terminal

linux,unix,awk,grep,less

Until you edit your question to provide more info, is this what you want?: $ awk '$4==1 && $6==4' file BCD 2 4 1 1 4 2 The above was run against your posted sample input file: $ cat file col1 srt end col4 col5 col6 col7 ABC 1 2...

Delete numbers from filename

shell,unix

for i in $(ls) ; do mv $i $(echo $i | awk -F '.' '{print $1"."$3}'); done For testing change mv to echo. PS: Did the code from my head, but should work. =)...

Disregard word order when comparing two variables

shell,unix,sh

Let's define our variables: a="abc pqr mno xyz" b="mno pqr xyz abc" Now let's define a helper function which puts the words in alphabetical order: sorted() { echo "$1" | sed 's/[[:space:]][[:space:]]*/\n/g' | sort; } Now, using our helper function, lets test for equality: [ "$(sorted "$a")" = "$(sorted "$b")"...

How to grep for value in a key-value store from plain text

linux,shell,unix,grep

Use a look behind: $ grep -Po '(?<=^FOO=)\w*$' file foo I also like awk for it: $ awk -v FS="FOO=" 'NF>1{print $2}' file foo Or even better: $ awk -F= -v key="FOO" '$1==key {print $2}' file foo With sed: $ sed -n 's/^FOO=//p' file foo ...

SFTP Processbuilder

java,unix,sftp,processbuilder,ssh2-sftp

Two possible approaches: Use the scp command instead. It does the same ssh-based file transfer, but allows you to specify source and destination on the command line. ProcessBuilder pb = new ProcessBuilder("scp", "-i privateKey", "-r", "localFileDirectory", "[email protected]:remoteDirectory"); The -r is for "recursive", needed if you are transferring a whole folder....

What is wrong with these formats for Unix Shell Scripting Comparing Strings [duplicate]

bash,unix

Spaces in Bash are crucial not optional. Change the if statement to: if [ "$uInput" != "n" ]; then If you are wondering why? see this: Why should be there a space after '[' and before ']' in the Bash Script...

Bash script to email when wc -l count is below 3

linux,bash,unix,wc

[[ $( find /folder/with/files -type f | wc -l ) -lt 3 ]] && mail -t [email protected] -s Problem <<< "Less than three files." Find and wc -l return the count of files and then [[ evaluates if the count is lees than three. If this evaluates to true and...

How to do the expansion of variable in shell script? [duplicate]

linux,bash,shell,unix,ksh

Using bash -c: newvar="$(bash -c "echo $var")" Using eval: newvar="$(eval "echo $var")" Example: #!/bin/bash var='$PATH' echo "$var" #This will show that $var contains the string $PATH literally #Using bash -c newvar="$(bash -c "echo "$var"")" echo "$newvar" #using eval newvar="$(eval "echo "$var"")" echo "$newvar" It will print the environment variable paths...

Difference on bash and ash parentheses

linux,bash,shell,unix,ash

Don't confuse the angle bracket in <( … ) with the one in redirections like cat < file. In bash, <( echo hi ) is effectively a file with the contents "hi" (at least for reading purposes). So you can do $ cat < <( echo hi ) hi You...

How to perform parallel processes for different groups in a folder?

bash,unix,parallel-processing,groups

So my whole ordeal was with trying to use my code on a directory with a lot of files. In order to get rid of the errer stating that there are too many Arguments, I used this code that I gathered from previous Ole Tange posts: ls ./ | grep...

Reading rsync source from file results in improper parsing of file names with white space

bash,shell,unix,scripting,rsync

Replace for JOB in `cat /tmp/jobs.txt`; do rsync -avvuh "$JOB" "$DESTINATION"; done by while read -r JOB; do rsync -avvuh "$JOB" "$DESTINATION" done < /tmp/jobs.txt ...

Doubts with for loop in Unix

bash,shell,unix,for-loop

A for loop in shell scripting takes each whitespace separated string from the input and assigns it to the variable given, and runs the code once for each value. In your case b* is the input and $var is the assigned variable. The shell will also perform expansion on the...

how to break one column into multiple columns in Linux [duplicate]

linux,bash,shell,unix,awk

Try using: pr -ts" " --columns 3 file_name It is good and short if you don't want to use awk. There are other methods too (one I told you, I also learnt it from there): split a column in multiple columns...

Calling find more than once on the same folder tree

linux,bash,shell,unix,find

Try this: find . -mmin +35 -or -mmin -25 find supports several logical operators (-and, -or, -not). See the OPERATORS section of the man pages for more details. ==================== EDIT: In response to the question about processing the two matches differently, I do not know of a way to do...

pass enter key from Java to Shell script

java,unix,jsch

According to the JSch javadoc, you must call setInputStream() or getOutputStream() before connect(). You can only do one of these, once. For your purposes, getOutputStream() seems more appropriate. Once you have an OutputStream, you can wrap it in a PrintWriter to make sending commands easier. Similarly you can use channel.getInputStream()...

Split a column's values into multiple rows awk/unix/python

python,unix,awk

This may help you $ cat file header: id,indicator,{(pid,days_remaining)} row: id_558314,1,{(property_66021,7),(property_24444,1),(property_285395,6)} $ awk -F, '{gsub(/[{}()]/,"")}FNR==1{print;next}{j=0;p=$1;for(i=3; i<=NF; i+=2){ $1=p;sub(/:/,++j"&",$1);print $1,$2,$i,$(i+1)}}' OFS=, file header: id,indicator,pid,days_remaining row1: id_558314,1,property_66021,7 row2: id_558314,1,property_24444,1 row3: id_558314,1,property_285395,6 Better Readable version awk -F, '{ gsub(/[{}()]/,"") } FNR==1{ print next } { j=0 p=$1 for(i=3;...

Multiple line search in a file using java or unix command

java,shell,unix,command

You can find like this. File file = new File("data/pattern.txt"); Pattern pat = Pattern.compile("subclass \"Pool1\" 11:22:33:44:55:66 \\{\\s*dynamic;\\s*\\}"); String content = Files.lines(file.toPath()).collect(Collectors.joining("\n")); Matcher m = pat.matcher(content); while (m.find()) { System.out.printf("found at %d-%d%n", m.start(), m.end()); } ...

Bash Scripting - AWK with Delimiter?

bash,unix,awk

Specify field separator with -F: awk -F":" '{print $2, $5}' ...

Selecting unique lines based on two columns

unix,awk

You can perfectly use an index that uses more than one field for the array elements: awk -F"\t" '!seen[$2, $3]++' file In this case we use $2, $3 as index. This way, we will get all different elements of the tuples ($2, $3)....

C std library don't appear to be linked in object file

c,osx,unix,objdump,otool

Dynamic libraries are linked to the final executable, not to the object files, so you should run (e.g.) otool -L com_ex1 This should show something like com_ex1: /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0) because on OS X, the math library is part of libSystem: $ ls -l /usr/lib/libm.dylib lrwxr-xr-x...

How to send message (in C) from one thread to another?

c,multithreading,unix,pthreads

An example, it's pretty simple — first make a pipe with pipe(). It creates two file descriptor — one for reading, and the second for writing. Here we calling it two times to have both read and write sides. Then we calling fork (that makes a second thread), and write/read...

gzip and pipe to output (performance consideration)

linux,unix,encryption,gzip,solaris

Gzip is a streaming compressor/decompressor. So (for large enough inputs) the compressor/decompressor starts writing output before it has seen the whole input. That's one of the reasons gzip compression is used for HTTP compression. The sender can compress while it's still generating content; the recipient can work on decompressing the...

Improving a sort program's efficiency; displaying column sort % completion in terminal

python,perl,sorting,unix

From your sample data, you are going to sort approximately 950MB. It will take 9.5s reading from normal HD (100MB/s). I do not know how fast it will be sorted by standard sort but from my experience it can go 1-3 millions of records per CPU core. Let's say 1...

wc -l on unix command return value

linux,shell,unix

Use pipes for IO redirection: $> /home/user/Development/loc -c /vobs/unitTestStub/works.h | wc -l ...

Capture tee's argument inside piped Perl execution

perl,unix

The short answer is - you can't. tee is a separate process with it's own arguments. There is no way to access these arguments from that process. (well, I suppose you could run ps or something). The point of tee is to take STDOUT write some of it to a...

How to make zero the entire row except the first column, if it has a zero in any other colum in Linux?

linux,bash,shell,unix,sed

Assuming the columns in your input file are separated by tabs: awk -F'\t' '{ if ($2 == 0 || $3 == 0) { $2 = 0; $3 = 0 }; printf("%d\t%.1f\t%d\n", $1, $2, $3) }' ifile.txt Output: 1 4.5 9 2 0.0 0 3 2.4 4 4 3.1 2 5...

ImageMagick - Making 2 GIFs into side by side GIFs using IM convert

image,unix,imagemagick,imagemagick-convert

I don't have 2 animated GIFs of the same length, so I'll just use two copies of this one: Let's look at the frames in there, with this: identify 1.gif 1.gif[0] GIF 500x339 500x339+0+0 8-bit sRGB 32c 508KB 0.000u 0:00.000 1.gif[1] GIF 449x339 500x339+51+0 8-bit sRGB 32c 508KB 0.000u 0:00.000...

How to find average and maximum in an interval using Shell [closed]

linux,bash,shell,unix,awk

Please make a search before you ask any question many posts are already there You can try something like below, modify accordingly Input [[email protected] tmp]$ cat input.txt 1 3 2 5 3 4 4 3 5 2 6 1 7 3 8 3 9 4 10 2 11 2 12...

Replacing alternate spaces with newline?

unix,replace

awk might help in this case: echo "0 1 2 3 4 5" | awk ' { for (i=1; i<=NF; i++) { if ((i-1)%2 == 0) { printf "%d ",$i; } else { print $i } } } ' We split by space and have 6 items. We, then, are...

Grep a gzipped file?

unix,gzip

If you mean you just want to do this in a pipelined fashion, this should work: curl http://www.imdb.com/sitemap_US_02002.xml.gz | zcat | grep 'imdb.com/title/tt' ...

How to remove characters before and including an underscore?

linux,string,bash,unix,awk

Using Parameter Expansion: $ var="fooo_barrrr" $ echo ${var#*_} barrrr To change the var itself, var=${var#*_}. Note this removes up to the first _: $ var="fooo_barrr_r" $ echo ${var#*_} barrr_r If you wanted to remove up to the last one, you would need to use ## instead: $ var="fooo_barrr_r" $ echo...

Zip all subdirectories using python

python,linux,unix,ubuntu

Probably your issue is with the path you're passing as an argument. I've tried your script with the following changes: import shutil import os loc = "testfolder" path = os.getcwd() + '/' + loc + "/" dirs = os.listdir( path ) for file in dirs: name = file shutil.make_archive(name, 'zip',...

How to fix btrfs root inode errors

unix,fsck,btrfs

Provided that the broken inodes are the only problem present, the solution is to simply remove them. There may be a quicker way to do this, but here is what worked for me. From here I gleaned that you can use the find command to search for an inode like...

Output of SQL query and command to a file in shell script

bash,shell,unix,cron

You are overwriting the file. echo moo >output.lst echo bar >output.lst Now, output.lst only contains bar. The trick is to append, instead of overwrite. echo moo >output.lst echo bar >> output.lst Your script has multiple additional problems, so it is not really clear what you actually want it to do....

C - does read() add a '\0'?

c,unix,io,posix,unbuffered

does read() add a '\0'? No, it doesn't. It just reads. From read()'s documentation: The read() function shall attempt to read nbyte bytes from the file associated with the open file descriptor, fildes, into the buffer pointed to by buf. Is there potential for error here, other than the...

Kill command in UNIX

linux,bash,shell,unix,ubuntu

See the manual page (http://linux.die.net/man/2/kill) If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init), but see below. So I guess that is you out of the system - but life continues for the...

Path of the current, parents and root directory

shell,unix,sed,path,pwd

gnu sed echo $(pwd) | sed -r -e 'p; :a; s#(.*)/.*#\1#; H; ta; x' | sed '/^$/d' this will print all directories from current -> root it uses greedy search for '/' keeping only left part, appending in hold space, ta is conditional branch for substutution, so if there is...

How to create a new file where each new line contains some text and quoted line/step number?

shell,unix,command-line,awk

The code needs to be placed inside of BEGIN block: gawk 'BEGIN { for (i = 1; i <= 1000; i++) print "begin\""i"\"text"i"end" >> "path/to/output.txt" }' ...

Copy file into multiple directories - Unix

linux,bash,unix,directory,directory-structure

First try (has limitations) for d in $(find . -maxdepth 2 -type d | grep "/.*/"); do cp file "$d" done LIMITATIONS: No spaces/slashes/glob characters in the dir-names Second try (cleaner, thanks to gniourf_gniourf) find . -maxdepth 2 -path './*/*' -type d -exec cp file {} \; ...

Is setting environment variable through a makefile - possible?

c,unix,makefile,malloc,gnu-make

Browning, setting an environment variable in the makefile is easy, and you have done so, but that is not what you want. That makes it take that value during the compile. But you want it to change malloc's behavior when you run the program. Reading the man page you referenced...

Unable to connect to mysql after automating mysql-server installation in bash script

mysql,linux,bash,unix

I think Álvaro its right about the quotes, try something like debconf-set-selections <<< "mysql-server mysql-server/root_password password $passdb" debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $passdb" ...

Where is the cupsctl terminal executable on MacOSX?

osx,shell,unix,find,cups

Use the UNIX find command to search your entire disk starting at the root e.g. find / -name 'cupsctl' Shouldn't actually take all that long assuming an average sized SSD. A couple of seconds on my Mac $ sudo find / -name 'cupsctl' 2> /dev/null /usr/sbin/cupsctl or, as it's OS...

schedule automate shell script running not as ROOT

python,linux,shell,unix,linux-kernel

Ideally you should have your system administrator add your user account to /etc/cron.allow - without that you do not have permission to use the crontab command, as you probably discovered. If that is not possible, then you could use a wrapper shell script along these lines (note: untested): #!/bin/bash TIME="tomorrow...

`fs.mkdir` is creating the directory with different permissions than those specified

node.js,unix,permissions,fs

Because it applies umask on your mode. Type umask in your console, you will see 022 or 0022. You can overwrite it for your node process with process.umask(newmask);...

How to open a new terminal from my working terminal with same directory in Linux?

linux,unix,ssh

if you connect to your remote server via ssh -x [host] now run gnome-terminal & this will open a terminal with the same ssh connection. is this what your were after?...

Unix c program to calculate pi using threads

c,unix,pthreads

There are numerous problems with that code. Your specific problem is that, in C, variable length arrays (VLAs) are not permitted at file scope. So, if you want that array to be dynamic, you will have to declare the pointer to it and allocate it yourself: int N, T; double...

How to search for a text in specific files in unix

unix,grep

It might be better to use find, since grep's include/exclude can get a bit confusing: find -type f -name "*.xml" -exec grep -l 'hello' {} + This looks for files whose name finishes with .xml and performs a grep 'hello' on them. With -l (L) we make the file name...

Use Unix Executable File to Run Shell Script and MPKG File

osx,shell,unix

The most common issue when handling variables containing paths of directories and files is the presence of special characters such as spaces. To handle those correctly, you should always quote the variables, using double quotes. Better code would therefor be: sudo sh "$path/join.sh" sudo sh "$path/join2.sh" It is also advised...

How can I configure and allow pipes in my bash script?

bash,unix

In Unix like systems, everything is a file.Funneling output of a command (again, it is a file) to another as an input is called pipe lining (or piping in short). So when you see a set of commands as follows: history | grep ls | less history : returns list...

awk — adding a new delimiter to the default space delimiter

unix,awk

You can specify a regular expression as the delimiter: echo "1 2"|awk -F"[ |=]+" '{for (i=1;i<=NF;i++) print $i}' It also means echo "1 2 3==5"|awk -F"[ |=]+" '{for (i=1;i<=NF;i++) print $i}' would print 1 2 3 5 ...

My JSch session doesn't execute command

java,unix,jsch

I assume the problem is that you close the connection before the command is even started. All the examples your pointed to read a command output, until the end (hence until the command finishes). You do not read the output so you fail to wait for the command to finish....