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....
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...
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.
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...
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...
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 ...
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...
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 "...
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...
If your file is called test.txt, you can do xargs -L 2 < test.txt ...
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...
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...
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...
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...
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...
$ sed "s/\\\\\\\'/\\\'/g" file 'one', 'two \'change', 'three \'unchanged' Here is a discussion on why sed needs 3 backslashes for one...
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...
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...
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...
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 ...
You need to change ServerName from scripts to page in second section in httpd-vhosts.conf.
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>...
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...
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)....
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 ...
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 ...
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).#! ...
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...
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...
Like so FOO="$(du -m myfile.csv)" echo "$FOO" Output 1.25 myfile.csv ...
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: $...
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...
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" >>...
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,...
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...
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,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,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...
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. =)...
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")"...
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 ...
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....
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...
[[ $( 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...
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...
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...
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...
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...
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()...
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;...
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()); } ...
Specify field separator with -F: awk -F":" '{print $2, $5}' ...
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)....
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...
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...
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...
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...
Use pipes for IO redirection: $> /home/user/Development/loc -c /vobs/unitTestStub/works.h | wc -l ...
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...
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...
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...
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...
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...
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' ...
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...
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',...
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...
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....
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...
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...
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...
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" }' ...
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 {} \; ...
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...
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" ...
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...
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...
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);...
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?...
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...
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...
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...
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...
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 ...
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....