date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,455,096,620,000
I have a couple of arguments inside a list (array, e.g. $@) and I'd like to know if the option -v is in the list. In Python I would simply do: verbose = "-v" in sys.argv How do I achieve that in shell without much code?
In a shell script, you call the getopts function in a loop. There is a code example in the dash manual. Note that your Python code is not correct except in extremely simple cases. It detects an argument -v anywhere on the line, even if it's the argument of another option or after non-option arguments. The correct way...
Shell is option given
1,455,096,620,000
I trying to make control statement to check on a option flag is used or not? For -o output.file if is used I would like to make equal to variable OUTPUTSUM = OUTPUTFILE and if there no -o option use then I have it defaulted to relative path of the script? I just not sure how to go about checking for -o option? PSEUDO...
bash parameter expansion: use default value if variable is unset or null: outputsum=${outputfile:-"$scriptpath/SUMMARY"} Get out of the habit of using $ALL_CAPS_VARNAMES -- one day you'll use "PATH" and break your script.
bash control statment for when an option flag is used
1,455,096,620,000
The man page for install describes the --compare option like so: -C, --compare compare each pair of source and destination files, and in some cases, do not modify the destination at all However, there is no explanation or further reference as to what "in some cases" exactly means.
The full install manual gives more details: Compare content of source and destination files, and if there would be no change to the destination content, owner, group, permissions, and possibly SELinux context, then do not modify the destination at all. Note this option is best used in conjunction with --user, --group...
install --compare is said to, in some cases, not modify the destination at all - but in which cases?
1,455,096,620,000
About the ps command - to add one/many extra column/header with the default headers according with the option(s) used with the ps command - it through O the option. Intro If ps x is executed the output is as follows: PID TTY STAT TIME COMMAND 1677 ? Ss 0:00 /lib/systemd/systemd --user 1679 ? ...
I'd recommend not using the O option like that because it can lead to confusion because it behavior changes depending on what fields it gets and quite often it is very confusing. So you probably see ps xO psr and think that means it should sort and show the PSR (last processor used) column? It's not doing that actuall...
ps command: strange behavior with 'O' option, extra column/header does not appear as expected
1,455,096,620,000
I would like to get an option value when launching a shcell. I wrote: optstring=hcnxl: V=0 while getopts $optstring opt; do case $opt in h) V=1 ;; c) V=2 ;; n) V=3 ;; x) V=4 ;; l) V=$OPTARG ;; *) echo -e "wrong synthax" && exit 1 ;; esac done shift $((OPTIND-1)) echo :: ${OPTARG} : $OPTAR...
Change the last line to echo "$V" You don't need to shift anything, while getopts already loops over the options.
How to get option value $OPTARG correctly?
1,455,096,620,000
I have these aliases in my ~/.bashrc alias grep='grep --color=auto -H' alias fgrep='fgrep --color=auto -H' alias egrep='egrep --color=auto -H' but they have no effect when I run find ... -exec grep ..., and I always have to provide those options manually. Is there a way to tell find to rely on aliases in the -exec op...
You can't use aliases like that. Aliases work only if they're used first in a long command sequence, the shell basically replaces the alias text with the actual command. When you enter a command, the shell first searches for an alias, then a function and so on. Command substitution/alias substitution doesn't work if y...
Aliasing grep in find's -exec option
1,455,096,620,000
I am using zsh 5.4.2. The function that is causing issue is: function zp () { zparseopts -E -watch:=o_watch -show=o_show echo "show : $o_show" echo "watch : $o_watch" } Output: $ zp --show --watch "Watching" show : --show watch : --watch Watching $ zp --wat...
For comparison, I'm pretty sure that's how the GNU C function getopt_long also works, e.g. with GNU ls: $ ls --sort --foo ls: invalid argument ‘--foo’ for ‘--sort’ Valid arguments are: ... If you made the argument to --walk optional, zparseopts would take --watch --show as two arguments: In all cases, option-argumen...
If no argument is given to mandatory option, zparseopts takes next option as the argument
1,455,096,620,000
I was trying to find out what qalter's -r flag does, but I can't search for -r when viewing the man page for it (pattern not found). Yet it's clearly there. If you scroll down a bit you'll see it. Why can't I search for flags in this man page? This online version seems to work fine though.
It sometimes happens that man pages contain formatting commands and settings that lead to certain characters being rendered using various non-ASCII characters. This can be ⎪ instead of |, ­ (soft hyphen) or ‐ (hyphen) or ‑ (non-breaking hyphen) instead of - (ASCII hyphen-minus), ∗ instead of *, etc. Try searching for ...
Can't search for flags in qalter's man page?
1,455,096,620,000
The manpage for objdump states: --demangle[=style] ... The optional demangling style argument can be used to choose an appropriate demangling style for your compiler. Nowhere does it mention what possible styles are recognized by the program. Wherever I have found reference to the --demangle option in form po...
I looked on the sources and I found the solution, and also I found some misleading information on objdump: You should use objdump -H to get the list of available styles. Just running objdump give you misleading information: -H Display this information, which it is not. -H gives you much more data. In any case, on my s...
What are the possible objdump demangle styles?
1,455,096,620,000
I'm looking at an online man page for the sync command and I can't quite figure out the intended use of the -d or --data option. Is it faster? Does it have any noticeable effect? Or is it something legacy?
Many filesystems have checksums for meta data. Usual data on the other side is often not checksummed. Using sync -d is a faster operation than a complete sync and should be preferred in situations where time matters, like hanging on a fail-safe battery. sync -d also needs less IO access and thus can increase the lifes...
Could someone explain when I would use sync -d over sync with no options?
1,455,096,620,000
Is it possible to invoke some program in a Bash script with complete command line parameters (both the key and the value) stored in variables? I use the following scanimage call in a script: scanimage -p --mode "True Gray" --resolution 150 -l 0 -t 0 -x 210 -y 297 --format=png -o scan.png I want to store some of the ...
You can do this if you use an array instead of a string. Try this: options=( '--mode' "True Gray" ) scanimage -p "${options[@]}" --resolution 150 -l 0 -t 0 -x 210 -y 297 --format=png -o scan.png
Invoke a program in a Bash script with command line parameters stored in a variable
1,455,096,620,000
The Debian guide for compiling a kernel says: Do not forget to select “Kernel module loader” in “Loadable module support” (it is not selected by default). If not included, your Debian installation will experience problems. However, I have downloaded the 3.12.22 kernel, run make xconfig and searched for the “Kernel mod...
Parts of this guide are seriously out of date. “Loadable module support” is the name of the option that enables kmod, the kernel component that calls modprobe to load modules with a symbolic name based on hardware identification. You can see these symbolic names in /lib/modules/VERSION/modules.alias; they're automatic...
Debian + Linux kernel 3.12.22: “Kernel module loader” option is not available
1,455,096,620,000
Wanted to check for understanding; while revisiting the topic of using dd over netcat I experimented with compressing the data with bzip2. In the man page, there's -c (compress or decompress to standard output) and there's -z (complement to -d: forces compression, regardless of the invocation name) Is -c simply a way ...
From the man page: -d --decompress Force decompression. bzip2, bunzip2 and bzcat are really the same program, and the decision about what actions to take is done on the basis of which name is used. This flag overrides that mechanism, and forces bzip2 to decompress As this says bzip2, bunzip2 and ...
bzip2 -c versus -z
1,455,096,620,000
I found some code in one of the answers here and accommodated it to my needs but now I have two questions: Q1: how can I display the options text after the code in case statement finishes? So the user can see the options again. Q2: Can I make it so that every option is displayed on its own line when I run the script? ...
Q1: add spaces to the end of any of the options to make it longer than 40 characters, for example: options=( "quit/exit" "new rational db" "run php for rational codebase" "run php for playground codebase " ) Q2: Not sure if there is a more elegant way (didn't see in help s...
How does "options" in shell scripting work?
1,455,096,620,000
Short version: I am searching for a way to get the behaviour of the -f flag in rm when using rmdir. Long version: I am running a parallel process where every command must clean up its working directory after completion. Commands may operate in the same working directory, so rmdir -p --ignore-fail-on-non-empty works pe...
You could check if the directory exists first: [ -d "$tmpdir" ] && rmdir -p --ignore-fail-on-non-empty "$tmpdir" This could still produce errors if two jobs start to remove the directory at exactly the same time (a TOCTOU vulnerability: both test and see the directory, then both try to remove it), but that's probabl...
-f option for rmdir
1,455,096,620,000
In Linux Ubuntu about the 'tar' command for these versions: tar -tzf /path/to/filename.tar.gz # Show the content tar -xzf /path/to/filename.tar.gz # Extract the content Observe both commands use the z option, and well, they work as expected. Through man tar, about the z option, it indicates: -z, --gzip, --gunzi...
Archiving and compression are two separate things. Most archiving programs on Windows (e.g. zip, 7z, rar, and many more) combine the two into one program that does both archiving and compression - so people who are used to using Windows tend to think of them as being just one inseparable thing. While many of these pro...
Why tar command uses gzip command through 'z' option?
1,455,096,620,000
Let's say I want to search a file for a string that begins with a dash, say "-something": grep "-something" filename.txt This throws an error, however, because grep and other executables, as well as built-ins, all want to treat this as a command-line switch that they don't recognize. Is there a way to prevent this f...
For grep use -e to mark regex patterns: grep -e "-something" filename.txt For general built-ins use --, in many utilities it marks "end of options" (but not in GNU grep).
Stop executables and built-ins from interpreting a string argument starting with - as a switch? [duplicate]
1,455,096,620,000
How can I have some of the options to a unix command come from a file? That is the file does not contain all the options -- other options are specified elsewhere. For example I have the filelsoptions.txt with the following content: -F -G Now I would like to execute ls -a <and all options specified in the file lsopton...
For the trivial example listed above, ls -a $(cat lsoptions.txt)
Options to a command specified in a file
1,455,096,620,000
I've got that far: wc --files0-from=FILE lets one get the word count of a list of files. Each entry in this list mus be terminated with an ASCII NUL character. Question: A way to set a terminating character, such as NUL by hand, or something else? I found this here [quoted from the info wc output]: … produce a list ...
ls ends each filename with a newline (\n) and not a NUL (\0) (if its standard output is not a terminal). A way to list the files in the current directory, using NUL as a separator, is: find . -maxdepth 1 -print0. This will match the files starting with a period too. To ignore them, use: find . -maxdepth 1 \! -name '....
wc - setting a terminating character
1,455,096,620,000
I'd like to write a script that reads a file and passes every line as options (or "option arguments") to a command, like this: command -o "1st line" -o "2nd line" ... -o "last line" args What's the simplest way of doing this?
Here is one possibility: $ cat tmp 1st line 2nd line 3rd line 4th line $ command $(sed 's|.*|-o "&"|' tmp | tr '\n' ' ') As glennjackman points out in the comments, word splitting can be circumvented by wrapping in eval, though the security implications of doing so should be appreciated: $ eval "command $(sed 's|.*|-...
How to pass every line of a file as options to a command?
1,455,096,620,000
What is the -alhF flag in ls? I can't find it in the man page.
From man ls: -a, --all do not ignore entries starting with . -F, --classify append indicator (one of */=>@|) to entries -h, --human-readable with -l, print sizes in human readable format (e.g., 1K 234M 2G) -l use a long listing format The command ls -alhF is equivalent...
What's the -alhF flag in ls?
1,455,096,620,000
What is the difference between quotes wrap around only the option value eg: grep --file="grep pattern file.txt" * vs quotes wrap around the option name and option value eg: grep "--file=grep pattern file.txt" * ? They produce the same result.
Quotes and backslash in shells are used to remove the specialness of some characters so they be treated as ordinary characters. Double quotes are special in that they still allow expansions to take place within. Or in other words, within them $, \, and ` are still special. They also affect how those expansions are per...
What is the difference between quotes wrap around only the option value vs quotes wrap around the option name and option value?
1,455,096,620,000
About the ps command, consider if for simplicity: in tty3 is executed the yes command in tty4 is executed the yes > /dev/null command through ps I need to show in the report the complete command with options, pipes and redirection, in this case redirection, was tried ps aux and ps -ef and does not appear as expected...
You can't. At least, not without deconstructing output from ps, lsof, and a little bit of guesswork. You can use ps -ef or maybe ps -wwef to get the command with its options, but redirections and pipes are not part of a command and so will not be shown
ps command: how show the complete command with options, pipes and redirection? (or all together)
1,455,096,620,000
About the tar command Introduction Having for example: source numbers 001.txt # with the 111 content 002.txt # with the 222 content 003.txt # with the 333 content If is created the numbers.tar.gz file through the tar -czf numbers.tar.gz numbers command, therefore now we have: source numbers.tar.gz numbers ...
--keep-newer-files is useful if you want to keep changes made on the target after the source files were last modified, and replace anything older on the target with newer versions from the source. To illustrate the difference between the two options, you need another piece of information, the timestamp of each file. C...
When is mandatory use the "--keep-newer-files" option for the tar command?
1,657,201,961,000
I have a simple script to search patterns in my code sources, named prgrep #!/usr/bin/bash grep -irnI --exclude-dir={.git,obj} --exclude=tags --color=auto "$@" (The fact that it is a script and not an alias or function is that I want to be able to call it from inside vim and with any shell) Note that the search is ca...
New versions of grep have the option --no-ignore-case which overrides -i: --no-ignore-case Do not ignore case distinctions in patterns and input data. This is the default. This option is useful for passing to shell scripts that already use -i, to cancel its effects because the two options override each other. For ...
grep flag to NOT ignore case
1,657,201,961,000
I have been using the following command to install the Expo CLI package: sudo npm install expo-cli --global The command above works successfully to install that package. However, I'm wondering if moving the --global before the package name would work equally to the command above. So, doing this instead: sudo npm in...
The man page for npm(1) shows: Synopsis npm <command> [args] It doesn't say much else, so all we can deduce is that install is the <command> and must come before the [args]. The [args] are expo-cli and --global. Let's inspect the install command to see if we can get more details. npm-install(1) says: Syno...
does it matter where flag appears in a command?
1,657,201,961,000
I recently had to use this command as I got some error due to nvidia package diversion, but I don't exactly know how it is working: LC_MESSAGES=C dpkg-divert --list '*nvidia-340*' | sed -nre 's/^diversion of (.*) to .*/\1/p' | xargs -rd'\n' -n1 -- sudo dpkg-divert --remove sudo apt --fix-broken install I read about L...
LC_MESSAGES=C dpkg-divert --list '*nvidia-340*' lists all the diversions matching the glob pattern *nvidia-340*, in English so that the output is of the form “diversion of ... to ... by ...”. sed -nre 's/^diversion of (.*) to .*/\1/p' extracts the text between “diversion of” and “to”, i.e. the name of the diverted f...
What do these options on dpkg-divert and sed do as it relates to Nvidia package diversion?
1,657,201,961,000
I've summarized a list of commands that accepts symbolic link options according to SUSv4-2018ed: cd chgrp chown chmod cp find ln ls pax rm The full list also includes their defaults and other related options supported (such as -h and -d), and I stored it on my HDD for reference. I've previously seen (GNU documents i...
P and L indeed refer to the physical symbolic link itself, and the logical file the symbolic link refers to. If one goes to section A.3. subsection "symbolic link" of the Rationale volume of 2018 edition of the Single Unix Specification, all of -P -L -H are mentioned, and it says -H (for half logical) Thanks goes ...
What do letters for symlink options (-P -L -H) stand for?
1,657,201,961,000
I usually combine options together whenever there are more than one option to be used with respect to some command. For example , if i want to create an archive using tar i will write tar -cvf archive.tar file1 file2 but my doubt is that how to know the correct order in which i have to combine the options together. If...
The manual for any given command will describe exactly how to use its options. In this case, the -f option takes a filename argument. An option's argument (if it takes one) must be placed just after it. In your first tar command, this filename argument is archive.tar, but in your second it is v. The second command ...
correct order while combining different options of a command
1,657,201,961,000
I grasp the heading of this question odd, but I do wonder if in some situations there should be a need to take extra caution and somehow "enforce" non-recursivness when changing permissions with chmod nonrecursively (without the -R argument). Say I have a directory ~/x. This dir has a few files, as well as a sub-dir ~...
You can use find and restricting to get only files in the current directory find ~/x -maxdepth 1 -type f -exec chmod +x {} +
Make all files in a dir executable (non-recursively) while strictly-ensuring non-recursivness
1,657,201,961,000
I see the tutorial, when create a user: useradd -g liao1 lamp You see they place the -g liao1 before the lamp, and I tested the: useradd lamp -g liao1 I put the param after the name, I can create the user too, but I am not sure if there is distinction.
As ivanivan noted, the interpretation of the line parameters is done by the program (useradd) in your case. Many programs don't care about the order of the parameters, but some do. Eg. convert (from the imagemagick package) converts images and specifies: convert [input-option] input-file [output-option] output-file S...
Does the params and the name affect the command in Linux?
1,657,201,961,000
How do I understand what the various options/flags mean? For example: 1) uname -a - What does -a denote here? 2) pyang -f - What does -f denote here? I just want to understand if there is some reference/doc that tells the usage of these? Please clarify.
With almost all Linux commands, I think the fastest and easiest first course of action is to append "--help" to the command. This gives you a good summary, which is often enough. If you need more details, the man command is a good second choice. For example: $ uname --help Usage: uname [OPTION]... Print certain ...
What do the options after a specific command mean?
1,657,201,961,000
I'm busy setting up a back-up script to run on my Pi using rsync. I see that a number of people use the -v option in their cron jobs. Why? It's going to be run as root, and not in a terminal where someone will see it. I understand that maybe if something happens you can tail /var/logs/syslog, but the chance of that ha...
Usually, cron sends the output of the jobs it runs to the relevant user; so -v is useful there because you get an email with the full output of the rsync command. On a correctly-configured system, even mail to root goes to the appropriate user. For this to work you need mail to be setup appropriately on the system run...
Use of Verbose in a cron job
1,657,201,961,000
I have one txt file called sales.txt Fred apples 20 April 4 Susy oranges 5 April 7 Mark watermelons 12 April 10 Terry peaches 7 April 15 And when i use this command: [root@ip-10-0-7-125 bash-tut]# cat sales.txt | cat /dev/stdin | cut -d' ' -f 2,3 | sort 20 April oranges 5 peaches 7 watermelons 12 The point is if i ...
The man page on my system says: -d, --delimiter=DELIM use DELIM instead of TAB for field delimiter So if you don't specify -d, cut assumes that your fields are separated by TAB characters. Your input file contains no TAB characters. Meanwhile, the man page also says: -f, --fields=LIST sele...
Why do i need -d option on this cut command?
1,657,201,961,000
On an NFS server, the shares are typically set up in /etc/export, where mount options like rw, root_squash, sync etc. can be set. When mounting the NFS share on the client side, again mount options can be specified. How do these two (possibly opposite) ways to set the options relate to each other? Do the options on on...
The mount options on the NFS client can be more restrictive than those on the server but not the opposite. For example, if a share is exported read/write the client can choose to mount read-only. However, if a share is exported read-only then the client gets read-only no matter how it tries to mount it.
NFS server mount options vs. client mount options
1,657,201,961,000
I know that is not a exciting question, but yet I don't understand why some programs needs program -h and other program --help sometimes is very boring recognize it
In practice, programs should have both options. The -h is the "short form" and --help is "long form". Short form command options are usually one or two characters while long form options are more descriptive (such as yum update -y and yum update --assume-yes meaning "assume yes to all questions"). Programs that don't...
why some programs needs -h and other no
1,657,201,961,000
If in Ubuntu Server is executed: curl https://services.gradle.org/distributions/gradle-7.5.1-bin.zip -O appears: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --...
Apparently there is some problem with your DNS resolution in the ubuntu Server Try to set an other DNS server like 8.8.8.8 or 1.1.1.1 See the contents of /etc/resolv.conf and set nameserver 8.8.8.8 update: After fixing the issue with DNS , add -L option to curl which allows it to "follow redirects" The problem here wa...
curl: (6) Could not resolve host: services.gradle.org
1,657,201,961,000
I read this question Get SSH server key fingerprint In the answer and solution appears the following command (adapted here for presentation purposes) ssh-keyscan 192.168.1.X | ssh-keygen -lf - I know that the first command isolated shows the public keys of the host. When the complete command is executed - thus the ...
By default, ssh-keygen -l will ask you interactively for what public key file to show the fingerprint of. With -f you give it the pathname of some existing file instead. If the pathname is - (a dash), input is read from standard input instead of from a file. This is a common practice that quite a few other commands a...
How does "-" work in the "ssh-keygen -lf -" command?
1,657,201,961,000
Please consider the prior discussion as background to this new question. I have modified my script and applied the same filesystem options to my USB drive's ext4 partitions using tune2fs, and mount options specified in the fstab. Those options are all the same as for the previous discussion. I have applied those chan...
Some ext4 filesystem options may not take effect if specified in /etc/fstab as they require changes to filesystem structures. Some of those can be simply applied with tune2fs while the filesystem is unmounted, but there are some options that may require running a full filesystem check after tune2fs to take effect prop...
EXT4 on USB - how to specify journalling behaviour to be same as for root disk partitions
1,657,201,961,000
About the less and according with: Less command Linux / Unix Colored Man Pages With less Command indicates the following: f ^F ^V SPACE * Forward one window (or N lines). b ^B ESC-v * Backward one window (or N lines). z * Forward one window (and set window to N). w * Backward one window (and set window to N). En...
I'll try my best to explain with an example. Open a long text file with less, something with obvious lines. Now type 4z, and you will see that 4 lines have shifted down. Type z and another 4 lines have moved. That 4z has told less that you want the window size to be set to 4. Once you have set the window size, all opt...
less command: b/f vs w/s
1,657,201,961,000
Through the ps --help all command about the option(s) related with tty exists the following: -a all with tty, except session leaders a all with tty, including other users x processes without controlling ttys I know the difference between tty[1-6] and pts/[0....
pts is used for any UNIX 98 pseudoterminal, not only remote connections. You’ll see it used for graphical terminal emulators, screen or tmux sessions, etc. You mentioned tty[1-6], tty can also be a prefix for pseudoterminals, when BSD pseudoterminals are used; you’ll then see ttyp0 etc. It is also used as a prefix for...
ps command: How generate the report of processes but according with only either tty or pts?
1,657,201,961,000
I am using a bash script to call rsync commands. Have decided to collect some options in an array called oser. The idea is to look at what's different in the two invocations and put that into the array, instead of putting all of the common options into the array. Now I would like to add the --backup possibility to r...
How about this: # "always" options: you can put any whitespace in the array definition oser=( -av --progress --log-file="$logfl" ) # note the `+=` below to _append_ to the array (( filetr_dryrun == 1 )) && oser+=( --dry-run ) # now, `oser` contains all the options rsync "${oser[@]}" "$source" "$destin...
Adding options using bash arrays
1,657,201,961,000
The man page for txt2html says: --make_links Should we try to build links? If this is false, then the links dictionaries are not consulted and only structural text-to-HTML conversion is done. (default: true) I want to set this to false. How do I do this? I could not find this informatio...
The txt2html manual also says Boolean options can be negated by preceding them with no [...] The manual then refers to the Perl package Getopt::Long. In its manual, one may read the following about boolean options: The option does not take an argument and may be negated by prefixing it with no or no-. [...] This ...
How to specify boolean value in argument to external command?
1,657,201,961,000
came across this line in a code base today ln -fs /tmp/Cargo.lock . and I couldn't find the -fs argument anywhere in man ln. What does it do? P.S. The project runs this command inside of a docker container I tried this command on my local machine too by making a file in the same directory path as the given command and...
Standard Unix tools, and tools using the standard way of parsing command line options, allow for combining multiple single letter options into a single string of options (as long as the individual options don't take option-arguments)1. Because of the way the -f and -s options to the ln utility are defined (as options ...
What does the -fs flag do in the ln command?
1,657,201,961,000
It used to be that you could force command line FTP to use IPv4 like so: ftp -4 ftp.example.com However, at some point in the relatively recent past the "-4" (and for that matter, the "-6") option seems to have been removed. Despite exhaustively searching the Web (even for the exact error "ftp: 4: unknown option") I c...
-4 and -6 are options added by a patch in the Debian version of netkit-ftp; you’ll find these available in any Debian derivative. Fedora, RHEL and CentOS don’t have an equivalent patch, so their ftp doesn’t support these options. To force IPv4, you could try specifying the target IP address rather than the host name.
What happened to the "-4" option for command line FTP?
1,657,201,961,000
Could you please explain what each option on this ls command does: ls -td -- */? The result of such command would look like below: $ ls $ ls -al total 4 drwxr-xr-x 5 root root 68 Jun 4 09:58 . drwxrwxrwt. 13 root root 4096 Jun 4 10:05 .. drwxr-xr-x 5 root root 36 May 31 15:48 05-31-2018 drwxr-xr-x 5 root r...
-td is the two options -t and -d written together. -t tells ls to sort the output based on time, and -d asks to show directories named on the command line as themselves, instead of their contents. The -- option is as far as I know not explicitly documented for many commands that do support it and it has become a sligh...
What is -- and -td options on ls command?
1,657,201,961,000
I am writing a shell script that takes several args like -l -s -a -f thing ming and append only those starting with -. This is my code: arrayOfArgs=() for arg in "$@": do case arg in -*) arrayofArgs+=($args) ;; esac done Now my arrayOfArgs print this -l, -s, -a, -f. The thing I am worried about is t...
Rather than trying to solve the question you've asked, this answer offers a solution that attempts to solve the underlying issue. For this example I've assumed that arguments a and s are booleans (switches) but argument l takes a parameter: unset -v flagA flagS valueL while getopts "al:s" OPT do case "$OPT" in ...
passing options from an array to built in ls command in UNIX [closed]
1,657,201,961,000
If you type help set, then - among other things - a list of shell options is displayed. But these options are not the same as those displayed with shopt. And different also from those displayed with set and env. Is there a command which displays options such as errexit and braceexpand and their current values? Also, w...
Use set -o: $ set -o allexport off braceexpand on emacs on errexit off errtrace off functrace off hashall on histexpand on history on ignoreeof off interactive-comments on keyword off monitor on noclobber off noexec o...
Is there a command which displays options like `errexit` and `braceexpand` other than `help set`?
1,657,201,961,000
I have SerNet Samba 4.0.9 installed on CentOS 6.4. How can I tell if it was compiled with CUPS support?
The docs, which say they're valid for Samba 3 and 4, say: "...make sure, that your smbd is compiled with CUPS support:" # smbd -b | grep CUPS HAVE_CUPS_CUPS_H HAVE_CUPS_LANGUAGE_H HAVE_CUPS HAVE_LIBCUPS
Does SerNet compile Samba 4 with CUPS support? (How to tell in general?)
1,657,201,961,000
I would like either of these inputs to work. That is, the -n option itself is optional – I already know how to do that – but it then may have an optional parameter on top. If no parameter is given, a fallback value will be applied. command -n 100 command -n I can only make the former input type work or the latter, bu...
Not sensibly with Bash's/POSIX getopts, but you could do it with the "enhanced" getopt (without an s) from util-linux or Busybox. (And those only, in particular many "traditional" getopt implementations are broken wrt. whitespace also) The man page says of getopts: optstring contains the option characters to be recog...
Can you make a bash script's option arguments be optional?
1,389,384,877,000
Is there some way of saving all the terminal output to a file with a command? I'm not talking about redirection command > file.txt Not the history history > file.txt, I need the full terminal text Not with hotkeys ! Something like terminal_text > file.txt
You can use script. It will basically save everything printed on the terminal in that script session. From man script: script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file ca...
Save all the terminal output to a file
1,389,384,877,000
There are tools providing coloured output: dwdiff -c File1 File2 # word level diff grep --color=always # we all know this guy ... The question is: How to convert their colored output of arbitrary program into coloured html file? Other output formats might be suitable as well (LaTeX would be great). I think html is go...
The answer to this question is probably what you want. It links to these tools, which do the conversion you're looking for: Perl package HTML::FromANSI aha, a C-language program (github repo)
Converting colored output into html
1,389,384,877,000
Currently I have a shell script which logs messages to a log file like this: log_file="/some/dir/log_file.log" echo "some text" >> $log_file do_some_command echo "more text" >> $log_file do_other_command When executing this script, there is no output to screen, and, since I'm connecting to the server via putty, I hav...
This works: command | tee -a "$log_file" tee saves input to a file (use -a to append rather than overwrite), and copies the input to standard output as well. Because the command can detect that it's now being run in a non-interactive fashion this may change its behaviour. The most common side effect is that it disabl...
how to output text to both screen and file inside a shell script?
1,389,384,877,000
I have a simple bash function dividing two numbers: echo "750/12.5" | bc I'd like to take the output from bc and append /24 and pipe said result to another instance of bc. Something like: echo "750/12.5" | bc | echo $1 + "/24" | bc Where $1 is the piped result. P.S. I realize I could just do echo "750/12.5/24" | bc ...
In the simplest of the options, this does append to the pipe stream: $ echo "750/12.5" | { bc; echo "/24"; } 60 /24 However that has an unexpected newline, to avoid that you need to either use tr: $ echo "750/12.5" | { bc | tr -d '\n' ; echo "/24"; } 60/24 Or, given the fact that a command expansion removes trailing...
Append to a pipe and pass on?
1,389,384,877,000
Mail logs are incredibly difficult to read. How could I output a blank line between each line printed on the command line? For example, say I'm grep-ing the log. That way, multiple wrapped lines aren't being confused.
sed G # option: g G Copy/append hold space to pattern space. G is not often used, but is nice for this purpose. sed maintains two buffer spaces: the “pattern space” and the “hold space”. The lines processed by sed usually flow through the pattern space as various commands operate on its contents (s///, p, etc.); ...
How do I add newlines between lines printed on the command line?
1,389,384,877,000
I have a command which outputs lots of data (say, strace with lots of syscalls, running for a few minutes). Is there any option (e.g. command wrapper or something similar) that would allow me to pause the output of the command (just the output on the screen, I don't mind the command running in the background), then un...
You have three options: press controlS to stop output, controlQ to resume (this is called XON/XOFF) redirect your output to a pager such as less, e.g., strace date | less redirect your output to a file, e.g., strace -o foo date, and browse it later.
Pausing terminal output
1,389,384,877,000
I often use find or locate to find out about paths. (~) locate foobar.mmpz /home/progo/lmms/projects/foobar.mmpz The next step is often to open or otherwise manipulate the files. In a happy case like above, I can do this: (~) ls `!!` ls `locate foobar.mmpz` /home/progo/lmms/projects/foobar.mmpz But nobody's too happ...
There is no feature to capture the output from the screen on most terminal emulators. I seem to recall the author of xterm (the “reference” terminal emulator) stating that it would be difficult to implement. Even if that was possible, the shell would have to keep track of where the last prompt had been. So you won't e...
Can zsh access the stdout of last run program?
1,389,384,877,000
I have a bash script that calls various commands and prints some output (both from the called commands themselves, such as git pull, and informative messages generated by the script itself such as Operation took XX minutes. I'd like to capture the whole output to a file from the script itself: basically I'm trying to...
A method I found to capture all output from any session is to start a new bash session and tee to a log file. its really useful for tracking more then just a script. bash | tee ~/bash.log #this will save standard output until the bash session is ended bash 2>&1 | tee ~/bash.log #this will save all output including er...
Capture all the output of a script to a file (from the script itself) [duplicate]
1,389,384,877,000
INPUT_FILE=`ls -rt $MY_DIR/FILE.*.xml | head -1 | xargs basename` I wanted to execute the second command (head -1) only if the first command is successful. How do I improve this command?
Try this: INPUT_FILE=`ls -rt "$MY_DIR"/FILE.*.xml | head -1 | xargs -r basename` Passing xargs the -r flag will cause it to only run basename if reads at least one item from standard input (head -1). head -1 will run but you won't see or capture any output from it. Also, if you don't want the user to see any error ou...
Pipe the output of a command if it is successful
1,389,384,877,000
There are many questions on SE that show how to recover from terminal broken by cat /dev/urandom. For those that are unfamiliar with this issue - here what it is about: You execute cat /dev/urandom or equivalent (for example, cat binary_file.dat). Garbage is printed. That would be okay... except your terminal continu...
No: there is no standard way to "disable it", and the details of breakage are actually terminal-specific, but there are some commonly-implemented features for which you can get misbehavior. For commonly-implemented features, look to the VT100-style alternate character set, which is activated by ^N and ^O (enable/dis...
How to prevent random console output from breaking the terminal?
1,389,384,877,000
Say I run some processes: #!/usr/bin/env bash foo & bar & baz & wait; I run the above script like so: foobarbaz | cat as far as I can tell, when any of the processes write to stdout/stderr, their output never interleaves - each line of stdio seems to be atomic. How does that work? What utility controls how each li...
They do interleave! You only tried short output bursts, which remain unsplit, but in practice it's hard to guarantee that any particular output remains unsplit. Output buffering It depends how the programs buffer their output. The stdio library that most programs use when they're writing uses buffers to make output mo...
What prevents stdout/stderr from interleaving?
1,389,384,877,000
I have 2 exactly same formatted, same size and same brand SD-cards. I would like to dd image to /dev/disk2 and to /dev/disk3 at the same time. Pseudocode sudo dd bs=1m if=/Users/masi/2016-05-10-raspbian-jessie.img of={/dev/disk2,/dev/disk3} How can you dd from one input to many output SDs?
Borrowing from don_crissti's answer using tee, but without dd or bashisms: sudo tee /dev/disk2 /dev/disk3 > /dev/disk4 < masi.img Using pee from Debian's moreutils package: sudo dd if=masi.img | \ pee "dd of=/dev/disk2" "dd of=/dev/disk3" "dd of=/dev/disk4" With bash, ksh, or zsh, that can be abbreviated to: s...
dd: write to multiple disks?
1,389,384,877,000
I am a relative Linux novice. I am trying to learn how to use at so that I can schedule tasks to begin at a later time, without using sleep. I have been looking at this previous question for help. My question is, in the following sample bash script that I have created, why is "Running" never -- as far as I can tell ...
Because at does not execute commands in the context of your logged in user session. The idea is that you can schedule a command to run at an arbitrary time, then log out and the system will take care of running the command at the specified time. Note that the manual page for at(1) specifically says (my emphasis): The...
Why does this 'at' command not print to the standard output?
1,389,384,877,000
Say I have a Zsh script and that I would like to let it print output to STDOUT, but also copy (dump) its output to a file in disk. Moreover, the script starts with the following option set -o xtrace which forces it to be verbose and print what commands it runs. I would like to capture this output as well in a file in...
It could be that your script is producing output to stdout and stderr, and you are only getting one of those streams output to your log file. ./my_script.sh | tee log.txt will indeed output everything to the terminal, but will only dump stdout to the logfile. ./my_script.sh > log.txt 2>&1 will do the opposite, dumpin...
Send copy of a script's output to a file
1,389,384,877,000
Where does standard output from at and cron tasks go, given there is no screen to display to? It's not appearing in the directory the jobs were started from, nor in my home directory. How could I actually figure this out given that I don't know how to debug or trace a background job?
From the cron man page: When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslo...
Where does the output of `at` and `cron` jobs go?
1,389,384,877,000
I'm tailing a log file using tail -f messages.log and this is part of the output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eget tellus sit amet odio porttitor rhoncus. Donec consequat diam sit amet tellus viverra pellentesque. tail: messages.log: file truncated Suspendisse at risus id neque p...
That message is output on stderr like all warning and error messages. You can either drop all the error output: tail -f file 2> /dev/null Or to filter out only the error messages that contain truncate: { tail -f file 2>&1 >&3 3>&- | grep -v truncated >&2 3>&-;} 3>&1 That means however that you lose the exit status o...
Suppress 'file truncated' messages when using tail
1,389,384,877,000
Suppose this situation wget http://file wget starts to download file. I put it in the background. ^Z bg The command goes into the background. But its output is still on the console also -- if the console is still open. Is it possible to stop the command's output? Wget is only an example; think about a command which...
Here's a solution that actually redirects the output of a command while it is running: https://superuser.com/questions/732503/redirect-stdout-stderr-of-a-background-job-from-console-to-a-log-file For a solution that is more usable in an every-day scenario of using a terminal, you could do wget -o log http://file & to ...
Is it possible to stop output from a command after bg?
1,389,384,877,000
I'm trying to write a simple script to monitor my network status, without all of ping's output: ping -q -c 1 google.com > /dev/null && echo online || echo offline The problem is that when I'm not connected, I'm still getting an error message in my output: ping: unknown host google.com offline How can I keep this err...
When you run: ping -q -c 1 google.com > /dev/null && echo online || echo offline You are essentially only redirecting the output of Stream 1 (i.e. stdout) to /dev/null. This is fine when you want to redirect the output that is produced by the normal execution of a program. However, in case you also wish to redirect t...
How to redirect the output of any command?
1,389,384,877,000
I have a script like this one at my .bashrc file at the mysuer home: eval `ssh-agent` ssh-add /path/to/my/key The problem is I have this output when I log with the user mysuer (su - myuser): Agent pid 1234 Identity added: /path/to/my/key (/path/to/my/key) I would like avoid this, silence this output, but load the ss...
As usual? { eval `ssh-agent`; ssh-add /path/to/my/key; } &>/dev/null
How can I silence ssh-agent?
1,389,384,877,000
When a process breaks, as I know no output will be return anymore. But always after breaking ping command we have the statistics of the execution, and as I know it's part of the output. amirreza@time:~$ ping 4.2.2.4 PING 4.2.2.4 (4.2.2.4) 56(84) bytes of data. 64 bytes from 4.2.2.4: icmp_seq=1 ttl=51 time=95.8 ms 64 b...
Ctrl+C makes the terminal send SIGINT to the foreground process group. A process that receives SIGINT can do anything, it can even ignore the signal. A common reaction to SIGINT is to exit gracefully, i.e. after cleaning up etc. Your ping is simply designed to print statistics upon SIGINT and then to exit. Other tools...
Why is there output of ping after it has been terminated?
1,389,384,877,000
My file consists of the the following; roughly: username:username:username:username:username The above line continues to about 600 characters. I use the awk command in order to use it as an argument in a API/HTTP request sent from the command line. I'm using my script to get a list of user accounts 'following' me,...
The utility you're looking for is diff. Take a peek at the manual for details.
How can I output the difference between 2 files?
1,389,384,877,000
I figure curl would do the job. I wrote in a script: #!/bin/sh function test { res=`curl -I $1 | grep HTTP/1.1 | awk {'print $2'}` if [ $res -ne 200 ] then echo "Error $res on $1" fi } test mysite.com test google.com The problem here is no matter what I do I can't get it to stop printing t...
-s/--silent Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute. So your res should look like res=`curl -s -I $1 | grep HTTP/1.1 | awk {'print $2'}` Result is Error 301 on google.com, for example.
How do I get (only) the http status of a site in a shell script?
1,389,384,877,000
How can we concatenate results from stdout (or stderr) and a file into a final file. For example ls -a | grep text1 concatenate with file2.txt into a final result (not file2.txt), without storing grep text1 to something intermediate such as grep text1 > file1.txt
ls -a | grep text1 | cat file2.txt - The - stands for standard input. Alternatively you may write ls -a | grep text1 | cat - file2.txt to have the output in different order. Yet another possibility using process substitution: cat <(ls -a | grep text1) file2.txt or in different order: cat file2.txt <(ls -a | grep t...
Concatenate contents from stdout and from file
1,389,384,877,000
I know that GNU Parallel buffers std/stderr because it doesn't want jobs output to be mangled, but if I run my jobs with parallel do_something ::: task_1 task_2 task_3, is there anyway for task_1's output to be displayed immediately, then after task_1 finishes, task_2's up to its current output, etc. If Parallel canno...
From version 20160422 you can do: parallel -k --lb do_something ::: task_1 task_2 task_3
GNU Parallel: immediately display job stderr/stdout one-at-a-time by jobs order
1,389,384,877,000
I want to capture to a file the output of the ls command ls >> lsOutput.log This one works if executed in the command line. But when put inside a shell script (lsOutput.sh), returns ./lsOutput.sh: 3: ./lsOutput.sh: total: not found lsOutput.sh code #!/bin/sh `ls -lrt` >> lsOutput.log
Just remove the backticks from your script: #!/bin/sh ls -lrt >> lsOutput.log Otherwise, the command is executed, and then its output is substituted and executed. For example: echo date will output: date, while `echo date` will output current date, i.e. it will first evaluate to date, and then executed, which is c...
LS Command output to file [closed]
1,389,384,877,000
I like to use set -x in scripts to show what's going on, especially if the script is going to run in a CI/CD pipeline and I might need to debug some failure post-hoc. One annoyance with doing this is that if I want to echo some text to the user (e.g., a status message or "I'm starting to do $X") then that message gets...
This is a horrible kluge, and I feel dirty for suggesting it, but... you could do this with a magic alias. The key to this trick is that aliases are expanded as part of the parsing phase of command execution, so set -x won't make anything print as they expand (unlike a function). So you can make an alias that prepends...
Temporarily unset bash option -x
1,389,384,877,000
I know we can use below format to redirect the screen output to a file: $ your_program > /tmp/output.txt However when I used below command, it says "-bash: /home/user/errors.txt: Permission denied" sudo tail /var/log/apache2/error.log > ~/errors.txt May I know how to make this output works? The ~/errors.txt doesn't ...
Behind the pipe, the sudo doesn't work. I don't know why you can't write to your home - maybe the file belongs to root? sudo tail /var/log/apache2/error.log | sudo tee ~/errors.txt Maybe you need a different user behind the pipe. For sure, you don't need a preexisting file.
tail program output to file in Linux
1,389,384,877,000
Sometimes it is really handy to just add set -x to the top of your script to show all commands before they are executed. There is only one drawback creating scripts with a decent output: I don't know how to add text output to the script this way. If I use echo 'some comment' it will result in printing it doubled: + ...
One hacky way is just to write your comments as arguments to a no-op command. Particularly useful might be the : null utility: set -x : Some interesting notes on the following are ... results in: + : Some interesting notes on the following are... The colon command does nothing, accepts whatever arguments you give it...
Adding comments using 'set -x'
1,389,384,877,000
I'm having some troubles on Ubuntu 14.04 initialization, it fails to mount an SSH folder and gives me the option of a manual recovery by pressing M, displaying a command-line logged at root user for debugging the problem. My troubles start when I try to read the sshfs help file and it is bigger than the screen, theref...
People usually use a pager like less to read such a long output: sshfs -h | less On less type H to show help. Q to quit. Note that you might occasionally need 2>&1 to see also additional output from stderr. For sshfs -h it has such an output so you'd better do that like this: sshfs -h 2>&1 | less Besides using a p...
Bash output command too large, can't read it!
1,389,384,877,000
I write a lot of non-interactive scripts where I would like all output to go to a log file and have nothing appear on-screen. To solve this, I've been using: #!/bin/bash exec &> logfile echo "Step One:" /some/command/one echo "Step Two:" /some/command/two I want to make sure this is a sane method. Are there any si...
Redirection of command output to a log file Redirecting all command output (including error messages) to a log file is standard practice for non-interactive shell scripts.   It’s particularly useful to have a record of command output for scripts that are run by cron or triggered by some other external event, and there...
exec redirects in bash
1,389,384,877,000
I have a Perl script on a *nix system which, at one point, is processing 50,000 + lines of text. This takes some time. I am trying to find a resource friendly way to let the user know the program is not hanging while it is processing all of this text. Currently I am printing output in realtime as the text is being pr...
[I just realized your script is perl, but the same logic applies, print "\r", etc. You will want to use STDERR or else turn off buffering, $| = 1. See bottom.] One way of implementing a CLI "progress indicator" involves the use of the \r (carriage return) character. This brings the cursor to the beginning of the cu...
Resource friendly way to indicate to user program is not hanging
1,389,384,877,000
How to save output of a command that modifies environment into a variable? I'm using bash shell. Assume that I have: function f () { a=3; b=4 ; echo "`date`: $a $b"; } And now, I can use commands to run f: $ a=0; b=0; f; echo $a; echo $b; echo $c Sat Jun 28 21:27:08 CEST 2014: 3 4 3 4 but I would like to save output...
If you're using Bash 4 or later, you can use coprocesses: function f () { a=3; b=4 ; echo "`date`: $a $b"; } coproc cat f >&${COPROC[1]} exec {COPROC[1]}>&- read c <&${COPROC[0]} echo a $a echo b $b echo c $c will output a 3 b 4 c Sun Jun 29 10:08:15 NZST 2014: 3 4 coproc creates a new process running a given comma...
Save output of command that modifies environment into a variable
1,389,384,877,000
I use the following to send an email at the end of a script. echo "Script finished on `date`" | /usr/bin/Mail -s "Script complete" "[email protected]". However, I want to echo the same message onto the screen as well. How do I do that in the same statement?
The easiest way is probably to tee the message to stderr as well as stdout: echo "Script finished on date" | tee /dev/stderr \ | /usr/bin/Mail -s "Script complete" "[email protected]" tee duplicates its input to multiple destinations, including stdout. By default, both stderr and stdout go to the screen; you're r...
How to send output to both screen and mail?
1,389,384,877,000
In a bash script, I must download a file from the web. I use the wget command for doing this. I would like to log the output of the wget command, and at "the same time" have the output prompting on terminal. I searched in the man wget without finding the way to achieve that. It seems that if you turn on the log with -...
You use the lovely tee command to do this: wget --no-check-certificate --auth-no-challenge --http-user=$jen_uname --http-password=$jen_psswd 2>&1 | tee -a wget_log THe 2>&1 means that STDERR goes to the same place as STDOUT, and they're both piped to tee. The -a means append. tee will then send the output both to wge...
wget a file, logging the output and showing the output on prompt
1,389,384,877,000
I have some output from iconv, e.g. $ iconv -l | grep ISO | head -5 CSISO4UNITEDKINGDOM// CSISO10SWEDISH// CSISO11SWEDISHFORNAMES// CSISO14JISC6220RO// CSISO15ITALIAN// durrantm:~ How can I change the //'s to, say --'s ? I tried $ (iconv -l | grep ISO).gsub('\/\/','--') but no luck.
There are a few approaches using either tr, awk or sed TR: iconv -l | grep ISO |head -5 |tr '/' '-' AWK: iconv -l | awk '/ISO/{gsub("//","--"); print $0}' |head -5 SED: iconv -l | grep ISO |head -5 | sed 's/\//-/g' # or, to avoid needing to escape the backslashes: iconv -l | grep ISO |head -5 | sed 's#/#-#g'
How to grep, then search and replace on the output?
1,389,384,877,000
I'm trying to run a command, write that to a file, and then I'm using that file for something else. The gist of what I need is: myAPICommand.exe parameters > myFile.txt The problem is that myAPICommand.exe fails a lot. I attempt to fix some of the problems and rerun, but I get hit with "cannot overwrite existing file...
You must have "noclobber" set, check the following example: $ echo 1 > 1 # create file $ cat 1 1 $ echo 2 > 1 # overwrite file $ cat 1 2 $ set -o noclobber $ echo 3 > 1 # file is now protected from accidental overwrite bash: 1: cannot overwrite existing file $ cat 1 2 $ echo 3 >| 1 # temporary allow overwrite $ ca...
How can I output a command to a file, without getting a blank file on error?
1,389,384,877,000
If I follow a file somehow like this: tail -f /var/log/syslog|grep s I see all lines containing an "s" Why does this not give any output, if I grep it again to the same "s"? tail -f /var/log/syslog|grep s|grep s
As Rubo77 mentioned, the issue is solved by adding the --line-buffered to the first grep command: tail -f /var/log/syslog|grep --line-buffered s|grep s However, you then may ask, why isn't this needed for a single grep command? The difference between the two is that in the following command: tail -f /var/log/syslo...
double grep on tail -f gives no output
1,389,384,877,000
I've tried to get a file from airodump-ng via redirecting a output stream via: airodump-ng mon0 2>&1 | tee file.txt but this appends to a file rather than rewrites it. So after that I've tried to redirect an output to other output stream via a fifo pipeline: First terminal: mkfifo fifo1 echo "while [ 1 ]; do cat ~/f...
Check man airodump-ng. You want the -w option. airodump-ng -w myOutput --output-format csv mon0 Generates a .csv file of the screendump with the output from airodump-ng one line per station.
How to save an output of airodump-ng to a file?
1,389,384,877,000
I'm trying to hide the "output" of a gnupg command, but it seems that it is always printed. the command is: echo "thisprogramwørks" | gpg -q --status-fd 1 --no-use-agent --sign --local-user D30BDF86 --passphrase-fd 0 --output /dev/null It is a command to verify the password of pgp keys, and by using it like this: a=$...
The "problem" is, that gpg writes directly to the TTY instead of STDOUT or STDERR. That means it cannot be redirected. You can either use the --batch option as daniel suggested, but as a more general approach you can use the script tool, which fakes a TTY. Any output is then sent to STDOUT, so you can redirect it to /...
Silent GnuPG password request with bash commands
1,389,384,877,000
I'm asked to output the current day using the cal command. So far, I discovered that before the current date there is a _ symbol. I decided to use grep here: cal | grep '\b_*', but it outputs the whole week. I've tried several variants, but it didn't work out. Actually, there is also a case, when current day has only...
When the output of the cal command is not a terminal, it applies poor man's underlining to the day number for today, which consists of putting an underscore and a backspace character before each character to underline. You can see that by displaying the characters visually (^H means control-H, which is the backspace c...
Output current day using cal
1,389,384,877,000
Is it true to say that CTRL+D stops input execution while CTRL+C stops output displaying (as plain data, without execution)?
No, it is not true. However, it is true to say that Ctrl+D signals an End of Transmission (EOT) event which will generally cause a program reading input to close the input file descriptor. Ctrl+D is used for this because its place on the ASCII table corresponds to the analogous End of File control character, even thou...
CTRL+D vs CTRL+C
1,389,384,877,000
Let's assume I receive the following output after executing a bash script in CLI (so this text will be displayed in terminal): POST https://mycompany.com/ COOKIE='BLABLABLABLABLA' HOST='ANYIPADDRESS' FINGERPRINT='sha256:BLABLABLABLA' How can I store the content of COOKIE (only the text between ' and ') into a separa...
These types of thing are not generic in nature, but specific though approach is generic I am assuming, you want to replace OpenConnect.Cookie = line with OpenConnect.Cookie = BLABLABLABLABLA So, to first create required string , you can use sed -i "s/^OpenConnect.Cookie =.*$/$( command_giving_output | grep 'COOKIE...
Bash: How to store a specific line of CLI output into a file?
1,389,384,877,000
Suppose I have an environment where there isn't a shell running, so I can't use redirection, pipes, here-documents or other shell-isms, but I can launch a command (through execvp or some similar way). I want to write an arbitrary string to a named file. Is there a standard command that will do something like: somec...
If you know of any other non-empty file on the system, then with POSIX sed: sed -e 's/.*/hello world/' -e 'wtarget' -e q otherfile With GNU sed and just your own non-empty file, you can use: sed -i.bak -e '$ihello world' -e 'd' foo With BSD sed, this would work instead: sed -i.bak -e '$i\ hello world' -e d foo If y...
Write string to a file without a shell [closed]
1,501,772,142,000
I am trying to interpret this result of hdparm: janus@behemoth ~ $ sudo hdparm -Tt --direct /dev/nvme0n1 /dev/nvme0n1: Timing O_DIRECT cached reads: 2548 MB in 2.00 seconds = 1273.69 MB/sec Timing O_DIRECT disk reads: 4188 MB in 3.00 seconds = 1395.36 MB/sec I do not understand how the cached reads can be slo...
Per hdparm man page: --direct Use the kernel´s "O_DIRECT" flag when performing a -t timing test. This bypasses the page cache, causing the reads to go directly from the drive into hdparm's buffers, using so-called "raw" I/O. In many cases, this can produce results that appear much faster than the usual p...
Why cached reads are slower than disk reads in hdparm --direct?
1,501,772,142,000
Is it possible to restart a systemd service when there is no output generated for a predefined amount of time? I have a script which apparently can hang, but that is not detected by systemd (or Python for that case), and thus it does not enter the failed state. However, it does stop logging output, so I should be ab...
I don't think systemd allows you to do that, at least the systemd.service(5) manual page doesn't seem to mention anything like that. However, what you could do is use systemd's builtin watchdog. You would do that by setting WatchdogSec= and then having your service send WATCHDOG=1 with sd_notify regularly. If you set ...
Restart systemd service when output is no longer generated
1,501,772,142,000
Say I only need the first 5 lines of an output for logging purposes. I also need to know if and when the log has been truncated. I am trying to use head to do the job, the seq command below outputs 20 lines that get truncated by head, and I echo a truncating information: > seq -f 'log line %.0f' 20 | head -n 5 && ech...
A note of warning: When you do: cmd | head and if the output is truncated, that could cause cmd to be killed by a SIGPIPE, if it writes more lines after head has exited. If it's not what you want, if you want cmd to keep running afterwards, even if its output is discarded, you'd need to read but discard the remaining...
Truncate output after X lines and print message if and only if output was truncated
1,501,772,142,000
How do I evaluate or calculate the return value of a command line? For exemple, I count the number of lines with a grep and I want to know if that value is above X. If so, I want to print the number to a file. Or I want to substract the value of a grep count to another grep count... How can I manipulate return values ...
I think you are mixing two things the return value typically indicates if a command was successful (return value 0) or not (anything else). You can get the return value of a command from the variable $? grep -c returns the count to stdout, to capture the count you can use something like variable=$(grep -c pattern file...
Evaluating the return value of a command line
1,501,772,142,000
I am on elementaryOS 0.4.1 Loki, which is based on Ubuntu 16.04.1. I want to use OBS, a screen recorder, to record gameplay along with the sounds that come from the same video game. I also want to use a voice chat application in the background while playing the game, but I do not want any of it recorded by OBS. OBS c...
Let me repeat: A single program or group of programs A (game) should output sound both to OBS and the headphone, while another single program or group of programs B (voice chat) should only output sound to the headphone, all on the Pulseaudio level. Correct? Don't use snd-dummy, it works on the ALSA level. Instead, cr...
How to create a virtual audio output and route it in Ubuntu-based distro
1,501,772,142,000
On RHEL/CentOS the package manager dnf can search for strings in the names and summaries of packages. How can I tell it to list only matches in the name (or in name and summary), but not in the summary only?
DNF unfortunately doesn't have an option to search only in the package name, there is an old RFE for this feature, but there was no activity since 2015. You can try using dnf list which can show both installed and available packages and supports glob expressions so it can be potentially used for searching by name only...
How to tell "dnf search" to list only matches in the package name (or name and summary), but not only in the summary?
1,501,772,142,000
I am writing a shell script to start my network in my virtual machine on boot, since it does not do this right away for some reason with a snapshot of a virtual machine. Since the eth device starts as being down, I have to get that device name with the following script and then start the device as well: gateway=ifconf...
You must use command substitution, otherwise, bash will think you assigned ifconfig result to variable gateway then run command -a: gateway=$(ifconfig -a | awk '/eth/ {print $1}') dhclient $gateway
ifconfig -a in a shell script