date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,437,404,310,000
According to Using "&&" is not effective for cURL submit form (don't execute second line if first line fails) In below code; first line is curl submit; second line is for queuing: curl -b cookies.txt \ -d title="$(sed '1,/sblmtitle/d;/slpstitle/,$d' sedut.html)" \ -d taxonomy%5Btags%5D%5B1%5D="$( sed '...
So you hit upon the key here, if curl's output is different then you can test for it. First you can direct that to a file. Next you can leverage the -s option from test: -s file True if file exists and has a size greater than zero. Here is some example code: curl -b cookies.txt ... -o /tmp/curl_output if [ -...
Success/fail tests for cURL (don't execute second line if first line fails)
1,437,404,310,000
I can see that uppercase letter means default here. Is there a standard for this? I'd like to read the full standards.
It isn't a written standard, it is, however, a de facto standard, meaning it had been used and found useful, so it came to be the common way to do things. As Alex said - from common sense.
What's the standard used by yum prompt "Is this ok [y/N]:"?
1,437,404,310,000
I'm writing a perl program where I want to accept all kinds of "file names" from the user, including /home/foo/bar.txt and scp://server/some/file.txt or whatever. And then I thought that if I can find a cmd line program that does it, I'll find a perl module that does it too, or I'll just run it through perl's system()...
I believe protocol name is sftp, not scp. In my system, following works: lftp -c 'get sftp://someserver/file', as well as ftp and http.
Need command-line program to download all of http:// https:// scp:// ftp:// style links (on e.g. ubuntu)
1,437,404,310,000
When I try to send email from alpine I get the following error: Error sending: connection failed to gmail-smtp... (The message disappear before I have the time to copy it). I suspect this is a firewall issue (I'm in a university campus). How can I fix this (or at least confirm)? Edit: I tried to telnet: yotam@sumsu...
Try connecting directly to the SMTP port on the server via telnet? See the Wikipedia page for an illustrative example. Start with the following (for a SMTP connection at port to smtp.gmail.com at port 25). Replace with the server and port you are using. In the following, EHLO and HELP are typed at the client prompt, a...
alpine failed to connect to smtp.gmail.com
1,437,404,310,000
So someone decided to set my gnome background as a practical joke to a rather disturbing picture. However, I don't use gnome and only log into it by accident. I need to remove the picture so when I accidently log into gnome it's not there. Can someone tell me what part of what file to modify?
gconftool-2 -t string -s /desktop/gnome/background/picture_options scaled # background style gconftool-2 -t string -s /desktop/gnome/background/picture_filename PATHTOIMAGEHERE # background file
How do I unset a background in gnome on the command line?
1,437,404,310,000
I've installed Ubuntu Server 10.10, and when I press up in a terminal nothing happens. Using Ubuntu Desktop it gave me the previous command that I ran. How can I make it do this in Ubuntu Server as well?
Does the up arrow key work in other contexts? It sounds like you might have the keyboard mapped wrong, bash history should be pretty easy.
Pressing `up` to get the previous command in a tty on Ubuntu Server
1,437,404,310,000
I am planning to setup a groupware server that's either Citadel or SOGo, which supports the GroupDAV, CardDAV, or SyncML protocols. Is there a commandline e-mail client that supports syncing contacts via such protocols either out of the box or with a plugin/extension?
According to the documentation of both of the software products you linked to (here and here) both support storing directory information using LDAP. If you do not find a command line email client that supports the protocols that you mentioned, you could try using LDAP instead. Every decent email client supports LDAP...
Commandline e-mail client that syncs contacts with external server?
1,437,404,310,000
I have un-tarred the nzbget0.70 debug version and have put it in the /ffp/bin dir. and I have a config file in the /ffp/etc/ dir but when I try to run it, I get the following: root@NAS:/mnt/HD_a2/ffp/bin# nzbget -sh: nzbget: not found root@NAS:/mnt/HD_a2/ffp/bin# sh nzbget nzbget: line 1: syntax error: word unexpected...
nzbget is a binary file; you can't use sh to process it, you would do that if nzbget were a shell script. Running just nzbget didn't work because by default the current directory is not on the PATH, so you need to do something like: $ ./nzbget Or: $ /mnt/HD_a2/ffp/bin/nzbget
CH3MNAS Fun Plug and NZBget. Cannot launch NzbGet 0.7, word unexpected
1,287,184,988,000
I wrote a bash command to scan /var/log/auth.log for messages occurring on the current day indicating unauthorised access. Currently it just fetches messages matching BREAK-IN and unauthorized. What other strings should I search for in /var/log/auth.log to keep tabs on unauthorized access? Here's the script for refer...
You could look for "Invalid user" which is thrown when someone tries to logon with an account that does not exist. It will also throw up "Failed password" when you enter in an invalid password. Also, you dont need to use cat to dump the file to grep. Grep can already look at the file as its second option. 'Grep sea...
What strings should I look for in /var/log/auth.log?
1,287,184,988,000
I have command line utility that generates text strings, by running a command within the directory: ./Utility -P it prints output on terminal. How to make a shell script showing the generated string in the Info dialog box, where the output can be selected by mouse and copied. So I need send information from a shell s...
This will capture standard output from this sub shell and save it to an environment variable named output. You can call it any other name. output="$( ./Utility -P )" zenity --info --text "${output}" --title "Utility finished" There are alternative tools such as yad (a fork of zenity iirc), or even a way to use your d...
Shell script to run command and show output in notification box
1,287,184,988,000
I'd like to generate a full-page QR code from the command line. The following command sort of accomplishes this: qrencode -o- https://example.net | convert png:- -gravity center -units pixelsperinch -density 300 -resize 2551x3295 -extent 2551x3295 qrcode.pdf Unfortunately, the resulting QR code is quite blurry, as t...
Change your resize to scale which uses "nearest neighbour" interpolation - i.e. it only uses colours already present in the original image without introducing new ones by doing interpolation between the old ones: qrencode -o- https://example.net | convert png:- -gravity center -units pixelsperinch -density 300 -scale ...
How to generate full-page QR code from command line?
1,287,184,988,000
If you have only one instance of VLC running, you can talk to VLC with dbus-send using org.mpris.MediaPlayer2.vlc as destination: $ dbus-send --dest=org.mpris.MediaPlayer2.vlc ... If you have two instances of VLC running, they have different destinations xxxx and yyyy. If you want to talk to one of them, you must us...
i always use busctl to get the complete dbus infos. There is a system bus (busctl --system) and a session bus (busctl --user) or complete list (busctl -l) enter: busctl --user | grep "vlc" then you get something like this :1.641 91266 vlc xxxxx :1.641 ...
How to get the destinations of two instances of VLC
1,287,184,988,000
I can run a command in all directories named _QWE using: find . -name '_QWE' -type d -execdir touch {}/1234.txt \; However, I need to run -execdir rename 's!^\./(\d+ -)\s(\d+\.)!$1!' {} \; in all the immediate sub-directories of _QWE to rename the sub-directories of the sub-directories of _QWE. I mean suppose I have ...
You could use the -path modifier to pick out directories immediately under the matching directories: find . -depth -type d -path '*/_QWE/*/*' ! -path '*/_QWE/*/*/*' -exec rename 's!(/\d+)\s+-\s+\d+\.\s+([^/]*)$!$1 $2!' {} + I have modified your RE slightly to anchor it to the filename component of the matched path. (...
Rename the sub-sub-directories of a directory named _QWE
1,287,184,988,000
In my lubuntu 18.04 distribution I have installed google-chrome version 114. By a bash script, at every boots, Chrome is launched and connects to a specific URL. The URL is always the same, but sometimes the content of the web site changes so I need to clear the cache of google-chrome at every boot. This need comes f...
After many tests of switch off and on on my system it is reasonable to think that a script which executes commands: rm -rf /home/myuser/.cache/google-chrome/* rm -rf /home/myuser/.config/google-chrome/Default/* is sufficient to clear all cache data of Google Chrome.
How to clear all cache data of google-chrome by commands executed by a bash script?
1,287,184,988,000
I've got a program that will be generating 4 large binary files (400GB+ each) that I need to upload to AWS S3 as quickly as possible. I'd like to begin uploading before the files are completely written; I'm toying with a few approaches and one that I feel may be viable is using split, but my implementation has a lot o...
Thanks for the input folks; lots of good suggestions and questions have allowed me to come up with a workable solution for the handful of times I need to use this. To answer a bunch of questions though: it's for a migration to a different AWS account, including restoring the DB; I'm constrained by security and archite...
Split large file in realtime whilst it is still being written to
1,287,184,988,000
Is is possible in bash - or other sh-derivative shell - to run in the foreground from command-line a list of commands that have their own variable scope (so any values assigned to variables in that scope will not known outside that scope), but also - if spawning a background command - that background command still be ...
In zsh, you can use an anonymous function, but you still need to declare variables as local. For instance: $ () { local t; for t in 100 200 300; do sleep $t & done; } [2] 4186 [3] 4187 [4] 4188 $ jobs [2] running sleep $t [3] - running sleep $t [4] + running sleep $t $ typeset -p t typeset: no such varia...
Separate variable scope spawning commands under job control
1,287,184,988,000
I am working with an old Raspberry Pi that only has text mode. Distro is Raspberry Pi OS based on Debian 11. By default the emoji characters only print as white diamond shapes in tty; in fbterm they show up as question mark in diamond shape. I can get fbterm to display glyph like Chinese characters by installing a pro...
Emojis are graphical elements. Terminals like fbterm are character-based, and cannot display graphical elements. In terminal environments you're limited to smileys such as :-) or ;-) just like in ye olden days.
Display emoji in tty or fbterm?
1,287,184,988,000
I'm using exiv2 0.27.2. I want to print the tag values of multiple webp files, but without the filename being printed. With the following command: exiv2 -g Exif.Image.Artist -Pv *.webp I get the following output: 3q2NIGNI_o.webp tomato 3qAwrJWu_o.webp orange 3qDZg9vz_o.webp cantelope I just want th...
You either post-process the output with a tool like sed etc exiv2 -g Exif.Image.Artist -Pv ./*.webp | sed 's/.*\.webp[[:blank:]]*//' or use a loop to pass a single file at a time: for f in ./*.webp; do exiv2 -g Exif.Image.Artist -Pv "$f"; done or use exiftool e.g. exiftool -q -p '$Exif:Artist' ./*.webp
Exiv2: How to print tag values without printing the corresponding filenames
1,287,184,988,000
How to chain commands, i.e. make the output of one command become the input of another? basename | dirname /dev/null Expected Output: dev Actual Output: usage: basename string [suffix] basename [-a] [-s suffix] string [...] /dev Also tried the following but it also did not work: dirname /dev/null | basename ...
It should be: basename "$(dirname /dev/null)" Though for arbitrary file paths where you can't guarantee path components won't start with -, you'd need to add some --s to mark the end of options: basename -- "$(dirname -- "$file")" $(...) can be used to run a command and collect output to be used as a command line pa...
How to chain commands
1,287,184,988,000
I have a few csv-s, each containing 3 columns separated by ",". Example: header1,header2,header3 value1,value2,value3 value1,value2,value3 ... Using this tutorial, I thought if I execute paste -d "," *csv > output.csv I will end up with something like this: header1,header2,header3,header1,header2,header3,... value1,v...
Most likely, your original files have \r\n end of lines. If it is so, the final file would have an extra \r between each line segment. Try using tr: paste -d "," *csv | tr -d "\r" > output.csv
paste command puts data from csv files vertically line by line instead of horizontally next to each other
1,287,184,988,000
When I type a long command on a command-line interface. Something strange may happen in the layout. The characters I typed don't show in lines correctly. Instead, they merge into 1 line or overwrite each other. And the cursor isn't displayed in its right place. For example: I want to type: /home/user/example/a/b/c>$ t...
Try this... Enter this command: export PS1="$PWD>" Then try a long command and see if the behavior changes. If it does, there's most likely a problem with the PS1 definition in your profile. When customizing PS1 try not to get too fancy, and avoid special characters and control codes if at all possible.
Chaotic Command-line Interface Layout
1,287,184,988,000
Sometimes I have output from a command line script that I would like to further process/filter with cli tools. I can't re-run the command because it takes a long time or will not produce the same output again. Currently I paste the output into a new file in the text editor, save it and then use cat on cli to pipe it i...
As suggested by @muru I use a clipboard-to-shell tool now: xsel. When I find that cli output needs to be mangled further, I select and copy it with ctrl+shift+c to the clipboard. Then I use xsel -b (= xsel --clipboard) to paste it as standard input to other tools: $ xsel -b | grep foo | sed s/bar/baz/ This is solutio...
Quickly filter text with cli commands
1,287,184,988,000
I have linux server. I expect there's headless GUI that can be controlled by CLI for my server. I do know it possible display GUI with XRDP. But I expect I can control it with SSH or CLI. It works fine when i'm using XRDP. I have OpenBox (a windows manager) installed. I expect I can interact GUI with CLI or maybe ther...
It seems that Environment Variable DISPLAY was not set correctly here. It should be set to something like this: export DISPLAY=:0.0 Or more generally: export DISPLAY=$HOSTNAME:$N.$W Where $HOSTNAME & $N & $W should match the Existing Situation. In OP case, HOSTNAME is empty (which means localhost) & N is 10 (which can...
Interacting with GUI from CLI (headless GUI)
1,287,184,988,000
I would like to know if there is any difference in the final output between the various command-line tools for encoding FLAC files, like ffmpeg, sox, the “official” flac etc. In some contexts, I have noticed that it's recommended to use flac over the others, but given that FLAC represents lossless encoding, am I corre...
The FLAC encoder has a ton of parameters, so you'll need to consult with the source code of ffmpeg/sox to see how they use the codec but despite all of this does it really matter? FLAC is a lossless encoder, so even if flac, ffmpeg and sox produce different FLAC files, they will all decode bit perfectly. FFmpeg will p...
FLAC encoders – any difference in output between the command-line tools?
1,287,184,988,000
I use Z shell on Mac and have some settings in both .zshrc and .profile in my home directory. I found that when I only have .profile, zsh import .profile in a new session; and when I have both .profile and .zshrc, zsh only import .zshrc while ignoring .profile. Is there any way to make the shell respect both settings ...
Zsh typically sources .zprofile rather than .profile at login. (It will not source .zshrc if the login does not go to an interactive session.) However, if you want it to source .profile and there's nothing specific to another shell in there (like bash-specific stuff), you can always put source .profile in the .zprofil...
How to make Z shell respect both ~/.zshrc and ~/.profile simultaneously?
1,287,184,988,000
I have 1 x big folder that has lots of .txt files I am trying to group these .txt files in separate subfolders based on specific rules from a rules.csv file (on what subfolder they belong to): LARGE FOLDER: file1.txt file2.txt ... file100.txt The rules would be: file1.txt file3.txt file8.txt belong to "subfolder1" fil...
Assuming your files has no whitespaces in their name as shown in your question which they don't, then you could use a simple shell-loop to move the files into thier corresponding directories in the second column. while IFS=' ' read -r fileName dirName; do mkdir -p "./$dirName" && mv "./$fileName" "./$dirName"; don...
Move files in subfolders based on the specific rules from a file
1,287,184,988,000
I have following files starting with a digit. $ echo [0-9]* 1001tracklistsIcon.svelte 1passwordIcon.svelte 3mIcon.svelte 42Icon.svelte 4chanIcon.svelte 4dIcon.svelte 500pxIcon.svelte And I'd like to rm them. I tried this but not working: $ find . -type f -name [0-9]* -exec rm {} \; find: 1passwordIcon.svelte: unknow...
You need to wrap your pattern in "": $ find . -type f -name "[0-9]*" -exec rm {} \; Otherwise your shell will replace it with the matching file names before running find.
How to rm files starting with a digit
1,287,184,988,000
I have this bash script: #!/bin/bash OriginFilePath="/home/lv2eof/.config/google-chrome/Profile 1/" OriginFileName="Bookmarks" OriginFilePathAndName="$OriginFilePath""$OriginFileName" DestinationFilePath="/home/Config/Browser/Bookmarks/ScriptSaved/Chrome/Profile 1/" DestinationFileName=$(date +%Y%m%d-%H%M%S-Bookmark...
It is perhaps hard to notice, but message gives you two hints: cp: target '1/20211207-001444-Bookmarks"' is not a directory | | | +-- Notice quote +-- Space in target In other words 1/20211207-001444-Bookmarks" is not a directory. So...
Linux "cp" command inside bash script
1,287,184,988,000
Object: to find the IP addresses of HTTP servers in a pcap file with a specific header string. Can or should the -l option to flush be used? One way: the following was done but am wondering if it can be shortened. If this question is too broad, please advise. tshark -r file.pcap -T fields -e ip.src -e http.server > n...
If you want a count of the src IP addresses in the frames that also contain an HTTP response with a Server header containing xxx_xxx, you could do: tshark -r file.pcap -T fields -e ip.src 'http.server contains "xxx_xxx"' | sort | uniq -c | sort -nr See the doc for the syntax of wireshark display filters. Some of ts...
TShark pcap filter command possibly simplified?
1,287,184,988,000
I have a laptop with Artix Linux on it that I'm using as a web server. I want to keep it minimalist, w/o graphical environment and only the absolute necessary software. My problem is I still don't know how to turn off/on the display (to save energy) when I'm not interacting with it (which I do very rarely). I am aware...
Nevermind, I found a page in ArchWiki that explains everything. No additional software is needed. All I have to do is change the value in /sys/class/backlight/intel_backlight/brightness to 0 to turn the display off. To turn it back on, I can use any value grater than 0. The maximum value can be found in /sys/class/bac...
Turn off/on laptop display from TTY without additional software
1,287,184,988,000
I have an example to better illustrate what I'm talking about: $ touch tas $ ln -s /etc/leviathan_pass/leviathan3 /tmp/l2/tas ln: failed to create symbolic link '/tmp/l2/tas': File exists Basically I can only symlink if the file I want to link doesn't exist. I understand this issue when talking about hard links - th...
The command ln won’t clobber existing files by default. You can use ln -sf TARGET LINK_NAME to force overwriting the destination path (LINK_NAME) with a symlink. You can use ln -f TARGET LINK_NAME to overwrite LINK_NAME with a hard link to, your explanation doesn’t make any sense about inode conflict. It just repla...
Why can't I symlink a preexisting file to a target file? [duplicate]
1,287,184,988,000
With the screen command, the -X option allows you to execute a command in the specified screen session, but when you try to use it when creating a new screen, e.g: screen -dmS -S downloader -X "wget https://google.com" you get the error No screen session found.. So it's clear the the -X option only works for pre-exis...
I found my answer, although it was under a different title and the question was slightly different, this does the job: screen -d -S downloader -m wget https://google.com It creates a new screen called downloader, detaches it and runs the command.
Execute command when creating new screen session
1,287,184,988,000
I'm using stat like this: stat -f "%Sp %p %l %Su %u %Sg %g %z %a %N %Y" /* I need also to tell if the file is hidden or not (MacOS). The . notation is not enough. MacOS hides more files. For example, this is what I need: ls -lO total 9 drwxrwxr-x 32 ro...
If macos stat is like FreeBSD's, the flags can be expressed in the format specification with %f for the numeric form or %Sf for the decoded text form like in ls -lo. See man stat, man chflags and man ls on your system for details.
Can stat show if file is hidden?
1,287,184,988,000
I have a below curl command which works fine and I get the response back. I am posting json data to an endpoint which gives me response back after hitting it. curl -v 'url' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' ...
Your data payload is a JSON document containing a query key. The value of that key is a JSON-encoded document, possibly describing some form of query, which is not in itself a JSON document. Newlines are encoded as \n in JSON values, and the JSON parser that the server is using would translate these into literal newl...
How to send curl request with post data imported from a file
1,287,184,988,000
I'm running a bash script to output logs under a log directory. Initially I want to know how many logs are generated, simply do the following: ls logs | wc -l And as the bash script is running in real time, I can further use: watch -n 5 'ls logs | wc -l' to display the number of log files concurrently. But I also know...
I'm not sure if xargs can accept two arguments from 2 commands. It can run a command with multiple arguments spread across multiple lines from input. For example, this will tell xargs to run expr with three arguments taken from input (which are, in order, the number of logs, -, and the number of lines in file.txt): ...
how to use one command line to calculate substration of two intergers as results from two other commands
1,619,895,044,000
The time command is very useful for checking how much time it takes for a piece of code that I develop to run... However, I'd like to have a way to check the memory consumption of the codes that I develop too, regardless of the language that I use. So, if it's bash, python, or node.js... I'd like to have a way of che...
On many Unix-like systems, yes, GNU’s implementation of /usr/bin/time (with the path, to avoid the similar shell built-in) will tell you how much memory a given program execution used; for example: $ /usr/bin/time ls ... 0.00user 0.00system 0:00.00elapsed 50%CPU (0avgtext+0avgdata 2208maxresident)k 0inputs+0outputs (0...
Is there any way of checking the max memory consumption of a code that I run with the command line? [duplicate]
1,619,895,044,000
I'd like to use keys from a second keyboard to create custom shortcuts that are useful to me. For example, having to write a lot of math formulas, I'd like to press a key from the second keyboard, let's say the a key, for writing "\nabla" in a LaTeX editor. At the moment, I'm following this answer, that exploits the ...
For this I would use kmonad although it is probably overkill. It allows you to redefine every key differently on every connected keyboard. These keys can be traditional keyboard macros, or can act as new modifiers. This allows you to define new "layers" so you can type say Greek or maths. For the specific case of nabl...
Remap keys from a second keyboard in Ubuntu - towards the optimal solution
1,619,895,044,000
My script takes arbitrary number of arguments and also few options: I need to extract any options plus the first argument into one string, and any remaining arguments into a second string. ie: ./script.sh foo FILE1 [s1="foo" s2="FILE1]" ./script.sh foo FILE1 FILE2 FILE3 [s1="foo" s2="FILE...
set -o extendedglob first_set=("$@[1,(i)^-*]") first=${(j[ ])first_set} would store in $first the concatenation of all arguments up to the first that doesn't start with - with one space character in between. Then for $second, you can get the rest: second_set=("$@[$#first_set + 1, -1]") second=${(j[ ])second_set} I...
zsh: extract command line arguments into two strings
1,619,895,044,000
I have two tab-delimited files where I need to match text in the first column of file 1 to any position in lines of file 2. Upon a match I then want to print what's in the second column of the matching line of file 1 to the end of the matching line in file 2 (example below). I know this can almost certainly be done wi...
We could parse file1, map values ($2) to keys ($1), then parse file2 and append value to line, when a part of the line ($3) matches any key. BEGIN {OFS = FS = "\t"} FNR == NR {arr[$1] = $2; next} {for (x in arr) if ($3 ~ x) {$0 = $0 " " arr[x]; break}} {print} This prints correct results for your example but it is no...
Map field of first file based on patten matching in second file
1,619,895,044,000
Consider a directory containing sub directories sub1, sub2, sub3 etc. Now consider the case that I am in sub3 and want to switch to sub4, I do something like cd ../sub4. However I want something like next to switch to the "next" directory and prev to switch to the previous one, where the order should be alphanumerical...
You could define cdprev and cdnext functions like: cdnext cdprev() { local dirs i dirs=(${PWD%/*}/*(nN-/)) if (($#dirs <= 1)); then print -ru2 No other dir in $PWD:h return 1 fi i=$dirs[(Ie)$PWD] if [[ $0 = cdnext ]]; then ((i++)) else ((i--)) fi ((i <= $#dirs)) || i=1 ((i >= 1 ))...
Fast way to switch to next/previous directory in command line
1,619,895,044,000
This sequence of commands works OK: pngtopnm file.png 2> /dev/null > dump1 pnmfile < dump1 stdin: PPM raw, 1920 by 1080 maxval 255 ls -l dump1 -rw-r----- 1 cmb 6220817 Sep 15 14:26 dump1 But redoing the pipeline to use 'tee' truncates the output in the dump file: pngtopnm file.png 2> /dev/null | tee dump2 | pnmfile...
pngtopnm file.png 2> /dev/null | tee dump2 | pnmfile pnmfile only reads until it has enough information to output the file information and then closes the pipe. At that point tee closes the pipe and dump2 as well. Try tee -p dump2.
tee pipeline and pnmtools - truncated file
1,619,895,044,000
I am trying to make a custom command prompt that looks like this: [][][][]$, where the [] can be filled with custom information. For example, if I write in the console . file.sh 0 2 "date -R" then the command prompt looks like this [Sat, 29 Aug 2020 11:02:40 +0200][][][]$ the 0 stands for position, and 2 stands for th...
Your script currently only updates the prompt when it is explicitly sourced. If you want it to run every time the prompt refreshes, I think you need to use PROMPT_COMMAND. Try the following modified script. This will call the function set_prompt to update the prompt every time. I've also exported the commands to gener...
The values don't get updated in my custom command prompt when I hit enter
1,619,895,044,000
Okay, so I'm kinda stumped here. I'm in the midst of a deep-dive into BASH, for the purposes of writing some automation scripts for my employer. Also, full disclosure here: I'm a web guy; hitherto I've known JUST enough CLI to operate git. My issue is, about half the staff are using MacOS, the other half are using Git...
In a useful and reliable way, you probably can't. You basically need to test each command individually to see what it does. (The command "echo" is a particularly bad case of this. There are a lot of variations.) What you can do, is check version numbers and operating system. For BASH, try bash --version | head -1 ...
Is there a convenient way to test if a given flag is supported on a command?
1,619,895,044,000
I am using Debian Buster and would like to find out which process does the most writes on a specific partition, just like iotop but limited to a single block device?
iotop cannot do that because it reads processes IO counters (/proc/PID/io) which are common for all block devices, including virtual filesystems like tmpfs. What you'll need to do is block I/O tracing: https://tunnelix.com/debugging-disk-issues-with-blktrace-blkparse-btrace-and-btt-in-linux-environment/ https://www.c...
How can I see which process does the most writes on a specific partition?
1,619,895,044,000
How mount a mount point available in desktop/file manager under Removable Media category but has not ever been clicked so not been recognized from shell yet, by use of command line? Then only if this first click was done, it further can be recognized and used on shell by commands
On a systemd system you likely have udisksctl, from the udisks2 package. Quoting the udisks(8) manual: udisks provides interfaces to enumerate and perform operations on disks and storage devices. Any application (including unprivileged ones) can access the udisksd(8) daemon via the name org.freedesktop.UDisks2 on the...
mount point available in desktop Removable Media using shell command line
1,619,895,044,000
I need to transfer a particular file from my Linux PC to Android phone using a Bash script. I have already exposed my phone filesystem to the PC. With this I can easily communicate between the two using nautilus and GS Connect on PC and KDE Connect on phone. By the way my both devices are on same home network. Please ...
Finally, I got the solution using sftp. I have used the following script. #! /bin/bash #Capture and share screenshot to my phone gnome-screenshot cd /home/prm/Pictures FILE="$(ls -Art | tail -n 1)" #To get the last created file echo $FILE sftp sftp://192.168.1.3:1761/primary/DCIM/Screenshots <<EOF put "$FILE" bye EOF ...
Linux command to move file from desktop to phone on home network
1,619,895,044,000
am trying to write a bash script to get the total size of sub folders in a S3 bucket. My bucketpath s3://path1/path2/subfolders Inside the path2 folder i have many sub-folder like 2019_06 2019_07 2019_08 2019_09 2019_10 2019_11 2019_12 I need to get the size of each subfolder in a bash script. I wrote a script like #...
First of all, if you want to check if a file exist no need for exclamation mark ! since[ -e FILE ] will return True if FILE exists. But the problem is your bash script cannot check if 2019_06 existed because these files are in S3. Lines in $FILES are just strings. You can check with [ -n STRING ] which means True if t...
How to pass each line of an output file as an argument to a for loop in the same bash script?
1,619,895,044,000
I copied column 7,8 and 9 from file 1 into columns 7,8 and 9 in file 2 producing a new file 3. the produced file (file 3) is not aligned as the original files, How can I edit it to preserve the alignment ? I used the command: awk '(getline line < "file 1") > -1 {split(line,a); $7 = a[7]; $8 = a[8]; $9= a[9]} 1' file 2...
The problem is that you have either 8 or 9 data fields in file1 and 5 or 6 in file2. Either C3 9999 is one badly formatted field or C410000 should be two fields C4 and 10000. To adjust the formatting depending on the number of fields you can use two format strings and switch between them save the number of array ele...
How to solve the alignment problem of the columns in a text file after copy and paste?
1,619,895,044,000
When I use less, at times I like to have things go on for a while so I use the ESC-F sequence key which, up to here, does what I want. The only way I've found to go back to the normal less command is to use Ctrl-C. However, when I do that, it stops (Cancels) the running process. What I'm looking for is a way to return...
The correct answer is Ctrl+X. Otherwise in pipe operations like find /var/log -name "*.log" | xargs less, Ctrl+C will terminate less and exit to prompt.
How do I cancel the effect of "ESC-F" in "less" without canceling the running process?
1,619,895,044,000
If I have, for example, a column of numbers: 4 6 8 10 12 Is there a way in Vim that I could find all numbers higher than 8, than do math only with these numbers? Obtaining a new column as a result: 4 6 8 (10+2)=12 (12+2)=14
You can achieve this kind of substitution using the \= special replace expression. Check out :help sub-replace-special for all the details, but here's how this specific replacement could work: %s/\d\+/\=str2nr(submatch(0)) > 8 ? str2nr(submatch(0)) + 2 : submatch(0) In the replacement part of the :substitute command,...
How can I edit columns of numbers in vim using conditionals?
1,619,895,044,000
Computer Environment OS: Arch linux - Manjaro Shell: zsh AIM I'm trying to enable the following commands to not require a password input for my main user account: ab sudo systemctl stop NetworkManager sudo systemctl start NetworkManager FAILED ATTEMPT I've read and have tried to follow some of the online help and go...
The lines in /etc/sudoers.d/ab should probably be like this: ab ALL=(root) NOPASSWD: /bin/systemctl stop NetworkManager ab ALL=(root) NOPASSWD: /bin/systemctl start NetworkManager With sudo and normal, locally stored sudoers.d files (and nothing advanced like sudoers information stored in a LDAP server), any changes ...
Trouble trying to set no password for certain cli commands in linux
1,619,895,044,000
I've looked at a lot of bash tab completion questions and haven't yet found one that answers this one. I'm on a linux system (GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)) and normally tab completion works just fine. However, when I go to use tab completion for an environment variable or command-line ...
shopt -u progcomp disables programmable completion, i.e. scripts that may provide e.g. per-program completion. They might provide features like only completing files that match *.tar or such when the command line starts with tar, etc. Those scripts usually come with your distribution, or not, in the case of the Mac. ...
Bash tab completion not working following = character
1,619,895,044,000
On an Amazon Linux 2 instance, the command line is throwing the following connection refused error every time a command is run that references a file path. The same error is thrown when an https url is used in place of the file path. Why is this happening, and how can this problem be remediated so that the file can...
This looks like you can't connect to the Kubernetes API server. This could be for many reasons The kubernetes API server is not running The API server is not listening on TCP/8080 The API server is not listening on the loopback address of 127.0.0.1 The API server is not listening with HTTP (but with HTTPS) A local fi...
unable to recognize file. connection refused
1,619,895,044,000
I'd like to show that entering passwords via read is insecure. To embed this into a half-way realistic scenario, let's say I use the following command to prompt the user for a password and have 7z¹ create an encrypted archive from it: read -s -p "Enter password: " pass && 7z a test_file.zip test_file -p"$pass"; unset ...
What's insecure is not read(2) (the system call to read data from a file). It isn't even read(1) (the shell builtin to read a line from standard input). What's insecure is passing the password on the command line. When the user enters something that the shell reads with read, that thing is visible to the terminal and ...
Sniff password entered with read and passed as a command line argument
1,619,895,044,000
$ ls -ltr /{,usr/}bin/l*|tail -4 -r-xr-xr-x 1 root bin 31544 Dec 20 2017 /usr/bin/login -r-xr-xr-x 1 root bin 31544 Dec 20 2017 /bin/login lrwxrwxrwx 1 root root 15 Aug 28 2018 /usr/bin/libpng-config -> libpng12-config lrwxrwxrwx 1 root root 15 Aug 28 2018 /...
The braces are replaced by each of the strings between the commas, so X{,a,b}Y is expanded to XY XaY XbY, so your /{usr,/}bin/l is expanded to /usrbin/l* /bin/l*, and not /usr/bin/l* as you seem to expect. /{,usr/}bin/l* #-> /[]bin/l* /[usr/]bin/l* /{,usr,/}bin/l* #-> /[]bin/l* /[usr]bin/l* /[/]bin/l* /{usr,/}bin/l* ...
Significance of comma ',' operator, for concatenating strings in Unix
1,619,895,044,000
We want to remove the list of commands that were run in the past in the New Command window. It is the AutoFill or AutoComplete history of commands. To see them, follow these steps: Launch Terminal Open Shell menu, and click on New Command If it is empty, type something and run it. The next time you open the New Com...
If you run this command : open -a Finder ~/Library/Preferences/com.apple.Terminal.plist You'll see a CommandHistory tab where you can remove entries. If com.apple.Terminal.plist is not in above path, you can search it by : find ~ -name com.apple.Terminal.plist
On macOS, how do we remove the past commands history from Terminal > Shell > New Command?
1,619,895,044,000
I have a text files in ascii format and wanted to replace a specific value by value saved in another text file. consider a file of name text_1. . . . 50.asc 5 columns, 4 rows sample data in a file 0.40007 0.544 0.6795 0.1545 -3.4028 0.61488 0.8471 0.7444 0.3537 0.0709 0.65128 0.6651 0.7948 0.9200 0.893 0.70952 0....
With flexible GNU awk features: gawk -i inplace -v repl="Replacing_values.txt" 'FNR==1{ getline $5 < repl }1' *.asc -i inplace - allows to modify the input file(s) in-place -v repl="Replacing_values.txt" - a variable keeping the filename with replace values FNR==1 - consider only the 1st line of each input file getl...
Update specific value of one file by values in another text file
1,619,895,044,000
We have several clustered servers and need to check 1 server in each cluster. How do I compare entries in a list to return only one server in each cluster? All server names follow [a-z]-[a-z]-[a-z][0-9].domain_name Example server list. test-rac-1.domain_name test-rac-2.domain_name test-rac-3.domain_name test-rac-dg1....
You could filter all lines with grep using a regex. grep '[a-z-]1\?\.domain_name' file > newfile This returns all lines with letters or minus and an optional 1 before ".domain_name". The inverse operation would be to remove all lines containing numbers > 1 before ".domain_name": grep -v '\([2-9]\|[0-9]1\)\.domain_na...
uniq cluster name
1,619,895,044,000
I currently installed Arch Linux and I want to install the wxPython module for Spyder3. I had problems installing it with pip. Therefore, I downloaded the wxpython tarball. Here are the steps which I followed: cd Downloads sudo tar -xvzf wxPython-4.0.6.tar.gz cd wxpython-4.0.6 After that, I wanted to build the setup...
Ensure pip, setuptools, and wheel are up to date While pip alone is sufficient to install from pre-built binary archives, up to date copies of the setuptools and wheel projects are useful to ensure you can also install from source archives: python -m pip install --upgrade pip setuptools wheel "ModuleNotFoundError: No ...
Failed to build setup.py on Arch Linux
1,619,895,044,000
If I want to use the name of my primary screen (HDMI-0, found out via xrandr) within another command, the device is never found. Instead I have to use the name HEAD-0. From what I've already read I assume this is probably a nVidia-thing, but I don't understand how it works, why it's done and most importantly: How can...
Not sure if it's the correct answer, but you can query connected displays via nvidia-settings --query dpys. If I understand it correctly, HEAD-x is mapped to a display of the output of nvidia-settings in the order they appear. For example: HEAD-0 is the first connected display, HEAD-3 the fourth, etc.
How to find out, which screen is HEAD-0, HEAD-1, etc.?
1,619,895,044,000
I can use goobook to create a google contact with NAME and EMAIL but I need to add a PHONE.
I have patched goobook to accept a phone number when adding new contacts. Clone my forked repository: git clone https://gitlab.com/ardrabczyk/goobook && cd goobook Now you can follow the instructions in README.rst. In this case, as you're now installing goobook from source just do this: sudo python3 ./setup.py insta...
How to create a google contact from command line?
1,619,895,044,000
I have multiple (22) files that are named like this: chr1.out, chr2.out...,chr22.out each of those files has 46 columns and multiple lines The first 6 columns and 6 rows in one of those files looks like this: alternate_ids rsid chromosome position alleleA alleleB index rs4814683 rs4814683 NA 97...
Using a bash script: #!/bin/bash tmp_d=$(mktemp -q -d -t 'replace.XXXXX' || mktemp -q -d) for f in chr*.out; do tmp_f="${tmp_d}/$f" n="${f#chr}" n="${n%.out}" awk -v n="$n" '$3 == "NA" { $3=n }1' "$f" > "$tmp_f" mv "$tmp_f" "$f" done rm -r "$tmp_d" First we make a tmp directory as we will be cr...
How to replace all values (all NAs) in a column with numeric part of the file name?
1,555,798,757,000
I'm taking a Linux course and I have no idea on how to get past this annoying error: chcon: cannot access path: No such file or directory But before that we had to define our virtual host Perhaps maybe that's where the error resides, but I'm not sure because I've checked and retyped everything but still get the error ...
Two things: As steve (vaguely) said, you appear to be trying to change the context of directories that don’t exist yet.  You have showed us mkdir default; you need to create elm.lt.unt.edu and elm-vh.lt.unt.edu also. It looks like you actually said sudo chcon -R -t httpd_sys_content_t elm.lt.unt.edu/elm-vh.lt.unt.edu...
chcon: cannot access (file): No such file or directory
1,555,798,757,000
The following script takes a user input (path to a mounted macOS volume such as /Volumes/Macintosh\ HD/) #!/bin/bash # Author: Swasti Bhushan Deb # macOS 10.13.3 # kMDItemWhereFroms.sh read -e -p "Enter the full path to the Mounted Volume (e.g /Volume /Macintosh HD): " path var=$(mdfind -name 'kMDItemWhereFroms="*...
You can make use of mdfind's -0 option together with xargs to have the names found terminated by a NUL character (and therefore not having to worry about space/tab/newlines etc). read -e -p 'Path? ' path mdfind -0 -name 'kMDItemWhereFroms="*"' -onlyin "$path" | xargs -0 mdls If you want to see the path/file names as ...
Parsing "mdls" output
1,555,798,757,000
To find a python script, I use pgrep -af python. Is there a similar command to find node.js scripts?
You could just do: pgrep -a node This could potentially detect false positives if you have another process with node in its name. Also note this wouldn't work if the node script is using a node hashbang and was run without the node command, although I think that would also be the case for python scripts.
Show all running node.js scripts using bash
1,555,798,757,000
I want to create a cli in bash that allows a user to be able to fetch a list of database instances on our platform. I want them to be able to type in something like: $ dbinv instances show --environment=all Equally, if they want to look at the users of a specific instance called db1, they might type: $ dbinv instanc...
You may be able to use all 3 languages. I would recommend looking to see how svn, hg, git, docker do it. They will have a wrapper command: e.g. dbinv. It will look at its 1st argument, and then call a helper script. e.g. dbinv show arg1, will call «directory-containing-dbinv-commands»/dbinv-show arg1. This wrapper can...
Sub-commands in bash [closed]
1,555,798,757,000
I am using this command, find -name (file name) -ls | awk '{print $11,"\t",$5,"\t",$7,"\t",$8,$10}' to gather information of tons of files. However, some files are giving us weird numbers where date should be, if files are modified in 2018. was wondering if you have any suggestion on this to convert those numbers t...
Since you are using Linux, you can make use of the -printf argument to the find command: find -name 'pattern' -printf '%p\t\t%Tb %TY\n' Sample output: $ find -name 'file*' -printf '%p\t\t%Tb %TY\n' ./file1 Sep 2018 ./file6 Sep 2018 ./file4 Sep 2018 ./file2 Sep 2018 ./file3 Sep 2018 ./file5 Sep...
convert the dates to a standard format
1,555,798,757,000
I am supposed to use ls to find files that end in a certain letter, but it does not matter if the file has an extension or not. For example, I want it to do this > ls test test.txt test.ascii other.txt > ls [something] test test.txt test.ascii So that I can find files that end with a 't', but it doesn't include the fi...
something= |grep -e ".*t\.[^.]*" -e "^[^.]*t$"
Using ls to find files that end in a character, ignoring extension
1,555,798,757,000
I want to remove the .html file from the /home/user1/html/ directory. I have tried nearly all of the solutions posted on a myriad of other web sites. Nothing is working. user1@comp1:~/html$ sudo rm -f .html rm: cannot remove '.html': Permission denied Properties of directory: user1@comp1:~$ ls -al total 0 drwxrwxrwx...
You must run fsck on the partition where the file is. To do that you must boot in single mode and do something like fsck.ext4 /dev/yourpartdevice (or change ext4 to the partition type - and replace yourpartdevice by the partition with problem) But... "lsattr: Inappropriate ioctl for device While reading flags on .h...
Yet another `rm: cannot remove 'file': Permission denied`
1,555,798,757,000
I noticed this interesting set of commands today: $ seq 5 > alfa.txt $ awk '{print 6 > ARGV[1]} 1' alfa.txt 1 2 3 4 5 $ cat alfa.txt 6 6 6 6 6 My first question was why am I getting several 6 rather than just one, but then I remembered you need to close each time: awk '{print 6 > ARGV[1]; close(ARGV[1])} 1' alfa.txt...
At least on my system, it appears to be 32768 from a file, and 65536 from a pipe: $ yes | head -100000 | tee file > pipe $ awk '{print "n" > ARGV[1]}' file $ sed s/y/n/ pipe | awk 'BEGIN {while (getline < "-") print > ARGV[1]}' pipe $ wc -l file pipe 32768 file 65536 pipe
Awk buffer size
1,555,798,757,000
Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example: #!/bin/sh PROCESS1 & PROCESS2 & PROCESS3 & Here is the problem. I need to start these processes in the same order as show...
Based on what you're describing it sounds like there's something fundamentally wrong with PROCESS2 that's causing it to exit. If I model what you're describing with 3 processes, it mostly works as one would expect when you background the 3 processes and then capture and pass the 2nd process's PID to process 3. Example...
How to pass PID of one process to another process within the same shell script?
1,555,798,757,000
I have large tab delimited file like below ENSBTAP00000053998 GO:0005576 GO:0006952 ENSBTAP00000014280 GO:0005515 XP_010996658.1 GO:0005515 GO:0032947 ENSCAFP00000005761-D107 GO:0006826 GO:0006879 GO:0008199 XP_010987712.1-D2 GO:0004579 GO:000825...
With Awk: awk '{for(i=2;i<=NF;i++) print $1,$i}' OFS='\t' file or Perl perl -alne '$x = shift @F; print "$x\t$_" for @F' file
Split multiple column into two columns based on first column
1,555,798,757,000
is there a better way, preferably without an extra software-stack, to lock specific ssh users into a program without access to a working shell? Imagine a cli program which should be the only interface a user has access to via ssh. My hacky solution: In /etc/passwd replacing the user-shell with following script: #!/bin...
Issue at Hand You desire to lock remote users into using a specific shell when they connect to your server. As you have probably found out, chsh or other solutions are geared towards local users. Solution As per this solution by user muru, I would edit your sshd_config to use the ForceCommand option. You could use a...
Replace login shell with program (mini-jail)
1,555,798,757,000
I want to find all .mb files in multiple big folders, but I only want to return one file from each folder if there are many files matching my search criterion. folder structure .. --abc |_scenes | |__ file1.mb | |__ file2.mb |... --def |_scenes | |__ file3.mb | |__ file4.mb ...
find + awk solution: find /net/*/scenes -maxdepth 1 -type f -name "*.mb" \ | awk -F'/' '{ fn = $NF; $NF = "" }!a[$0]++{ print $0 fn }' OFS='/' -F'/' and OFS='/' - stand for input and output field separator fn = $NF - storing the last field value (i.e. a filename) into variable fn !a[$0]++{ print $0 fn } - on the 1st...
How do I return the first matched result in each folder with find command in tcsh?
1,555,798,757,000
I tried chfn to change the umask value of a user as follows sudo chfn -o umask=022 username But I have this error chfn: Office: '=' is not allowed I also tried a failed attempt to escape the = sign as follows sudo chfn -o umask\=022 username sudo chfn -o "umask=022 username" How can I use or escape the equal sign ...
chfn changes the information in the fourth field of /etc/passwd (or equivalent). Most of the data there is only used for display purposes, and it's even called the "user name or comment field" in the passwd(5) man page. Debian's man page for chfn(1) however mentions that part of it is used for "accounting information...
How do I use equal sign on chfn command?
1,555,798,757,000
When you write on the terminal 'vim filename', i know vim receives filename as a parameter but i guess that a program receives vim as a parameter too... is it just the terminal emulator or another program?
At the point at which you type vim filename on the command line, the shell has already started, so the shell (and the terminal emulator) does not get vim as a command line argument. vim, on the other hand does, but this is not available to the user. When a program is started, its name is usually given as the zeroth c...
Which program does receive command line commands?
1,555,798,757,000
For changing a specific image's size I use the following command: mogrify -geometry x50 my_image.png Every time that I take a new print screen, an image is saved on my ~/Pictures folder. I'd like to make a script that watches my Pictures folder and takes an action copying a reduced sized version of my new image to a ...
I've created this functional script that solves my problem using inotify-tools. So I'm leaving it here in case it's useful for someone else. #!/bin/bash watchedFolder=~/Pictures iconsFolder=~/.icons imageGeometry=100 while [ true ] do fileName=$(inotifywait -q -e create --format "%f" "$watchedFolder") if ! [ -...
How can I execute scripts based on changes that are happening on a specific folder?
1,555,798,757,000
Long story short, for my first thread here, I have a software RAID5 array set up as follow: 4 disk devices with a linux-RAID partition on each. Those disks are: /dev/sda1 /dev/sdb1 /dev/sdd1 /dev/sde1 /dev/md0 is the raid5 device with a ciphered LVM on it. I use cryptsetup to open the device, then vgscan and lvcan -a...
So, I managed to get a full recovery, thanks to this link What I did is as follow: I replaced the faulty disk and restarted the server. Then, I formatted the new disk as a Linux-RAID partition type. # mdadm --examine /dev/sda1 /dev/sdb1 /dev/sdd1 /dev/sde1 Then, based on the link above, I (re)created the array, ba...
MDADM - Disaster recovery or move on from the state I put my RAID5 array into
1,555,798,757,000
Suppose that I have only the following in ~/foo: . .. foo With file managers if I cut the subfolder foo and paste it into ~ it automatically replaces the contents of ~/foo with that of ~/foo/foo. But is there a native command-line tool to do so, although I can achieve the goal with a function, too?
I don’t know any way to do it in one step, but the easiest way around the problem is to remove the problem.  The fact that the two directories have the same name is a problem; so, rename one of them: mv foo foo2 && mv foo2/foo foo && rmdir foo2
How do I replace a folder with its only subfolder of the same name in CLI?
1,555,798,757,000
How can I tell if a printer is shared on the command line instead of CUPS web GUI shell (e.g., http://localhost:631/printers/HP_LaserJet_Professional_P1108).
You can find this information in the /etc/cups/printers.conf file. Use: view /etc/cups/printers.conf or less /etc/cups/printers.conf
How to know whether a printer is shared on CLI shell?
1,555,798,757,000
I use rsync -rP --rsh=ssh user@[ip]:~/datasets/ ./ to download a directory containing lots of large files from the server. I want to resume the progress when it is interrupted (by Ctrl+C or network error). But I found that when I restart rsync with the same parameters, it downloads from the very beginning, even when...
The rsync command will not resume properly because the modification times of the remote and local files differ. You may request that the modification times on the local files are set to the same timestamp as the remote files with --times (or -t), but most often one uses --archive (or -a) which implies both -r and -t a...
rsync command does not resume
1,555,798,757,000
Suppose I have a file called index.html and I want to compress it and display the compression size of it. Well I would do this... bzip2 index.html -v Now that gives me all of the data bits/bytes, percent compression ratio, and the in and out compression. Suppose I want the in number (in my case it is a 20). Well t...
bzip2 prints that information to stderr. This prevents error messages from intermingling with decompressed data when one decompresses to stdout as with bzip2 -dc or bzcat. You need to send stderr to awk. My bzip2 produces this format $ bzip2 index.html -v index.html: 1.444:1, 5.542 bits/byte, 30.73% saved, 179 ...
How do you extract certain information from bzip2 -v?
1,555,798,757,000
I have a command, # ssh -t computer.A 'command' to execute a simple command on computer.A remotely over SSH. To add to this, I want to execute a command on computer.B through computer.A.  In my head it would look like this: # ssh -t computer.A 'ssh -t computer.B 'shutdown -p now' shutdown -p now' This command would ...
You would need to escape your quotes and separate the two commands from each other. ssh -t computer.A 'ssh -t computer.B \\'shutdown -p now\\'; shutdown -p now' If you wanted the second shutdown on computer.A only to run if the first was successful, replace the ; with &&. You could also alternate the quotes like so: ...
Performing multiple operations in one SSH command
1,555,798,757,000
According to the man page: -b, --bytes=SIZE put SIZE bytes per output file -C, --line-bytes=SIZE put at most SIZE bytes of lines per output file So if -b already splits a file by bytes per file, what is the purpose of -C? How is it any different?
-C attempts to put complete lines of output into the target file, up to a maximum size of SIZE, whereas -b just counts bytes without regards to line endings. -C may put less output into the output file in order to stop at the closest line ending that doesn't put it over size.
What is the difference between split -C and split -b?
1,555,798,757,000
Is there a way that I could reference the same path from one command to the next? For example, I may want to list the contents of a specific folder: $ ls ~/Documents/some/dir Then, once I've done that, I may want to perform some action in that same directory: $ mv ~/Documents/some/dir/file.txt ~/Documents/other/dir I...
That's the insert-last-word widget which in emacs mode is bound to Alt+_ and Alt+. by default. So $ ls ~/Documents/some/dir $ ls Alt+_/file.txt Alt+_ Or you can use the $_ special variable, or csh-style history expansion (!$) if you prefer.
How can I reference the same path from one command to the next? [duplicate]
1,555,798,757,000
I have a command that takes a pid and operates on it. Works great. lsof -p 1112| wc -l But when I use the approach to pipe in the pid, that I normally use, it fails because this is a java app: lsof -p (ps -e | grep logstash) | wc -l it fails to work, because java apps do not show up by their name in ps -e, rather t...
We established two solutions: var1=`pgrep -f logstash`; ls -al /proc/$var1/fd |wc -l or, more hack, ls -al /proc/`pgrep -f logstash`/fd |wc -l Note the use of back ticks.
how to pipe PID of java app into a command?
1,555,798,757,000
I have several folders ,where each folder contain two files fastq.gz. Usually they are named as sample_R1.fastq.gz and sample_R2.fastq.gz. where sample_ can represent the folder name ,or something else. But in my case the folders are : 1008_a 2085_a 2130_a 2192_a 2221_a 2242_a 2269_a 2482_a And each of these folder co...
find + bash solution: Sample folder structure (for ex. 1080_a and 2085_a): $ tree 1008_a/ 2085_a/ 1008_a/ ├── C85CBANXX_s6_1_O07_0452_SL137634.fastq.gz └── C85CBANXX_s6_2_O07_0452_SL137634.fastq.gz 2085_a/ ├── C7V65ANXX_s6_1_M19_0413_SL131164.fastq.gz └── C7V65ANXX_s6_2_M19_0413_SL131164.fastq.gz The job: find . -ty...
Renaming files inside folders
1,555,798,757,000
I want to target all files called fooxxxbarxxx. The common thing among all those files is that it contains foo and bar. I've tried to use *foo*bar* and *foo**bar* but it doesn't work. Specifically, I'm trying to create soft links to those files, and the rest of the code already works for more straightforward executi...
In bash shell you need to use extglob option for this OR type shell expansions. shopt -s extglob nullglob and then do the globbing as ln -s /path/**/@(*foo*bar*|*bar*foo*)
How can I stack wildcards to target specific files?
1,555,798,757,000
I frequently need to do the following things in MySQL: Create a non-root user Set that user's password Grant that user all privileges Make a database with the same name as the new user Allow usage only for users from the localhost. Previously I did this using PHPmyadmin, but I would prefer doing it directly from BAS...
This works for me: echo 'create database testdb; create user "testdb"@"%" identified by "mypassword"; grant all privileges on testdb.* to testdb;' | mysql -u root -p The percentage sign indicates that connections to this database may be made from other systems. Replace the % with localhost if you only need an account...
Creating an autorized, all privileged user and an identically named DB via CLI (Bash) in one row
1,555,798,757,000
I could do: !systemctl:p to get systemctl reload bind result printed (as last command in the history starting with systemctl string). but doing the same with the partial search on the command history: !?reload:p results in zsh: no such event: reload:p the former looks the most recent event in the history that starts w...
Per the manual (emphasize mine): !?str[?] Refer to the most recent command containing str. The trailing '?' is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str. so in your case it's !?reload?:p that is, you need a trailing ? after the sea...
printing and not executing the result of zsh history expansion on partial search
1,555,798,757,000
I need to securely erase a CD without marks of intentional data loss (can't scratch or break it), so I was wondering: how could I use growisofs or dd to burn all non burned spaces in the disk to render it unreadable?
growisofs works only with DVD or BD media. dd cannot write to unformatted CD (only CD-RW but not CD-R could be formatted). A CD-R medium might be still writable (aka "appendable") on its unused area. But it cannot be blanked in any way. You may only overwrite the unused area by some harmless bytes. (Question is why yo...
Can growisofs or dd be forced to erase a CD-R?
1,499,006,042,000
I'm trying to learn some more Linux, and from experience the best way is to try to bang your head against the wall. So now that I've done a task manually a few times I would like to automate it. This involves making a oneliner to kill some tasks so I can restart them. At the moment I'm working with the following: for ...
Notice that the for loop output is broken apart at the word boundaries, viz., whitespaces/newlines. Whereas what you said you wanted is the whole line to come contained in the $i. So you need to do these 2 things: set the input field separator to a newline. disable the wildcards expansion. set -f;IFS=$'\n'; for i in ...
Scripting with 'for' and grep/egrep
1,499,006,042,000
I am kind of stuck in a tricky situation. I have a file, whose contents look like this: 3 2017-05-30 2017-09-29 2 2017-05-27 2017-08-26 1 2017-05-27 2017-08-26 Now, user selects to modify a date by choosing labelNum which would be values in column 1. Upon promp...
With single awk: awk -v lbl=$labelNum '$1 == lbl{ print $2 }' temp.txt -v lbl=$labelNum - passing in labelNum variable value into awk script $1 == lbl - if the 1st column value equal to the variable value - executes the followed expression
Grep for a specific element
1,499,006,042,000
Under Waayland I used busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode off to turn off / on the display however after having to go back to X11 due to Wayland being unusable this command works same as dpms force off. With X11 I can r...
I think you possibly misunderstand what DPMS "off" means. Look at the table in Wikipedia, what DPMS actually does is to signal the power saving state by turning the horizontal sync and vertical sync signals (or the HDMI equivalent) off, and disabling the DAC in the graphics card, while the rest of the graphics card ke...
Turn off X11 / Xorg display (not standby)
1,499,006,042,000
I have a large tab file with 15 columns (FILE1) and a list (FILE2) of names which should appear in the table. The problem is the name may appear in columns 4 to 10 in FILE1 and it may not be a case match. I want a command which searches line for a hit and then print the whole line. Preferably this would not be case s...
Answer in comments above see @Philippos and @George Vasiliou replies Briefly the answer is grep -Fwf FILE2 FILE1 > out I was having an issue whereby then I executed the command it would copy FILE1. This was occurring because of trailing blank lines in FILE2. When I removed these the command worked perfectly. As some...
extract lines from large tab delimited file using a list
1,499,006,042,000
I was testing imapsync 1.727 to sync imap from an older version of zimbra (7.1.4) to version 8.7.7 and got an error as above with command below: imapsync \ --maxsize 52428800 --buffersize 8192000 \ --nofoldersizes --nosyncacls --subscribe --syncinternaldates \ --authmech2 PLAIN \ --exclude '(?i)\b(Junk|Spam|Tr...
You can't have a line continuation that is followed by a comment on the same line. This is ok: echo \ hello This is not ok: echo \ #newline here hello In the first example, the \ escapes the newline, and the command that is executed will be echo hello. In the second case, the \ just escapes the space after it, and w...
--regextrans2: command not found
1,499,006,042,000
var $abc contains: abc jkl def mno ghi pqr var $def contains: stu vwx yz Expected output: abc jkl stu def mno vwx ghi pqr yz heemayl's solution: I tried paste <(echo "$abc") <(echo "$def") but it is giving output as below ASFSFGFGGRRFDFFFFFH 33566 AHSHDFFBORDASHFYEHFYUCH 33568 FASFSSFHJUYRT 33371 FA...
Using paste, with help from process substitution to get two file descriptors for paste to operate on: paste <(echo "$abc") <(echo "$def") Be careful with the quoting of the variables. Example: $ echo "$abc" abc jkl def mno ghi pqr $ echo "$def" stu vwx yz $ paste <(echo "$abc") <(echo "$def") abc jkl stu def mno vw...
Join multiple columns from multiple variables? [duplicate]
1,499,006,042,000
I didn't have mail installed before, so I've did it using: apt-get install mailutils After that I've tried to send a mail with this command: mail -s "Ssubjects" [email protected] But I see just this error message: cannot send message: Process exited with a non-zero status anyway I can't understand what is the probl...
Possible duplicate: mail: cannot send message: process exited with a non-zero status Try: sudo dpkg-reconfigure postfix as proposed in the answer.
'mail' use problem from command line
1,499,006,042,000
How do I show an alert in virtual console ttyX (not necessarily the active one) so that the user sees the alert on the next command invocation. I'm looking for something similar to the "you have mail" alert.
If you know which user is logged in on which virtual console, you can use write. E.g., assume user dirk is logged in on tty2, you can do echo 'You have a message' | write dirk tty2 and the user will see the message (with two additional lines). The user on the virtual console needs to enable receiving messages with me...
Alert in virtual console
1,499,006,042,000
I'm trying to compare a new file (e.g., new.txt) to an old file (e.g., old.txt) to see what was added in the new file. I'm trying to add the newly added information to a new file called newCourses.txt and the modified information to modifiedCourses.txt. If this is not possible with a diff, what are the alternatives wi...
You could use awk: awk 'NR==FNR{ z[$5]=$0; next}{ if ($5 in z){ if ($0!=z[$5]){ print >"modifiedCourses.txt"}} else { print >"newCourses.txt"}}' old.txt new.txt This reads old.txt and saves the lines into an array (the indices are the names of the courses) and then reads new.txt and for each course it checks if it's ...
Saving diffs to two files for modified and new additions