date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,543,536,286,000
I had to use the following command in an assignment: who|tee test|wc -l The output on my system is below, which implies that 2 users are connected: 2 Why is it I don't get the output of who on the screen, and right after that the output of wc -l? I thought tee wrote the output to the screen and created a file with t...
The effect of piping to tee is that whatever your first command writes to its standard output is written to a file (whose name you passed as a command-line argument to tee) as well as written to the standard output of the tee command. If the pipeline doesn't continue and you don't perform any redirections on the tee c...
Strange output when using tee in pipe command
1,543,536,286,000
I am downloading a couple of thousand files listed in a file using: wget -i filename Sometimes it encounters the following error reported by the server for a particular file: HTTP request sent, awaiting response... 500 Internal Server Error The problem is that wget then hangs. What I want for it to skip that file a...
Try using wget --tries=1 --waitretry=1 -i filename. This will try only once after a failure and only wait one second before doing so. It's also possible the server is not closing the socket after sending the 500 error. In this case, adding --read-timeout=30 will timeout the connection after 30 seconds of no data fr...
Prevent `wget` hanging when it encounters error 500
1,543,536,286,000
I'm trying to detect if a package is installed in a bash script using the following but the script keeps erroring out and preventing anything after it from running. Is there an option for apt that tells it to NOT throw an error when a package is not in the list? pkgExists=$(apt list "azure-cli" | grep "azure-cli" -s)...
If a package is not in the list, apt list just shows Listing... Done and exits. If you try to pipe its output like you do however it throws a clear warning: WARNING: apt does not have a stable CLI interface. Use with caution in scripts. Use dpkg-query --list instead, e.g.: dpkg-query --list "azure-cli" && echo "exis...
Prevent apt list from throwing error [duplicate]
1,543,536,286,000
I am using these commands in Linux Kali but I keep getting an error when I run the second command: "No such file or directory found." end=7gb read start _ < <(du -bcm kali-linux-1.0.8.amd64.iso | tail -1); echo $start parted /dev/sdb mkpart primary $start $end These are some commands out of a larger set of commands I...
read start _ This assigns the first word (according to $IFS) of the input line to the variable start. du -bcm kali-linux-1.0.8.amd64.iso | tail -1 is a strange way for getting the size of the file, rounded up to the next megabyte. parted /dev/sdb mkpart primary $start $end creates a partition on sdb which begins af...
What does these commands do?
1,543,536,286,000
To clarify the intent of my question, let me make an analogy to the question "What is the simplest way to put data into a file?" The usual way that GUI users will put data into a (new) file is to double click on a program icon, click the menu bar, click "new," click "save," click to choose a location for the file, typ...
I'll assume that the two users and their two computers are independent, e.g. that user A can't simply access user B's computer and write files into the filesystem. That means that the minimal config is one where A can connect to the MTA on B's machine, and the MTA considers itself responsible for email to B's machine/...
What is the simplest way to email between two computers?
1,543,536,286,000
I came across the notion of primaries from running man find: . . . PRIMARIES All primaries which take a numeric argument allow the number to be preceded by a plus sign (``+'') or a minus sign (``-''). A preceding plus sign means ``more than n'', a pre- ceding minus sign means ``less than n'' and neither mea...
They're the conditions/actions of find's language, the ones that the "expression" referred to in the usage line mainly consists of: -name, -type, -print, -exec etc. The term is used to separate them from the operators that only combine the primaries: !, -a, -o and the parenthesis. I don't remember seeing that term u...
What are command primaries?
1,543,536,286,000
I looked into the integrated manual of the xargs command, where the -I option is explained. And though I read the few lines repeatedly, I can not make any sense of it: -I replace-str Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, un‐ ...
Here is a quick pair of examples of xargs -I in action: $ echo foo bar baz | xargs -I quux echo quux foo bar baz $ echo -e "foo\nbar\nbaz" | xargs -I quux echo quux foo bar baz -I means "Replace this marker with the newline-separated items coming in from standard input".
what is the purpose of the -I option of the xargs command? [duplicate]
1,543,536,286,000
I recently switched from OSX to Linux for my personal use. I have a home media server running headless Ubuntu, and now a laptop running Mint. My habit is to move things to the server with scp. In the past, on OSX, when I typed to copy target I would painstakingly type each character of the path, because if out of habi...
This is your shell’s command completion in action: it “knows” that when the current command-line starts with scp, in certain contexts it needs to connect to the target system (if it can) to complete paths there. This can be done transparently because you’ve loaded your key. You’ll see this typically implemented in /us...
scp aware of target machine path?
1,543,536,286,000
In what way does the final value of number being assigned by read var number (and we enter 5) and number=5 differ? I was making this for loop: read var number #number=5 factorial=1 i=1 for i in `seq 1 $number` do let factorial=factorial*i done echo $factorial when I noticed that if the number has the value a...
If you change the first line to read number you’ll get the behaviour you’re looking for. read var number reads two values and stores them in variables named var and number. If you only input one value, seq 1 $number expands to seq 1 which is just 1.
For with read value
1,543,536,286,000
It's for a bash script. Basically, I want to format, or erase a USB (or SD) storage device; with a single command line. I was going to use fdisk, but it seems to require user interaction where I want automation. So then I decided to try zeroing it out with: dd if=/dev/zero of=/dev/<target disk>; but it only seems ...
If you want to use fdisk, with only one partition, with all blocks used, this will suffice: echo -e "n\np\n1\n\n\nw\n"| fdisk /dev/<target disk> && mkfs.ext4 /dev/<target disk> Change mkfs.ext4 to whatever filesystem type you want it to use. If you just want to delete data, your dd command should be fine.
What's the quickest way to format a disk?
1,543,536,286,000
What's the best way to trim the massive disclaimer from the end of the whois output? It looks something like this: >>> Last update of WHOIS database: 2017-01-30T20:17:39Z <<< For more information on Whois status codes, please visit https://icann.org/epp Access to Public Interest Registry WHOIS information is provi...
From the manual page: -H Do not display the legal disclaimers some registries like to show you. So.. whois -H domain.example.com?
How to trim the WHOIS disclaimer?
1,543,536,286,000
When I run into errors I sometimes get errors in my language set by locale. Is there a way besides switching locale to force English error messages for the sake of googling the solution?
Locale settings are how most programs decide what language to use. While a few programs have a different setting, the most common way to select the language of messages is through locales. There's no other way that works across more than one application (or family of related applications). You don't need to set any sy...
Is there a way to force program to output errors in English?
1,543,536,286,000
I knew how to set up a command in $PATH, but I need someone refresh my mind. In fact, I have the '.sh' script /home/jeremie/Downloads/pycharm-community-2016.3.2/bin/pycharm.sh that I want to put in $PATH. My purpose is to be able to use pycharm as a command. I figure out that the first step is export PATH = $PATH:Down...
The PATH is a list of colon (:) separated directories where the shell will search to find the file you're calling. Therefore you would need to add /home/jeremie/Downloads/pycharm-community-2016.3.2/bin to it and not include the file itself. If you want to change the name from pycharm.sh to pycharm, you would either r...
The PyCharm command
1,543,536,286,000
The following find-exec(mv) command finds a directory named say prog-3.6.9-stable-gnu and changes its name sucessfully. Yet, the command also returns: find: './prog': No such file or directory This is the command: find ./ -type d -name 'prog-*' -exec mv {} prog \; I get a similar result when find-exec(rm) that dir:...
The error appears because you are moving a folder "prog-*". The actual behaviour of find is: find analyzes first the directory itself, and then its contents. So, find, in your example: 1. finds the directory prog-3.6.9-stable-gnu 2. renames it in prog (so now has a new name) 3. tries to access prog-3.6.9-stabl...
find exec mv finds an inode (dir), changes dir's name, but returns "No such file or directory"
1,543,536,286,000
I have directory scalable for vector icon theme and I have bunch of symlinks in there which I want to replace by a file that contain names that I can use with ln command, I've create the file it contain lines that look like this: scalable/actions/messagebox_warning.svg scalable/emblems/emblem-danger.svg scalable/emble...
Assuming your file is in the right order (target, then link name), and that no filename contains special characters or spaces: sed 's/^/ln -sf /g' < src/symlinks | sh will transform your list of symlinks into a series of ln -sf commands and run it using sh.
How to create symlinks from file
1,482,553,843,000
Sometimes when I log on to a system via SSH (for example to the same server), I have such privileges that there can install some software, but to do that I need to know how package management software is in the system. Is there a way to quickly find it out? In particular, for me uname -a returns: Linux cloud 2.6.32-27...
Well, the easiest way (at least to me) would be to simply check which package manager is installed. It is not a wild guess to assume you are either using apt or yum (Debian based or Red Hat based package managers). So, if you try: which apt /usr/bin/apt You see that apt is installed. If you try: which yum <no output>...
How can I find information about the package management software in the linux (unix) systems, in particular in cloud?
1,482,553,843,000
I have a file in which I want to change all of the code that has the following format : n{,3}L{,2}n{,5} where n= [0-9] any number and L [a-zA-Z] any letter either capital or not I want to change A or a into AB and d or D into DK, something like this: Annnnn--> ABnnnnn ; Dnnn-->DKnnn the file looks like: $ cat file...
As for what's wrong with your script, you are replacing A or a with AB and D or d with DK, so any pre-existing B or K would not be affected; sed is not looking for it. You could put an optional [bB] or [kK] using ? (zero or one of the preceding character) to make it replace that character too if it occurs. To make sur...
How to substitute some letters in a multi-length word consisting of digits and letters in a specific format?
1,482,553,843,000
I got the following command: curl -H 'Content-Type: application/json' -X POST -d '{"host": "'$(hostname)'"}' http://sitename.com/update.php Which works as expected, but if I try to send uptime output instead of hostname I get: curl: (6) Could not resolve host: 19:12; Name or service not known curl: (6) Could not res...
Using one type of quote is more simple and solves that issue; curl -H "Content-Type: application/json" -X POST -d "{\"uptime\": \"$(uptime)\"}" "http://sitename.com/update.php" or you can use 2 quote types but it's less elegant; curl -H 'Content-Type: application/json' -X POST -d '{"uptime": "'"$(uptime)"'"}' 'http:/...
How to POST 'shell output' as JSON data with Curl
1,482,553,843,000
I have a directory with subdirectories and files structured like this: 01/fileA 01/fileB 01/fileC 02/fileD 02/fileE 03/fileF 03/fileG 03/fileH 04/fileI I'd like to get a CSV that looks like this: 01, fileA, fileB, fileC 02, fileD, fileE 03, fileF, fileG, fileH 04, fileI In other words, I want to generate a CSV with ...
That can be done in a number of ways. One simple method could be this for d in * do echo -n "$d, " ls -m $d done
Find all files, create CSV with one row per subdirectory and file names in collumns
1,482,553,843,000
I have a binary sequence like 0011000111000111. I put this in a file abc.txt. I want to test its randomness using rngtest. I am getting as follows: /Documents$ rngtest <abc.txt> bash: syntax error near unexpected token `newline' Please help me. I am getting this after using rngtest <abc.txt. Is it random? rngt...
Remove the ">" after the .txt. rngtest < abc.txt
Randomness test using rngtest
1,482,553,843,000
When i run this find command: find /html/car_images/inventory/ -type f -iname \*.jpg -mtime -4 i get output like this: /html/car_images/inventory/16031/16031_06.jpg /html/car_images/inventory/16117/16117_01.jpg /html/car_images/inventory/16126/16126_01.jpg /html/car_images/inventory/16115/16115_01.jpg /html/car_image...
Assuming you don't have filenames with newline(s): find /html/car_images/inventory/ -type f -iname \*.jpg -mtime -4 \ -exec sh -c 'echo "${1%/*}"' _ {} \; | sort -u | \ xargs -d $'\n' -I{} rm -r {}/thumbnails The parameter expansion, ${1%/*} extracts the portion without the filename from each found en...
Use output from find command to then remove a specific directory
1,482,553,843,000
This command on ubuntu is giving no such file or directory error: /# mv mongodb-linux-x86_64-$VERSION mongodb mv: cannot stat 'mongodb-linux-x86_64-2.6.7': No such file or directory even though both file and directory exist. Any idea why? Thanks edit /# ls mongodb-linux-x86_64-* mongodb mongodb: mongodb-linux-x86_6...
The file (directory) name you have is mongodb-linux-x86_64-2.6.2-rc0, not mongodb-linux-x86_64-2.6.7. The variable VERSION is being expanded to 2.6.7, but the desired expansion as far as your directory name is concerned would be 2.6.2-rc0. So you need to either define variable as such, and do the mv-ing: VERSION='2.6....
No such file or directory when moving a file
1,482,553,843,000
I am trying to follow this answer on OS X 11.x block return from any to 192.0.2.2 The console displays : -bash: block: command not found So, I tried to install it using brew: brew install block However, I got another error . How to install this firewall utility?
On recent versions of OS X, pf is installed and running by default. The linked question is referring to changing the pf configuration, not installing a new utility. Modifying a firewall on a production system is not something which should be done without reading the documentation (man pf.conf , man pfctl). To add th...
block command line not found
1,482,553,843,000
According to this question, which said "How to run a command multiple times?", the correct answer was for i in `seq 10`; do command; done Now, If the command has an argument and every iteration, we should pass this argument to the command automatically. How can we perform this in Linux terminal? thanks.
With the loop you reference in your command, you are storing the next "word" from the seq command in the variable i. You can use that value anywhere you like, so to pass it to the command you can invoke it as command "$i" You can avoid the need for the extra seq process with bash at least you can do it like for ((i=1...
How can we change a multiple running command line arguments in Linux terminal?
1,482,553,843,000
How can I modify the pattern in the second instruction, so as to exclude nested directories? (such that ls returns only foo.mp4, not the content of bar:). $ ls * foo.mp4 foo.ogg bar: bar.ogg $ shopt -s extglob $ ls !(*.ogg) foo.mp4 bar: bar.ogg PS: I use OS X.
What was I thinking?! $ ls *.!(ogg) foo.mp4
Look for files in the current directory that don't match a pattern
1,482,553,843,000
Can anyone explain what the significant of the '@' symbol in the following command date -d @1472067906.1413 +%Y.%m.%d 2016.08.25 How does the date command handle this; I can't seem to find any information on man page.
Your best hint in the man page is indeed in one of the examples – @x means x seconds past the epoch: EXAMPLES Convert seconds since the epoch (1970-01-01 UTC) to a date $ date --date='@2147483647' (I assume there could otherwise be parsing ambiguities if you wanted something like 7 seconds past the ep...
Purpose of '@' in Unix Date command (for epoch)
1,482,553,843,000
How can I find out the number of visitors in real time in my website? I'd like to access to it via SSH, so it should be some CLI programs. In the worst case scenario I was thinking to analyse the number of IPs in the Apache/Nginx access file for a range of the last 5 min or so.
Most web statistics tools summarise the log over a period of 24 hours or a month. The simplest cli ncurses-based one is goaccess. For an instant view of your apache server current cpu usage and threads there is server-status which you could retrieve via curl, in html. See a live demo (beware large file). Nginx has a...
How can I see the number of visitors in my website via CLI
1,482,553,843,000
I am new to bash. When I run the following command: grep "type" /root/myFile | cut-d'=' -f2 I get the following: 102 304 503 442 I want to store the contents of the first command into a variable such that the content of the variable would be the equivalent of declaring it like this: myVariable="102 304 503 442" I ...
myVariable=`grep "type" /root/myFile | cut-d'=' -f2` What is between back-ticks (`) is run and the output is assigned to myVariable. If your current output is separated by line feeds (\n), then you may want to replace them with spaces with tr such as: myVariable=`grep "type" /root/myFile | cut-d'=' -f2`|tr '\n' ' '` ...
Generating strings of words with space delimiters from cut statement
1,482,553,843,000
I need to list all mount points associates to external storage devices such as USB keyfobs and SATA external drives. The only way I found under Ubuntu, is to call 'mount' and grep for '/media'. But I wonder if there is a better, more universal way. All this from the command line interface (terminal/bash).
Looking in /media is a reasonable way to find hotplug block devices. You can also use lsblk to list the block devices and whether they are hotpluggable: $ lsblk -l -p -o name,rm,hotplug,mountpoint NAME RM HOTPLUG MOUNTPOINT /dev/sda 0 0 /dev/sda1 0 0 / /dev/sda2 0 0 [SWAP] /dev/sda3 0 ...
List of mount points of external storage devices such as USB keyfobs and SATA external drives, from the cli
1,482,553,843,000
How shell processes the content of command line in order to execute? Command first and then option and arguments. Dividing command line into segments. Processes from beginning to the end.
"shell" is a generic word for bash, ksh, zsh and all. For all those shells, there is a man page (e.g. man bash) which details how command is expanded before execution (variable $foo are replaced by content, fu* in replaced by fun funny (provided thoses files exixts) and the like). You can debug simple command using ec...
How shell processes the content of command line in order to execute?
1,482,553,843,000
I have list in the file called name.txt with these strings: Los Angeles, CA us1.vpn.goldenfrog.com Washington, DC us2.vpn.goldenfrog.com Austin, TX us3.vpn.goldenfrog.com Miami, FL us4.vpn.goldenfrog.com New York City, NY us5.vpn.goldenfrog.com Chicago, IL us6.vpn.goldenfrog.com San Francisco, CA us7.vpn.golde...
If you want a sed solution: sed 's/.*[[:blank:]]\([^[:blank:]]*\)$/\1/' file.txt The captured group (\1) will contain the portion of the line after last space, we are using that in the replacement. Example: % sed 's/.*[[:blank:]]\([^[:blank:]]*\)$/\1/' file.txt us1.vpn.goldenfrog.com us2.vpn.goldenfrog.com us3.vpn....
Remove start of lines with sed
1,482,553,843,000
I have the following log: 2016/01/20 00:00:16.035 [T114BaseServlet] ... Blah Blah Blah 2016/01/20 00:00:16.036 [ApplicationState] ... Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 2016/01/20 00:00:29.531 [T114BaseRequestPayloadParser] ... Blah Blah Blah 2016/01/20 00:00:36.036 [Applicatio...
To remove the whole block of lines beginning with one including your match up to the line occurring immediately previous to the next occurrence of [T1114Base you can do the following: sed -e'$!N;/ApplicationState.*\n/,/\n.*\[T1114Base/!P;D' <in >out It is fairly simple to understand how this works. By default sed eat...
How do I remove text blocks within a log file? [closed]
1,482,553,843,000
let's say the command is "ls word1 word2 word3" I want to move the cursor from end of line to "word2" but do not want to clear "word3" in process. Just jump back by two words and reach beginning of "word2" is there any keyboard shortcut to jump word backward and forward without deleting the word on command line?
When tcsh's line editor is configured in emacs mode (which is the default, use bindkey -e to go back to it if you had enabled vi mode earlier): % bindkey | grep word | egrep 'for|back' "^[^H" -> backward-delete-word "^[B" -> backward-word "^[F" -> forward-word "^[b" -> backward-word ...
how to move by a word in command line in tcsh?
1,482,553,843,000
I have multiple files ( about 20 files with 30000 lines and 32 columns) and I need to keep only the lines that start with the same string. I found these cases that are quite similar to what I need but I don't know how to adapt them.. compare multiple files(more than two) with two different columns how to compare valu...
One approach would be to first find all sets of 12 initial characters that are present in more than one file: cut -c-12 file* | sort | uniq -c The cut command above prints the 1st 12 characters from every file whose name starts with file, these are then sorted and the number of times each line is found is appended by...
Compare columns between different files
1,482,553,843,000
I'm trying to use a custom PS1 line, including colors and git repo information, on a Red Hat Enterprise Linux 6 machine. I have a predefined version I'm successfully using on other systems running Ubuntu or Mint. In my .bashrc, I added the following part at the bottom: # Colors Black='\e[0;30m' # Black Red='\e[...
The problem is this line in your ${COMPANYHOME_ROOT}/bashrc_company file: export PROMPT_COMMAND='PS1=`echo "\u@\h$PS2"`' The PROMPT_COMMAND variable defines a command that should be run before a prompt is shown. In your case, this has been set to setting PS1. So, each time a prompt is shown, your PS1 is being reset t...
PS1 from .bashrc overridden somewhere else
1,482,553,843,000
I have a tab delimited file: qrs John tuv abcd Sam efgh ijk Sam lmnp abcd Sam efgh ijk Sam lmnp qrs John tuv I am trying to print the line in which the second field does not match the previous line's value in the second field and to print the line in which the second field ...
From you comment, I assume it's a log file with login and logout dates, for example: date1 John logout date2 Sam login date3 Sam work1 date4 Sam work2 date5 Sam logout date6 John login Use awk: awk 'NR!=1&&$2!=f{print p"\n"$0} {f=$2; p=$0}' file Where: NR!=1 is true when awk proces...
Print the first and last match of a field with awk
1,482,553,843,000
in one of my shell program, I want start an xterm window from terminal and then the control of next execution should go to the newly opened window (by default the control will be in the terminal). How to do this using command line arguments (not by moving mouse pointer to the new window :) ) ?
If you want to open a new xterm and run a sequence of commands in that window, you can use the -e option. If you want the xterm to remain open after the command is executed, you can include the -hold option. For example: xterm -hold -e 'pwd; ls'
linux terminal transfer control to new terminal [closed]
1,482,553,843,000
I had a problem on my DNS and after using this magical command, solved the problem. So I got curious: how this command, dns-fix, worked? I am using the Mint distribution. The command is standard.
The Mint dns-fix command (from searching) appears to be a simple shell script that changes /etc/resolv.conf to use a few pre-defined nameservers. You can confirm by using a file viewer to examine the script; e.g., less "$(command -v dns-fix)".
How the command "dns-fix" works?
1,482,553,843,000
I have two tmp files named tmp1 and tmp2 which contains some lines. tmp1 file, 1c\ datafile no. 23 2c\ datafile is ok tmp2 file, 3c\ datafile no. 24 4c\ datafile is ok I have a file (named wrong_file) which entries I want to correct from tmp files datafile no. 32 datafile is ok datafile no. 42...
I'm pretty sure you can just do: cat ./tmp[12] | sed -f - ./wrong_file >outfile At least, that will not cause any issues if all of sed's script instructions are specific to line number. There's no need to apply the scripts separately - you can chain them all together and run the script at once. That you have to do th...
How to write data one by one from tmp files to the final output file using for loop?
1,482,553,843,000
When I am running in the GUI, if I run the pass command to read a password such as pass -c Email/FooBar, a password prompt will appear for my passphrase. If I type my password, my password will be copied into the clipboard. If I subsequently run the pass command to read a different password without logging out and log...
The difference in experience between using pass in a console (what you call a virtual terminal) and within a (GUI) terminal has nothing to do with pass, but with the secret key management done for gpg (as used in the pass scripts) by the gpg-agent. This gpg-agent is, in modern distributions automatically started with...
How can I cache the PGP unlock for unix pass when I am in the virtual terminal?
1,482,553,843,000
I would like to have an alias for the following code:- g++ *.cc -o * `pkg-config gtkmm-3.0 --cflags --libs`; but I want that when I enter the alias it should be followed by the file name *.cc and then the name of the compiled program *. for example: gtkmm simple.cc simple should run g++ simple.cc -o simple `pkg-c...
What you need isn't an alias, but a function. Aliases do not support parameters in the way you want to. It would end just appending the files, gtkmm simple.cc simple would end like: g++ -o `pkg-config gtkmm-3.0 --cflags --libs` simple.cc simple and that's not what you try to achieve. Instead a function allows you to:...
Aliasing a command with special parameters [duplicate]
1,482,553,843,000
I want to change the elementary tweak themes and hot-corner settings on my Elementary Luna (built on Ubuntu 12.04 "Precise") from the commandline. With what command can I do this? I know how to make the changes from the GUI. Is there a way to capture settings made that way to feed into the commandline command?
There is a partial answer here: The command to use is 'gsettings` and the actual settings to use you can find by using: dconf watch / in the terminal, while you adjust the settings. You get a bunch of statements like this: /org/gnome/desktop/wm/preferences/theme 'elementary' /org/pantheon/desktop/gala/behavior/hot...
Changing themes and hot-corner settings from command-line
1,482,553,843,000
I am trying to write up a command line interfaces that will removes a particular section / lines of codes within a list of json files. By the way, the json file are located within the sub-folders of the main directory I am pretty new to this but this is the code that I can come up with so far - find -name "*.json" | x...
First of all, change True to true. As a whole, this works very well: #!/usr/bin/python import sys import json inputfile = sys.argv[1] with open(inputfile,'r') as myfile: obj = json.loads(myfile.read().replace('True','true')) if "map" in obj: del obj["map"] json.dump(obj,sys.stdout,indent=4,separat...
Removing multiple lines
1,482,553,843,000
the below command when I run from the terminal will keep posting the output to message.log cf logs broker-analytics > /var/www/cfbrokerlogs/message.log However, if i close my terminal it will stop working. How do i make it run in the background all the time ? Also If for any reason if it stops execution what would a ...
You could use nohup combined with &: nohup cf logs broker-analytics > /var/www/cfbrokerlogs/message.log & The nohup command causes the program to ignore hangup signals (i.e. those that are sent when closing the terminal), and the & of course runs it in the background. If you want to make sure it's still running or ki...
How to run a command in background always?
1,482,553,843,000
I'm using a Google Drive command-line script that can return a list of files such as: Id Title Size Created 0Bxxxxxxxxxxxxxxxxxxxxxxxxxx backup-2014-12-26.tar.bz2 569 MB 2014-12-26 18:23:32 I want to purge files older than 15 days. How can I execute the foll...
You can apparently use the Google api to list and sort the files to your needs specifically (from drive --help): list: -m, --max Max results -q, --query Query (see https://developers.google.com/drive/search-parameters) ...and from the link... Search for files modified after June 4th 2012 modifie...
Extract lines with specific dates and execute a command on each of them
1,482,553,843,000
I have a DELL server R610, on this server there is a RHEL 6.4 This server has an idrac entreprise. I would like to configure the idrac from command line, avoiding reboot. I read on the man page of ipmitool that I can use a command like : #ipmitool lan set 1 mode dedicated but the command return man page : usage: l...
Up until a few years ago, ipmitool was undergoing rapid development. On some Linux distributions from around that time, the man page may not describe all the commands supported by the executable. In your case, setting Dell DRAC and iDRAC parameters is supported by ipmitool 1.8.11, and is done using the ipmitool delloe...
ipmitool set idrac mode
1,482,553,843,000
I'm developing a custom embedded barebones distro. I have console access over serial to my machine. I would like to control what tty my user sees on their framebuffer. Currently the machine boots and sits at the splash screen while my program writes things to tty0. The user has to press Alt+[F1..F10] to get to the des...
NAME chvt - change foreground virtual terminal SYNOPSIS chvt N DESCRIPTION The command chvt N makes /dev/ttyN the foreground terminal. (The corresponding screen is created if it did not exist yet. To get rid of unused VTs, use deallocvt(1).) The key combination (Ctrl-)LeftAlt-FN (with N in the range 1-12) usual...
Is there a console command that replicates Alt+[F1..F10] to change terminal?
1,482,553,843,000
I have a daemon daemon running in Server A. There, there's an argument based script to control the daemon daemon_adm.py (Server A). Through this script I can insert "messages" to daemon coming from user input. Free text, whatever you like it to be. Then, there's a web interface in Server B for daemon_adm.py in PHP usi...
To insert a string in a shell snippet and arrange for the shell to interpret the string literally, there are two relatively simple approaches: Surround the string with single quotes, and replace each single quote ' by the 4-character string '\''. Prefix each ASCII punctuation character with \ (you may prefix other ch...
Securely passing user input to command
1,405,003,621,000
Here's the script. It is successful when I run it from the BASH prompt, but not in the script. Any ideas? When I say "fails," I mean the sed regex doesn't match anything, so there is no replaced text. When I run it on the command line, it matches. Also, I might have an answer to this. It has to do with my grep alias...
I was actually able to figure this out, and I figure I'd add it here for the next googler who bangs their head against the same wall. I had a grep alias and GREP_OPTIONS set. This caused color highlighting to remain on in the script, even when piping to another command. That usually doesn't play nicely with sed. Here'...
Why does the same sed regex (after grep) fail when run in a bash script vs bash command line?
1,405,003,621,000
Let's say there's a specific time and date I have in mind. All files last edited before this date I want to keep in the directory but all files that have been edited since this date I want to mv somewhere else. The man page of mv doesn't show this being possible with mv directly. I thought some form of the the foll...
find /path/to/dir -mtime +5 -exec mv {} /target/path/ ';' will move all files in /path/to/dir that are older than five days to /target/path. You can try this to see what will actually be executed: find /path/to/dir -mtime +5 -exec echo mv {} /target/path/ ';' Note that the -mtime parameter checks the file's modifica...
With mv, possible to put a time dependence on files mv'ed?
1,405,003,621,000
I have a log file that has lines that look like this: blah blah blah Photo for (702049679 - blah blah blah Now I know I could get all the lines like that from the file by doing: grep "Photo for" logFile But how can I take those lines and get a comma seperated list of each number after the parenthesis in a single out...
A regex this complicated is better handled with Perl, e.g. grep "Photo for" logFile | perl -pe 's/.*Photo for ((\d+).*/\1/' | tr '\n' ',' If Perl is out of the question: grep "Photo for" logFile | awk '{sub(/.*Photo for \(/,"",$0);sub(/[ ].*/,"");print $0}' | tr '\n' ','
Awk/grep/sed get comma separated list of numbers from lines of text
1,405,003,621,000
is it possible to list all the ".php" files located into a direcotry and their octal permissions? I would like to list them like this: 775 /folder/file.php 644 /folder/asd/file2.php etc...
find /folder -name '*.php' -type f -print0 | perl -0 -lne 'printf "%o %s\n", (lstat $_)[2]&07777, $_' See also this related question: Convert ls -l output format to chmod format. -print0 is a GNU extension also supported by BSDs like OS/X. GNU find also has a -printf predicate which could display the mode, but that...
MacOsx - Shell - list all .php files and their octal permissions, inside a specifc folder
1,405,003,621,000
I've found this code in a tweet: :(){ :|: & };: It said something about fork, but I don't completely get how it works. Could anybody please explain in detail what it does and how it works? Thanks in advance.
That is a "fork bomb", as you've heard. There's a whole wikipedia page about it. The fork bomb in this case is a recursive function that runs in the background, thanks to the ampersand operator. This ensures that the child process does not die and keeps forking new copies of the function, consuming system resou...
What does this code do? [duplicate]
1,405,003,621,000
I have some gnome shell widgets that I need to be closed. I am unable to find which processes are behind them. Any idea how can I kill them?
You can always try using ps to determine what processes are running out of everything, e.g.: ps -ely | grep -i $PROCESSNAME Guessing at what the widget names will be: ps -ely | grep -i gnome Is very likely to list them all.
How can I kill gnome shell widgets?
1,405,003,621,000
I know that the finger command used to display information about local and remote users. finger --> display users log in on local machine, even if remotely. finger @hostname --> display users log in on the remote machine. finger user@hostname --> I don't know what is it used for? and who command used to know info abou...
who "Displays information about the users currently logged in to the local machine" - who man page. You can also specify a file for who to read from, like old logins file. finger Displays information about the user (being local or remote if a host is supplied) or all users if no username is supplied. finger provides m...
finger and who commands usage
1,405,003,621,000
I am asked to check and shut down the processes that I am not familiar with. So when I ls under bin folder, I see multiple process .sh. But I want to know which process is associated with which tomcat process. Is there any easy way to find out that? Example startmyprocess1.sh, but when I do ps -ef | grep startmyproces...
Starting myprocess from within startmyprocess.sh does not name the process after the underlying shell script, that is why your ps -ef | grep startmyprocess1 does not return a result. This is also why many processes, especially daemons, write their pid out to file so that you can easily reference it's process. This can...
check running process
1,405,003,621,000
For backup MySQL MyISAM database, I'm using: backupdb=siteone mysqldump -u root -pthepass --lock-tables --add-locks --disable-keys --skip-extended-insert --quick $backupdb > /var/www/html/db2.sql Even after long time using it, I still dont know what is the name of using nameofmychoice=anyname. After typing backupdb=s...
In your example, backupdb is called a variable. A shell variable will be there until you change it to a new value, or the shell exits (most likely because you type exit, or close the terminal). In your case, backupdb will be there for a long time, so you don't need to type that again and again. My guess is that you ar...
How reliable of using "nameofmychoice="anyname""
1,405,003,621,000
I set a variable TEMPP='-I ../dir1 -I ../dir2' then I run gcc -M $TEMPP somefile.c It seems not to include ../dir1 and ../dir2 in the search list of the include file, and if there is a space at the beginning of the variable, like TEMPP=' -I ../dir1 -I ../dir2' it reports an error: gcc: -I ../common1 -I ../encrypt: N...
In zsh, unlike other Bourne-style shells, the results of a variable substitution are not split into words that are interpreted as wildcard patterns. So in zsh, if you write a='hello *.txt' echo $a then you see hello *.txt, unlike other shells where you'll see something like hello bar.txt foo.txt. You can turn on word...
How to change the interpretation of a variable in `zsh`?
1,405,003,621,000
Possible Duplicate: How can I close a terminal without killing the command running in it? I'm using Debian for my Server. I just installed MediaCore, which works well. Now I want to have it always started and want to ask, how it'd be possible to start it as a service or in the background. I know how to start but t...
You have a couple options. First, you can launch it in screen and then Ctrl-A out of the screen after it launches. You can later reattach to the screen with a screen -RR {screen number}; you can figure out the screen number with a screen -ls. (If you only have one active screen a simple screen -RR will reattach). Se...
How to run regular programs as daemons/services [duplicate]
1,405,003,621,000
When using Git VCS, I execute all of the git commands on the directory that contains a .git repository. I want to execute a git-pull through an SSH trigger but how do I define the path to the repository to perform the action on?
If you set the GIT_DIR environment variable, git will use it as a path to the repository. In general, you can start a subshell like this: (cd /some/other/directory/; git pull) The subshell will have its own current directory and environment variables.
Execute a command in a different path
1,405,003,621,000
Is there a good, simple commandline player that uses gstreamer?
gst123 is command line music player that uses gstreamer. I have not messed with it, I generally use MOC.
Commandline gstreamer player
1,405,003,621,000
I'm trying to download a large number of files from a remote server. Part of the path is known, but there's a folder name that's randomly generated, so I think I have to use wildcards. The path is something like this: /home/myuser/files/<random folder name>/*.ext So was trying this: rsync -av [email protected]:~/file...
Instead of letting the remote shell expand a glob that results in a too long list of arguments, use --include and --exclude filters to transfer only the files that you want: rsync -aim --include='*/' --include='*.ext' --exclude='*' \ [email protected]:files ./ This would give you a directory called files in the c...
Retrieve large number of files from remote server with wildcards
1,405,003,621,000
I've configured openvswitch virtual switch and can list it with ip command as follows: # Show all interfaces ip link Output: 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 <snip> 5: ovs-system: <BROAD...
The Open vSwitch interface is not a kernel bridge interface, but a kernel(-accelerated) openvswitch interface, with its own separate driver. In case of doubt, any interface type will be displayed with the -details option (edited to match OP): $ ip -details link show dev ovsbr0 6: ovsbr0: <BROADCAST,MULTICAST,UP,LOWER_...
List openvswitch virtual switch with ip command
1,405,003,621,000
I could find the ip address of my board by using ifconfig but I need the port number as well to set Linux TCF agent. I tried netstat with several options but could not find as it returns too many and cannot scroll the screen to the top. So is there a way to find the port number given the ip address?
Prefer using ss netstat is deprecated (no update since 2011), as said in the man page, in the NOTE section. So you probably should use ss, which is part of the iproute2 package. You can use the following command: ss -nltp -n will prevent names resolution -l displays listening sockets -t is used for TCP transport (if...
How to find the port number given the ip address
1,405,003,621,000
Without giving more details, the only commands I know are file, stat and mediainfo. While both give some idea about an .epub document, not all. For e.g. file just gives the filename and declares it to be an epub document. Mediainfo is slightly better that it gives the following info. Format ...
Try exiftool which is the go-to tool to extract file metadata: $ exiftool Downloads/accessible_epub_3.epub ExifTool Version Number : 12.57 File Name : accessible_epub_3.epub Directory : Downloads File Size : 4.1 MB File Modification Date/Time ...
Getting more metadata about epub documents
1,405,003,621,000
I can download extensions from https://extensions.gnome.org/ or https://cinnamon-spices.linuxmint.com/ using curl. However, I am unable to do it from https://www.gnome-look.org To be specific, I am trying to download the zip files from https://www.gnome-look.org/p/1309239 and https://www.gnome-look.org/p/1308808 I fou...
To download the latest versions of the themes or icons, use the following command. curl -Lfs https://www.gnome-look.org/p/1308808/loadFiles | jq -r '.files | first.version as $v | .[] | select(.version == $v).url' | perl -pe 's/\%(\w\w)/chr hex $1/ge' | xargs wget or: curl -Lfs https://www.gnome-look.org/p/1308808/lo...
Download files from gnome-look.org via CLI
1,405,003,621,000
Im using grep for searching pattern in huge log files, since it's a log file and i want to see what's going on around the matches, i usually do grep -C 3 -color ... however, after reading a lot of logs i find a little annoying to distinguish between every 7 lines, which line belongs to which match, so i want to find a...
Like this using Perl and core Term::ANSIColor (installed by default): <COMMAND> | perl -MTerm::ANSIColor=:constants -pe ' BEGIN{ our @colors = (MAGENTA, BLUE, GREEN); our @cols; } @cols = @colors if not scalar @cols; my $color = shift @cols if /^$/ or $. == 1; print $color; END{ p...
Highlight grep results in different colors, a color per match (up to 3 colors)
1,405,003,621,000
I have a debian installation, where the OEM has a bunch of processes I dont recognize running, and I want to figure out if any of these things are dialing home. I ran sudo tcpdump | grep ^e <ssh_ip> but the pipe keeps breaking. I am connected via ssh, and the grep ^e is to omit the ssh ip of my client. Is there a way ...
In: sudo tcpdump | grep ^e <ssh_ip> First, that ^e has different meanings depending on the shell. in the Bourne shell, ^ is an alias for | (^, originally rendered more like ↑ being the pipe operator in its predecessor, the Thompson shell), so you'd pipe grep to e command there. in fish versions up to 3.2, ^ was to...
how can I parse tcpdump stream live?
1,405,003,621,000
I have two commands, as follows: This one gives repo names: az acr repository list -n registry -o tsv output looks like: name1 name2 ... This one gives digest codes for one repo: az acr manifest list-metadata -r ${REGISTRY} --name ${REPO} --query "[?tags[0]==null].digest" -o tsv output looks like: digest1 digest2 ...
You'd need something like: export REPO az acr repository list -n registry -o tsv | while IFS= read -r REPO; do az acr manifest list-metadata -r "$REGISTRY" --n "$REPO" --query '[?tags[0]==null].digest' -o tsv | awk '{print ENVIRON["REPO"]": "$0}' done Calling awk to prefix the output of each manifest co...
How to use output of multiple commands in last execution command while chaining commands?
1,405,003,621,000
Using ss, we can identify the local address, peer address, and process. Is there a command that returns how long these connections have been active?
Unfortunately, you have to work at it. The following script is a hack to attempt giving you what you are looking for. #!/bin/sh BASE=`basename "$0" ".sh" ` TMP="/tmp/tmp.$$.${BASE}" #Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port ...
Duration of connections returned by ss
1,405,003,621,000
I've set up so that I can SSH securely into my home PC from my laptop. Today, I tried running an update just to test, but I couldn't do it from the laptop. What I basically wanted to do, was to pass the command to the machine without SSH-ing into it while not keeping the connection alive. I tried looking around online...
Possible way: ssh -t myip 'sudo -b dnf upgrade -y >/tmp/aa 2>&1' You want your task to run whilst disconnected; use the 1> and 2> redirections You want your task to run in background; use sudo -b option You want ssh to provide interactivity to sudo; use ssh -t option Other possible but not recommended way: echo PAS...
How can I pipe an alias that requires sudo through SSH?
1,405,003,621,000
Ansible CLI allows to run a custom shell command (done implicitly using the default module "ansible.builtin.command"): ansible myhost -a "/bin/mycommand" Is it possible to do the same via tower-cli aka awx-cli? EDIT: answers that use the awx CLI tool are acceptable; however, I'd prefer solutions that use tower-cli/a...
In short, the answer is yes. According the Ansible Tower CLI Reference Guide, it is possible to do an awx ad_hoc_commands create resulting into a Job similar as others. The parameter for --module_name would be shell or command and if configured for ANSIBLE MODULES ALLOWED FOR AD HOC JOBS List of modules allowed to be...
Run a shell command via tower-cli
1,405,003,621,000
Before turning off my Laptop (which runs Fedora 36) I like to run sudo dnf offline-upgrade download -y && sudo dnf offline-upgrade reboot || sudo shutdown now So that all pending updates get installed automatically and I don't have to worry about using the Software Center or shutting down via GNOME. The only problem i...
Update (2023-04-08) - this is available as of dnf-plugins-core 4.4.0: dnf offline-upgrade reboot --poweroff It looks like it's hard-coded — see plugins/system_upgrade.py: def transaction_upgrade(self): Plymouth.message(_("Upgrade complete! Cleaning up and rebooting...")) self.log_status(_("Upgrad...
Fedora Offline-Upgrade shutdown instead of reboot from CLI
1,405,003,621,000
About the pkill command, I know is possible kill processes - for specific scenarios - based through tty[1-6] and pts/[0-N]. I tested and works as expected. Until here all is ok. But now, according with this answer and solution: What is the difference between kill , pkill and killall? it indicates (extraction): pki...
The session id is the identifier of a process’ session. Sessions are a concept tied to shell job control, at a level above process groups; all processes in a given session share the same controlling terminal. In non-graphical environments, sessions can be thought of as login sessions (at least, that’s part of the orig...
What does Session ID mean within the pkill context?
1,405,003,621,000
I have a command whose output I want filtered by the results (plural; multiple lines) of another command. So far I've been sending the results of the first command to a file and filtering the second command with grep -f: command1 > /tmp/output command2 | grep -f /tmp/output rm /tmp/output I'd like to put that in a si...
If your shell offers "process substitution", try command2 | grep -f <(command1) If not, you can also pass the list of regexps on the command line using command substitution: command2 | grep -e "$(command1)" That will have a lower limit on the maximum size of that list of regexps, and also means that it won't work if...
how to grep the results (plural) of another command
1,405,003,621,000
Given e.g. pdf (in any size) how to enlarge it to A2 size and print on four A4 pages? (if possible it would be great if pdf having multiple pages we could split like this, so if there is pdf with posters to print multiple at once) (of course command line solutions proffered ;) )
Starting from the pdf A2 format object, crop it with either pdftilecut or with pdfposter. See the pdftilecut github page for examples and source code, or consult the man page for pdftilecut once installed. If you decide to use pdfposter to tile your pdf file: $ pdfposter -s4 infile.pdf outfile.pdf Both solutions a...
A2 on four A4 pages? | Convert A4 PDF to "A2 on four A4" PDF?
1,405,003,621,000
I want to make a shell script which copies the past outputs of the GUI terminal emulator (for example, last 20 lines). The motivation is as following: When I execute a procedure which requires long time (for example, downloading a very large file, or converting a very large movie file), I sometimes remember another jo...
Run your command with nohup, screen or tmux in the first place. Of course this won't help if you already started your process. If that is the case, you can capture output of your command using strace: strace -p<PID> -s9999 -e write 2>&1 | grep -o '".\+[^"]"' (replace <PID> with the PID of your process) If strace ca...
Shell scripts: How to copy past outputs of terminal emulator?
1,405,003,621,000
I currently extract text from image using: import png:- | convert png:- -units PixelsPerInch -resample 300 -sharpen 12x6.0 png:- | tesseract -l eng stdin stdout | xsel -ib However, import png:- command to take screenshot is not working well for me. It somehow do not quite suit Linux Mint. Is there any other command ...
I remember having similar issues with scrot. In that case I added a sleep and it was fine! Worked fine for me, but I'm not on Linux Mint. { import png:-; sleep 0.1 ;} | convert png:- -units PixelsPerInch -resample 300 -sharpen 12x6.0 png:- | tesseract -l eng stdin stdout | xsel -ib Also, you could try out scrot with ...
How to send Screenshot to STDOUT
1,405,003,621,000
Is there a way to blacken parts of a pdf file (i.e. personal data that I don't want to send with the pdf)? Maybe from the command line where I can say make everything black on page 2 from pixel X455 to X470 and Y300 to Y320.
In the end I managed to do it with GIMP. You can open .pdfs in Gimp and edit them. I took a black paintbrush to redact some text. Then I clicked on export and used a .pdf ending and it was exported to PDF (with some quality loss).
Edit PDF On The Command Line
1,405,003,621,000
For a MacOS and Ubuntu Server 20, with the command man less I can read the following: -n or --line-numbers Suppresses line numbers. The default (to use line numbers) may cause less to run more slowly in some cases, especially with a very large input file. Suppressing line numbers with ...
less displays line numbers in two ways: at the start of each line, if -N is used; in the status line at the bottom of the screen, when verbose prompts are enabled (less -M; this will show the number of the first line shown, the last line shown, and the total number of lines). -n disables the latter, as well as the f...
less -n default behavior, is not the same as indicated through man
1,405,003,621,000
I tried How can I list all files which have been installed by an APT package?. But the problem is, for example: when I run sudo apt install libvirt-daemon-system it does not only install one package (in this case libvirt-daemon-system). It also installs the packages mentioned under The following NEW packages will be i...
After the fact, you can feed the list of installed packages to dpkg -L: dpkg -L libvirt-daemon-system cpu-checker ibverbs-providers ipxe-qemu \ ipxe-qemu-256k-compat-efi-roms libcacard0 libfdt1 libibverbs1 \ libiscsi7 libpmem1 librados2 librbd1 librdmacm1 libslirp0 \ libspice-server1 libusbred...
How can I list all files which have been installed by the APT command
1,633,012,780,000
Similar to this question, but instead of adding a new line to the end of the prompt, add a new line to the beginning of the long command (when a command reaches to the right side of the command line window). I believe I saw such behavior in fish as shown in this video. It only adds newline to the line containing the p...
In zsh, you could do something like: zle-line-pre-redraw() { (( BUFFERLINES == 1 + ${#BUFFER//[^$'\n']} )) || PREDISPLAY=$'\n' } zle -N zle-line-pre-redraw Which prepends a newline if the number of lines to display to render the buffer is greater than the number of newline characters plus 1 (meaning at least one li...
Insert newline to the beginning of the command if it's too long
1,633,012,780,000
I redirected standard error of bash command to a file and bash prompt got redirected. But when i print the content of file, it was empty. Where did the bash prompt go? and again when i redirect stdout of bash to a file, it redirected the output and and not the prompt as expected but while printing the content of file...
In the first one, it looks to me that Bash goes in non-interactive mode if stderr is connected to a file when it starts. In that mode, it unsets PS1, and hence doesn't print the prompt. It also shows in $-, it doesn't contain the i signifying interactive mode. $ bash 2> file.txt echo ${PS1-unset} unset echo $- hBs We...
Weird output when redirecting bash prompt to a file
1,633,012,780,000
I want to change the key binding in tmux copy mode. This is my tmux config: set-window-option -g mode-keys vi So I use the vi keybindings for copy mode. But since I use the colemak keyboard layout which has the keys n,e,i,o instead of j,k,l,o I want to bind the following: bind n down bind e up bind h left bind i righ...
See tmux list-keys: bind-key -T copy-mode Up send-keys -X cursor-up bind-key -T copy-mode Down send-keys -X cursor-down bind-key -T copy-mode Left send-keys -X cursor-left bind-key -T copy-mode Right send-keys -X cursor-right So in your case you can do: bind-key -T copy-mode-vi n send-keys...
Change key bindings in tmux copy mode
1,633,012,780,000
Im fairly new to linux, and until now, always thought sudo <command> was the same as exectuing <command> as root. I recently played around a bit with the ls command, and noticed a slight, but confusing difference. When executing sudo ls -lap (in the root directory), i get the following output: vs. when i execute ls -...
Your ls is an alias, and sudo doesn’t know about it. When you switch users to become root, your interactive shell runs its startup scripts and sets up the relevant aliases. Try running alias ls as root, not via sudo, to see the corresponding command. The difference in the output for symbolic links seems to be a side-e...
What is the difference between executing a command with sudo vs doing so as root user?
1,633,012,780,000
I could get system environment variables by using printenv command, but I need separate variables data: How could I lists of get local (session-wide), user (user-wide) and system (system-wide, global) environment variables separately? OS: Debian-like Linux (x64), kernel: 4.19.
I think you have a misconception about how Linux environment variables work. Environment variables for a running shell are only defined for that instance of the shell that is running. They have no meaning or relevance outside of that. If you change the $PATH variable in a shell you are using, that change will only hav...
Linux - Get List of Local-User-System Environment Variables Separately
1,633,012,780,000
I'm very new to scripting and makefiles, and am curious about the passing of command line arguments. So, let's say I have a makefile which compiles and runs something in C, for example CompileAndRun: CompileFile RunFile CompileFile: (Compiling code) RunFile: ./Program I would call this with make Compile...
The idiomatic way to do this is to pass a variable which you can then refer to in the Makefile, for example: CompileAndRun: CompileFile RunFile CompileFile: (Compiling code) RunFile: ./Program $(ARGUMENTS) You can now make RunFile to run it without any arguments or make ARGUMENTS="foo bar" RunFile to ru...
Makefile - Providing Optional Arguments
1,633,012,780,000
Is there a tool that can be used to monitor the traffic a web server is processing in real-time from the command line? I'm looking for a cli ncurses tool like nload, but one that can show the requests per second going to a web server like nginx or apache (or a cache like varnish) via mod_status or stub_status.
It doesn't look like nload, but you an get a ton of useful information from your web server's access logs (NCSA, W3C, squid,or any user-defined custom log format) in an ncurses-based tool called goaccess In Debian, run: sudo apt-get install goaccess goaccess /path/to/access.log -c It will look something like this
cli real-time monitoring of web server traffic per second over time (ncurses)
1,633,012,780,000
I am not able to find a way to append a line in yaml file after exact match of string but ignoring similar string having other values in it in a line. There are some example but that is not my case. I have a yaml file and I am automating its configuration instead of adding values manually by going to line number, I am...
You could use $ to match the end of the line: sed -i "/callbacks:$/a\ \ - 'https://d1.example.com/callback'" a.yaml
How to append a line using sed in Linux yaml file after matching exact string
1,633,012,780,000
For example: curl -s 'https://api.github.com/users/lambda' |\ jq -r '.name' return value of "name" json attribute. If this attribute is empty or not exist command return null or '': curl -s 'https://api.github.com/users/lambda' |\ jq -r '.blabla' I need to run command like python main.py when command above return...
Since the command is successful, regardless of the output, you'll have to save it in a variable and pass it to your script if it isn't empty. It looks like you only get empty when you request data for a known field that has no value (e.g. .gravatar_id) and you get null if you pass an unknown field (e.g. .blabla). To a...
Execute command when command-line pipe result is not null or not empty
1,633,012,780,000
I have several folders within a parent folder, which all have the structure below, and am struggling to create a specific loop. parentfolder/folder01/subfolder/map.png parentfolder/folder02/subfolder/map.png parentfolder/folder03/subfolder/map.png parentfolder/folder04/subfolder/map.png etc... so each subfolder conta...
You may try something like the following for loop, for d in parentfolder/* ; do cp "$d/subfolder/map.png" "$d.png" done You should run it when your current directory is on the same level of the parentfolder.
cp command based on parent directory
1,633,012,780,000
The Bind related tools (host, dig, nslookup) don’t seem to be capable of encoding their output as JSON, judging from the man pages. I’m looking for a CLI tool that is, preferably one that does not depend on an interpreter or language runtime. (DOH is not an option as most DNS servers don’t support it.)
ogham/dog: A command-line DNS client has JSON output, as described in the section Output options: -J, --json Display the output as JSON I haven't tried it myself yet. Possible caveats: at the time of writing (2021-06-14), there has been only the initial release v0.1.0 (2020-11-07), and there is no wide...
DNS lookup with JSON output
1,633,012,780,000
I'm trying to search through the files and directories of a specific folder. For example, I was looking in /usr/bin for my python binaries. To do so, I used ls | grep python. When I did this, I was able to find, for example, python3, python3-config, etc. While this works fine, I know that there are easier ways to do...
you can do several things, using "globbing" In a nutshell: the shell tries to match ? to any character, (unless it is "protected" by single or double quotes * to any string of characters (even empty ones), unless protected by single or double quotes [abc] can match either 'a', 'b' or 'c' [^def] is any single characte...
Alternative to ls | grep [duplicate]
1,633,012,780,000
I have a data-set of Unix commands as input into terminal and I want to use them to compare user behaviours. Different users interact with different directories and files (they are all on separate computers). I want to look at which users use the same commands, with the same arguments/parameters (but I am happy to hav...
You can't. You need to know the semantics of every command executed. Any argument given to a command on the command line is just passed to the program which is then free to implement however it feels like. The program doesn't even have to be consistent in how it interprets arguments (it is probably not very usable if ...
How can I identify file names and directories from logs of Unix commands?
1,633,012,780,000
Using a live linux distribution we can install some package , it is not a persistent install, the package will be removed next boot. On a fully installed system, is there any command line tool or an apt configuration allowing a non-persistent install?
As far as the apt side of things goes, I’m not aware of anything; in fact apt and dpkg go out of their way to ensure that the system remains in a consistent state, and that as far as possible, changes made to the package selection are “permanent” (at least until the next apt or dpkg invocation). There is something you...
Is there any way to install a transient package?
1,633,012,780,000
I need to rename a file like a link, but if I try to rename it with mv file.gif http://link/123/file.gif it won't work. I've tried to escape the Slash / with a Backslash \ , but with no success. The Error that comes up tells me, that he didn't find the directory, because he sees the Slash as a layer of the directory t...
/ is the character that delimit components in a Unix file path. That character cannot occur in a directory entry's name. http://link/123/file.gif is the file.gif file inside a 123 directory itself inside the link directory itself inside the http: directory, itself in the current working directory. To rename it to that...
how to rename a file like a weblink (http://...)
1,633,012,780,000
How can I separate the following high-resolution single-page PDF into multiple pages (page count is unimportant), so that each page is the size of standard printer paper (8.5"x11"). The map should be zoomed to 200% before it's separated, so that I can see the small details. At 100% resolution lots of details are misse...
The requirement can be thought of as of tile cropping the original page. I think the following command does what you want: convert -density 288 HarrimanTrailMap.pdf -crop 20% +repage HarrimanTrailMap-tiled.pdf You'll need imagemagick and ghostscript installed. Also, you may encounter authorisation error when converti...
Separate high-resolution single-page PDF into multiple pages
1,633,012,780,000
I'm using git-annex in version 7.20190129 as it is provided on my Debian Stable (Buster) machine to keep big files under version control and have them distributed over multiple machines and drives. This works well as long as I have at least one "real" git-annex repository (not a special remote). What I'd be intereste...
A special remote is just storing the file data, not the git repository. Think of it as a a library's cellar: A library may build an additional room to store its books there, but if you want to build a library back from the cellar, you don't have any index, don't know which book is in which catalogue, and you don't hav...
accessing git-annex special remote from new repository
1,633,012,780,000
I have directory structure like the following: . ├── ParentDirectory │   ├── ChildDirectory1 │   │   ├── 01-File.txt │   │   ├── 02-File.txt │   │   ├── 03-File.adoc │   │   ├── 04-File.md │   │   └── 05-File.txt │   ├── ChildDirectory2 │   │   ├── 01-File.txt │   │   ├── 02-File.txt │   │   ├── 03-...
With zsh: autoload -Uz zmv # best in ~/.zshrc zmv -n '(**/)(*)' '$1${${2##[[:space:]]#}%%[[:space:]]#}' (remove -n (dry-run) if happy). Add a (#qD) at the end of the pattern, if you also want to process hidden files and files in hidden directories. With rename, that would be something like: find . -depth ! -name . -e...
remove all leading and trailing whitespace from both file and directory names recursively
1,633,012,780,000
It is known that the character (!) Is reserved, the curious thing is that it works on the common user, but does not work as root, I tried some approaches to solve my problem, but without success, I would like to know if it is possible to escape these characters . The command I'm trying to execute is simple, a move ign...
This has nothing to do with escaping the ! character. The ksh shell implements some extended globbing patterns, and !(...|...|...) is one of these. The pattern matches anything not matched by any of the patterns in the parenthesis. Some shells are able to use ksh globbing patterns. For example, setting the extglob s...
How to escape reserved character on command line or shell script in linux?