date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,574,835,605,000
I'm looking the cflags for the turion X2 M500 processor I'm doing grep -m1 -A3 "vendor_id" /proc/cpuinfo and the output is: vendor_id : AuthenticAMD cpu family : 16 model : 6 model name : AMD Turion(tm) II Dual-Core Mobile M500
If your build environment is on the turion x2 machine: Step 1: Assuming GNU gcc/g++, -mtune=native -march=native will build code optimized for the machine on which the compiler is run. I don't know how to tell the compiler to dump the chosen flags, but If you want to cross-compile, you'll need to examine the capab...
what are the cflags of this microarchitecture?
1,574,835,605,000
When submitting jobs, I'm getting Exit codes returned, but I have to hit the return key for them to be printed to the log. 1. prompt_line/location sas query.sas & 2. [1] 66682 3. prompt_line/location 4. [1]+  Exit 1                  nice -n 19 opt/sas/sashome/server/SASFoundation/9.4/sas 99query.sas 5. prompt_line/lo...
If you are using a sh-compatible shell as your interactive shell (such as bash), you may use set -b: Report the status of terminated background jobs immediately, rather than before the next primary prompt. This is effective only when job control is enabled. In bash, th...
New prompt line not automatically put to command line upon exit code
1,574,835,605,000
Rawinput: ➜ datatest tree . ├── a │   ├── README.md │   ├── code │   └── data │   └── apple.csv ├── archive.sh ├── f │   ├── README.md │   ├── code │   └── data │   ├── Archive.zip │   ├── a.csv │   ├── b.xlsx │   └── c.xlsx └── toolbox └── tool.py 7 directories, 9 files Output: ➜ datatest ...
Something like this maybe? find . -type d -name data \ \! -exec test -f {}/Archive.zip ';' \ -execdir zip -rj data/Archive.zip data ';' This would locate each data directory (first line). The \! -exec test -f {}/Archive.zip ';' would filter out any data directory that does not contain any file called Archive....
How to compress all files from all subfolders if there is no `Archive.zip` in subfolder?
1,574,835,605,000
For example suppose we have a file called input.txt which contains 100 John Doe LEC05 12356 132 Carol Bon LEC05 156 122 Cavar Liktik LEC01 136 ... This command should find everyone in LEC05 and print out their first names in sorted order in a file called output.txt The command should be a one-line command (with pipes)...
With awk: awk '$4 == "LEC05" { print $2 }' /path/to/inputfile | sort > outputfile With grep and cut: grep 'LEC05' /path/to/inputfile | cut -f2 | sort > outputfile
One line shell command that finds all students in LEC05 and prints their first name in sorted order
1,574,835,605,000
This question is similar to How to show lines after each grep match until other specific match? I want to match a particular pattern in lines before another pattern match. Here I want to get the file from a given host. Each file can have multiple hosts. Hence I don't have a fix number of lines before I get to the host...
Another awk variation: /^<hostfile file:/ { output=substr($2, 6, index($2, ">") - 6); } /<host>/ && $0 ~ pattern { print output } Call it such as: $ awk -v pattern='xyz.com' -f findit.awk contextfile abc.txt $ awk -v pattern='asd.com' -f findit.awk contextfile xyz.txt
How to match a pattern in lines before another pattern match
1,574,835,605,000
I'm trying to learn how to parse files using the Linux commands and tools. I'm always confused on how to best leverage grep/awk/sed. Here is a specific use case. I have a log file that contains the following strings: Config Server received a Connection Establishment with an invalid public key, closing connection. Agen...
sed approach: sed -n 's/.* Agent Identifier: \(.*\) Socket IP: \(.*\)/\1 \2/p' inputfile > host_list.txt host_list.txt file contents(cat host_list.txt): SRV3 192.168.2.6 TESTSRV4 10.1.2.3 SRV1 192.168.2.15 TESTSRV2 10.1.2.4
Extract data from log file
1,574,835,605,000
I have a script that is run like this: curl https://example.com/install.sh | zsh - The script needs to read from use input: read "human_name?Your human name ?"</dev/tty The problem is the user sees the input and can enter their response but the response is not stored in human_name. Example: cat <<EOM | zsh - read "h...
You can always read from the terminal by redirecting from /dev/tty, as long as the program is not a background job. If it's a background job, it'll be paused by a SIGTTIN until it gets switched to the foreground. The problem with your script is not reading from the terminal, but what you do with what you've read. You ...
Reading from tty in piped shell
1,574,835,605,000
When looking for txt files, I run this command: find . -name "*.txt" -print This gives me a list of all the text files beneath current directory. However, find . -name *.txt -print gives me the following error: find: paths must precede expression: mein.txt Is this the generally expected behavior? What difference do ...
Within a token that is not quoted, it is your shell that will perform expansion, not the command that you are running. This means that, when you enter find . -name "*.txt" -print, then find receives the literal *.txt as one of its parameters, and uses this pattern as the argument to its -name option, which will match ...
In what way does quoting parameters to `find` matter? [duplicate]
1,574,835,605,000
I have some files under /mainFolder/test: abcd.log.2017_01_26_23_30.0 abcd.log.2017_01_26_23_35.0 abcd.log.2017_02_20_23_10.0 xyz1.log.2017-02-01 xyz2.log.2017-03-11 From these files, I need a file like abcd.log.2017_01_26_23_30.0. To search, I am trying like: myRegex="[0-9]{4}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}.[0-...
Using capture groups and $BASH_REMATCH to extract bits of strings: for name in *.log.*; do if [[ "$name" =~ \.([0-9]{4})_([0-9]{2})_([0-9]{2}) ]]; then printf '%d-%d-%d from "%s"\n' \ "${BASH_REMATCH[1]}" \ "${BASH_REMATCH[2]}" \ "${BASH_REMATCH[3]}" \ "$name...
extract date "2017-01-26"(in yyyy-mm-dd) from files name like "abcd.log.2017_01_26_23_30.0"
1,574,835,605,000
I have accidentally renamed a large number of my files with an .mp4 extension. Luckily the original extension has been preserved within the filename (e.g. simon.says.nfo.mp4) How would i now remove the mp4 part from just these files? Due to the naming system I have, I cannot just do a find for *.*.mp4 which would be a...
"rename" is a utility that does exactly what you need: rename 's/.mp4//' *.mp4 man rename for other info
Change misplaced file extensions
1,574,835,605,000
At certain time, various commands started to give various error messages. I catched a few of them and then rebooted the system and these commands were working. $ mkdir x mkdir: cannot create directory `x': $ file x.txt bash: /usr/bin/file: Input/output error $ touch x.txt Segmentation fault There were other...
Next step would probably involve looking at your dmesg | tail -40 output. Then again, it would probably answer with an other Input/output error. I guess you had to physically reboot this machine/commands were failing as well? Looks like your root filesystem is gone. Could be a problem with a disk, some sata cable, or ...
What could be wrong when mkdir, file and touch command give error messages
1,574,835,605,000
Which option should be used with tree command line tool to get sort from biggest to smallest? ├── [4.0K] types2 │   └── [ 116] types2.go ├── [4.0K] types3 │   ├── [ 689] types3.go │   └── [ 0] types3.go~ ├── [4.0K] web │   ├── [ 149] index.html │   ├── [ 647] web.go │   └── [ 0] web.go~ ├── [4.0K] wordco...
Even if the tree tool doesn't support sorting by size directly, you can still do it using tree and sort. You can use the following command to list all the files and their paths in the given folder and subfolders with their file size and then use the sort tool to sort them by the second column of tree output (that is t...
How to sort from smallest to biggest with `tree` command line tool?
1,574,835,605,000
for i in *; do echo ${i#*.}; done | uniq -u Why there are duplicates in the output?
Filter adjacent matching lines ... Note: 'uniq' does not detect repeated lines unless they are adjacent. You may want to sort the input first, or use 'sort -u' without 'uniq'.
When printing unique extensions in the directory with the uniq command there are duplicates
1,574,835,605,000
I need to run a program xyz. It finishes execution in a few seconds. It has some signal handling I need to test. From the shell or a bash script how do I execute the program and while it is executing send it a signal like kill -14. Currently, the command I am trying, is /usr/local/xyz input > some_file 2>&1 & PIDOS=$!...
That command looks ok. Though when I tried that, it appears the command was too fast. It's as if my test script didn't have time to install the signal handler before it got shot. A test script: $ echo '$SIG{USR1} = sub { print "GOT SIGNAL\n" }; sleep 100' > sigtest.pl Shoot it immediately: (the sleep is there so the...
How do I run a process and send it a SIGNAL while its running?
1,574,835,605,000
There are about 10000 files under a given directory. Are there any command that can help me randomly pick 1000 files from it and put them into another directory. The picked files should be removed from the original directory.
If you have shuf, it will easily let you do what you want, provided that no filename has a newline character in it, and there are no subdirectories: mapfile -t sample < <(shuf -n 1000 -e given_directory/*) mv "${sample[@]}" other_directory If there are subdirectories, you could get the list of files by using find ins...
Randomly select a proportion of files from a given directory [duplicate]
1,574,835,605,000
I've read a bunch of text files to extract some patterns. I need the line number too but the line number must be removed before the final grep (but can be saved for further processing maybe using variables). I'll explain my procedure splitting the (long oneliner) command for better understanding: read file with cat,...
Using awk on the original input file, prior to cleaning: awk '/account number [[:digit:]]+/ { match($0, "account number ([[:digit:]]+)", a); print NR ";" substr($0, a[1, "start"], a[1, "length"]); }' input This extracts the account number and prints the line number at the start of the line: 1;2345356432 3;8623525534 ...
extract line number and pattern in file at the same time
1,459,582,143,000
I'm trying to zip the contents of a site using tar and exclude a bunch of folders and error_log files but it doesn't seem to be working, when it's processing I still see many of the excluded files being processed. I am in the root of the site and I am trying to tar everything inside of public_html. Here is the comman...
You used exclude= instead of --exclude=. tar -zcvf files-live.tgz public_html/ --exclude='public_html/cache' --exclude='public_html/uplimg' --exclude='public_html/images/listings' --exclude='public_html/sets' --exclude='public_html/manage' --exclude='error_log'
Excluding files whilst using tar to zip site contents not working [closed]
1,459,582,143,000
ls -l | grep -v '^d' | sort -g -r -k 5 | head -2: I used this command to write into a text file. I've researched a bit online and I think these commands mean this: grep: a search that searches for a specific pattern in a string -v: an option for grep that tell it to find and display all lines that do not match '': no...
You've got most of the technical details, but I think you're missing the semantics of the whole thing. The single quotes in '^d' keep whatever shell runs that pipeline from treating characters in the regular expression (which is '^d') as "special". For example, $ is the regular expression meaning "end of line". Shells...
Linux command clarification
1,459,582,143,000
Sometimes a same command is provided by shell-builtin as well as other file/package. Example: $ type -a printf kill printf is a shell builtin printf is /usr/bin/printf kill is a shell builtin kill is /bin/kill And while executing command, I sometime face some difficulties or command doesn't work as expected. Example...
You can use env your-command to avoid interference from the shell. Example: $ env kill -L 1 HUP 2 INT 3 QUIT 4 ILL 5 TRAP 6 ABRT 7 BUS 8 FPE 9 KILL 10 USR1 11 SEGV 12 USR2 13 PIPE 14 ALRM 15 TERM 16 STKFLT 17 CHLD 18 CONT 19 STOP 20 TSTP 21 TTIN 22 TTOU ...
How do I execute command to avoid interference from the shell [duplicate]
1,459,582,143,000
I want to get the arg of a command from a var that has the index in it of the arg that I want. Something like this # command in terminal, `foo -r -f value_wanted` index="3" var=$"$index" echo $var ## expected output `value_wanted` I know I can just call it by $3 but that index I have is in the variable.
You can achieve that by using the following notation: echo "${!index}" If you want to process positional arguments, I suggest to use getopt (not getopts), though.
get command line agrument by variable in shell script
1,459,582,143,000
I am having a really hard time understanding how umask works. How is something that is 666 masked with 001 still 666 ?
A umask value of 001 says that it is preventing the creation of files with other executable permissions. (Actually not preventing the creation, as preventing the executable-permissions). A 666 mode in an open statement only permits user+group+other for read and write permissions. So the umask has no effect on that. ...
umask permissions that result in no change
1,459,582,143,000
As I am more of a web guy, i need a little help with this one, so I will explain what I am trying to do before I ask. I am creating batch script that will: GET request from an external server (json file), receive data, save locally as .json Use JQ to navigate the json for result[0].title Use the 'title' as a paramete...
While $1 typically has a special meaning (the first parameter passed to a script/function/etc.) you can indeed save the output of commands in variables. title=$(jq -r '.results[0].title' file.json) curl -i -H "Accept: application/html" -H "Content-Type: application/html" -X GET http://example.com/test/"$title" > test....
Create command line variables with PATH
1,459,582,143,000
I am trying to achieve something and in the experiment I came through following case , could somebody explain me how to understand whats happening. echo " Agent process not running on www.raja.server.local.com" | grep -oh "[*?<com]" o c o o o c c o m Thank you.
From the grep manpage: -o, --only-matching Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line. In this case, the -h is a no-op. grep is looking for each of the characters: *, ?, <, c, o, and m in the input string that you piped to it, ...
what grep -oh "[*?<com]" do?
1,459,582,143,000
I would like to compress four ISO files using 7z into a new archive called ISOs.7z from the command-line on my Sabayon machine. These are the commands I have tried so far (I know none of these specify the output 7z archive's name, just starting simple with these commands so that I can get the ropes of compressing with...
The correct syntax is: 7z a isos.7z *.iso or 7z a isos.7z chakra-2015.11-fermi-x86_64.iso openSUSE-Leap-42.1-DVD-x86_64.iso PCBSD10.2-RELEASE-08-19-2015-x64-DVD-USB.iso Sabayon_Linux_15.11_amd64_MATE.iso
Compressing files using p7zip from the command-line
1,459,582,143,000
When I tried to change from super user to common user and therefore typed "exit", I got an error message, that a job was stopped and I could not log out as root. So I listed the jobs: #jobs [1]+ yes | apt-get install build-essential I moved the job from the shells background to foreground fg 1 now I thought, I coul...
^C generates an interrupt signal (SIGINT). It's allowable for programs to mask this signal, and either ignore it completely or 'react' to it in a non fatal way. For example - you might want a program to stop whatever it's doing right now, but without terminating completely. So ^C doesn't always work. ^Z to stop the ...
unable to remove stopped job with ctrl+c
1,459,582,143,000
p_ash-3.2$ cp some_file1234.html /some/loc/ation/ofthe/some_file1234.html.html_Backu Have been seeing this intermittent issue with the command-line, while typing longer lines as part of any command, after typing some characters, say about 70, it starts all over again, from the extreme left, even before the -bash-3.X$...
Could be a carriage return (\r) in the destination file name. EDIT: Any chance you previously had your terminal settings messed up? This can happen if you by accident cat a binary file on your terminal. One way to fix that is stty sane Another reason might be that a SIGWINCH got lost when you resized the terminal wi...
Why would the prompt get overwritten?
1,459,582,143,000
i am trying execute ssh-copy-id in one port different than 22 (default). I researched and found the command below $ssh-copy-id -i ~/.ssh/id_rsa.pub "[email protected] -p 22001" but, when execute the command, i got this error: /usr/bin/ssh-copy-id: ERROR: ssh: connect to host 192.168.0.1 -p 22001 port 22: Connection re...
$ ssh-copy-id Usage: /usr/bin/ssh-copy-id [-h|-?|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname So in your case simply use: $ ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22001 [email protected] Because of your usage of quotes, the -p 22001 part became part of the hostname which explains the e...
ssh-copy-id different port
1,459,582,143,000
I came here across the command grep -E '(^| )ABC( |$)' file1 I am confused how to interpret the regular expression therein, because I know the ^ and $ character as beginning and end signifier, but in here they are not at the very beginning or end because of the bracket, ^ is sometimes used to negate a set of character...
It means that grep should search for ABC string only at the beginning of the line OR after space, moreover this string has to end with another space OR the end of the line. In other words someone wanted to search for a strings which form whole words. However this regexp has many issues, namely there could be many othe...
What is the meaning of (^| )ABC( |$) as an extended REGEX ?
1,459,582,143,000
I made a bash func for myself so I can through some words into a tree_hole file, it looks like this in bashrc: function th { echo -e "\n$@" >> /Users/zen1/zen/pythonstudy/tree_hole; } export -f th Thus I can do th Tom, I like your new laptop to cat the whole "Tom ..." sentence to the end of tree_hole file. But there ...
What you want isn't possible. You don't like the shell behaviour but this part of the shell behaviour cannot be changed. I guess this would work better for you: function th { { echo; cat; } >> /Users/zen1/zen/pythonstudy/tree_hole; } Your function would be called without parameters. cat would read from standard input...
Can I treat all what I typed after a command as raw string?
1,459,582,143,000
On Linux press F9 return a correct ~ On unix(solaris or hpux) return 0~ How to set correct tilde on those systems?
Solution found first must press CTRL+V and key in my case is F9 so i did CTRL+V F9 and return this ^[[20~ Now i know is key 20 and i bind it to tilde bind '"\e[20~":"~"' I try if work pressing F9 and return tilde I put this in $HOME/.profile for permanent change
Tilde on unix:hpux and / or solaris
1,459,582,143,000
I have installed Scientific Linux on VirtualBox and I am trying to follow some exercises on a book I picked up. The first thing I need to do is: mount /dev/dvd /media But when I do that, I get mount: you must specify the filesystem type What I would like to do is mount the virtual DVD where I see that the DVD in the...
I have realized that the reason why /dev/dvd was not being read was because of a setting that I had turned off on VirtualBox. I experimented a little bit and was able to mount the drive after that point. The setting I had to turn on was the .iso file found in Devices, DVD/CD in VirtualBox. I turned it off earlier bec...
Mounting /dev/dvd /media on VirtualBox
1,459,582,143,000
I'd like to install a program from sourceforge sources. Is there a way to download the latest stable source from SourceForge? an example for ntopng would be very welcome.
I'm pretty sure you can use wget and SourceForge, always use the url for the latest source. http://sourceforge.net/projects/$$PROJECT_URL$$/files/latest/download?source=files Where $$PROJECT_URL$$ needs to be replace by the part of url corresponding to the project. for ntopng ==> ntop which gives you: wget http:/...
automatically download latest stable tarball from sourceforge from command line?
1,459,582,143,000
I am using OS X 10.8.5. I am trying to figure out if the terminal is running bash. When I type in the following it says "getent" command not found -- but the error message seems to be coming from bash. Me$ getent passwd $(whoami) | awk -F: '{print $NF}' -bash: getent: command not found Am I running bash?
Your shell is bash and you have it trying to run getent. The reason it puts -bash: before getent: command not found is because otherwise it would look like getent was telling you it couldn't find a command.
Am I running Bash?
1,459,582,143,000
How to create a GUI in shell script without any third party libs (like setup command)
You can use whiptail or dialog Have look at this thread: Whiptail or dialog Bash Shell Scripting/Whiptail
How to create a GUI in shell script without any third party libs just like setup command [closed]
1,459,582,143,000
Is there any method to interact with a program directly from the commmand line? For example, I've a program, data.o, which produces a file mydata.out and then I want to plot it with gnuplot. I can open the plotting program with gnuplot & and then I would like the shell to write somehow in this job/background shell I ...
some programs like gnuplot accept a command file, it may be easier to generate on and then pass it as argument. some programs don't depend on interaction, for them piping to stdin may work ( printf "my command\n" printf "my other command line\n" ) | theProgram and its args other depend on interaction and ma...
How to interact with program from command line
1,459,582,143,000
I have a file where it contains a list of search patterns (searchPattern.txt). Its contents is similar to the contents below where there are 3000+ of them. 123456 234567 345678 . . . What I wanted to do is to use grep and search directories using the patterns listed in the file if they exist. It would be similar to t...
Try this one: grep -r -f /path/to/pattern/file diagnostics*
Grep to search directories for patterns inside a text file
1,459,582,143,000
For some reason (?), often when I write scripts nowadays they do not work, or work only in part, and then I try with . or source and they work perfectly. I'm unsure what is causing this as the scripts are different in a lot of ways, it's hard to isolate what must be sourced in order for the script as a whole to work....
If you want a command called script that actually sources the script file instead of running it as a separate process, then make a function: script () { . /path/to/script; } To make that function permanent, add it to the relevant rc file for your shell (e.g. ~/.bashrc for bash).
source script as command [closed]
1,459,582,143,000
Possible Duplicate: What is the easiest way to execute text from tail at the command line? I was guessing the ouput of a command that fails to execute should be sent to stdout and hence can be piped. It seems I am wrong, so please correct me. For example, $easy_install The program 'easy_install' is currently not...
The easiest way I can think of, since the line in question is a command, is: `$easy_install 2>&1 | grep sudo` The backticks or $(…) take the output of a command pipe and execute it as if you typed it, returning the output. Please note that this command won't work if you're missing sudo and trying to install it. But s...
How to act on output from a failed command [duplicate]
1,459,582,143,000
This is the last line in my .bashrc (lines breaks inserted for readability): STARTTIME=`date +%F-%Hh-%Mm-%Ss-%N`; \ script -q -t 2> /home/USER/logs/$STARTTIME-timing.txt \ -c 'bash --rcfile /home/USER/.bashrc-cp' \ -f /home/USER/logs/$STARTTIME-log.txt; \ gzip -9 /home/USER/logs/$STARTTIME-timing.txt /ho...
Q1 When you ALT+F4 your terminal, it sends a SIGHUP to the shell. The shell then exits and sends a SIGHUP to everything running under that shell. Because the shell exits, it stops processing all commands, so everything after executing script isnt run. The way to do this is to feed directly into gzip. STARTTIME=`date +...
terminal logging doesn't complete when I close the terminal
1,459,582,143,000
So I'm running a simple alias called vpn which runs a command and has an output, which I put into a .txt file. If interested to what exactly then here is the alias alias vpn="docker exec -it qbittorrent curl -sS https://ipinfo.io/json > $HOME/vpnstatus.txt" and the output when I use cat vpnstatus.txt; { "ip": "123.1...
The string you want to grep for is "ip": , but the string you are using is ip: . The double quotes are processed by the shell. To include the literal double quotes in the pattern, you need to quote them as '"ip": '. However, the correct (as in "robust") way to parse a JSON document is with a JSON parser, such as jq:...
How to use grep string that has double quotes in it
1,459,582,143,000
I want to check the free and reserved CPU in a linux server. I found this command mpstat and below is the output: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle all 7.13 0.00 2.46 1.73 0.00 0.08 0.00 0.00 0.00 88.59 If %idle is e.g 1.0% it means that I...
If possible, install the htop tool. I love it and have used so many times. It is like top but better and prettier with more options. To get the CPU average do following steps: execute htop press f2 to enter setup press 3 x right arrow key press 36 x down arrow key to CPU average press 2 x Enter or optionally move it ...
Check server's free and reserved CPU
1,459,582,143,000
I'm getting this error when I start my terminal: /home/USERNAME/.config/envman/PATH.env:2: permission denied: /home/USERNAME/.local/bin this is my .zshrc file: # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. # Initialization code that may require console input (password prompts, [y/n]...
Here's the error message wrapped to two lines for clarity: /home/USERNAME/.config/envman/PATH.env:2: permission denied: /home/USERNAME/.local/bin It means: "When trying to execute the 2nd line of PATH.env, I got the error: permission denied: /home/USERNAME/.local/bin. And the second line of your PATH.env is inde...
Permission denied error when starting terminal
1,459,582,143,000
Is there a command-line tool that enables to give a file more attributes than a name? For example, we have a file called ubuntu.pdf and we give it tags like command-line, shell, nautilus, my_favourite_stuff, whatever_else and a file linux.pdf with tags shell, command-line, ln, best_book and than I would like to have a...
Linux file systems do have capabilities for extended attributes, Stephen shows in his answer. But: many, probably most, graphical editors of various types will not truncate a file, then fill the same file with new content when you click on "safe". They instead make a new file, and rename it to original file name. In t...
Command-line tool enabling tagging and related tags functionality
1,459,582,143,000
I'm trying to write a very simple bash function that uses a one-line node script to read the value of a key from a JSON file. Here's the current contents of utils.bash: #!/bin/bash project_name() { echo $(node -e "require('../package.json').name;") } Yes, I know there are tools around that allow me to access JSO...
Well, the problem with PROJECT_NAME=project_name is it should be PROJECT_NAME="$(project_name)". The quotes in that case are not necessary as it's in an assignment to a scalar variable, but are a good habit to get into as in many other contexts (including your echo $(...)), omitting quotes implies splitting the result...
How can I write a function that returns the results of a one-line `node` script?
1,459,582,143,000
I use wget, rsync and curl to download files regularly (via https or ssh). One issue when I travel is that servers that are fast to access in one region become slow (or even inaccessible) in another. My current strategy is to use mirrors and switch to mirrors that are local to each region. I was wondering if there are...
The aria2c client has that functionality out of the box. It's a rather slim client and widely available. It does download in parallel by default, but that will only work to your advantage: if the fastest server is done delivering its part, it'll grab parts that a slower server hasn't yet
How to download using command line tools with a secondary (backup) source?
1,459,582,143,000
I'm using Windows 10 with WSL2. In all the terminals I have tried so far, I quickly encounter a broken command line. After pressing ENTER, the actual command appears differently, parts of the command prompt are deleted, editing does not occur at the cursor position, and random spaces are added, among other issues. Tod...
This looks like a fairly standard colorized version of a Debian/Ubuntu/Mint default prompt. \[ # begin non-advancing characters \e]0; # escape sequence to update terminal title \u@\h: \w # sets title to <user>@<host>: <working directory> \a # end terminal title \] # end non-adva...
Command line / prompt is broken, cannot edit (WSL2)
1,459,582,143,000
I have a log file like bellow. 130023432 195047 /media/ismail/SSDWorking/book-collection/_Books/book 1.epub 130023433 195047 /media/ismail/SSDWorking/book-collection/_Books/book 2.epub 130023431 195047 /media/ismail/SSDWorking/book-collection/_Books/book 3.epub I have a variable, var=130023432 I want to say if first ...
With this short awk (sub is sed like, to substitute a pattern or a regex): var=130023432 awk -v var="$var" '$1==var{sub($1" "$2" ", ""); print}' file or simply: awk -v var="130023432" '$1==var{sub($1" "$2" ", ""); print}' file /media/ismail/SSDWorking/book-collection/_Books/book 1.epub
If first word is $var then print the whole line except first two words
1,459,582,143,000
Here is an example of what I am trying to do: I have a folder (called 'dir') that contains the following: dir |_sub1.rar |_sub2.rar |_sub3.rar I will cd ~/ to dir and want to run a command that will extract all .rar files and place the contents into a folder with the same name. sub1.rar should be extracted to sub1, s...
set -e cd dir for rar in ./*.rar do [ -f "$rar" ] || continue dir=${rar%.rar} mkdir "$dir" ( cd "./$dir" unrar x "../$rar" ) # maybe rm "$rar" done Nothing clever here. Assumes you have an unrar command that takes an x option to do the eXtract. Just run a loop over the things matching ./*.rar, m...
Unrar all .rar files in a directory to a folder with the same name
1,459,582,143,000
I am writing to ask what the zero value (:0) means in the FROM column after the command w in bash. USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT Thank you
If you're talking/asking about the command w (I don't know a W command): It usually tells, from where a user is logged in. :0 is the $DISPLAY, when the user is logged in locally.
What does zero value means when pressing w in bash?
1,676,672,757,000
cdcl() { vlog -source -lint +define+"${1:-DEBUG}" -sv "${2:-*.sv}"; } Above is my fucnction, i defined it in .bashrc file. Below is my command line % cdcl 'RANDOM' 'abc.sv' This give me >> vlog -source -lint +define+RANDOM -sv abc.sv Is there a way, where i can skip giving the 1st placeholder value and only...
Since the function uses the default value expansion with the colon, i.e. "${1:-DEBUG}" and not "${1-DEBUG}", an empty value will also trigger the use of the default value. You can pass an empty value with "" or '', so cdcl "" abc.sv should result in the function running vlog -source -lint +define+DEBUG -sv abc.sv If...
How to pass 2nd argument when 1st argument is defaulted to its value in command line?
1,676,672,757,000
So I am working on building minimal os using busybox. What I want is I want to run my .net program from BIOS. But I am not sure linux will run .net program or not, so to clear my path I am using C program instead of .net program. I am generating initrd.img file successfully. Now before generating initrd.img file. I wa...
Your script is failing because you don’t have gcc in your initrd. You should not ship hello.c in your initrd; you should build the program and ship that instead in your initrd. You should also specify the full path to your program when attempting to run it.
How to integrate C program with init file?
1,676,672,757,000
So a document contains strings of the form: 9s5s4sKs7h6h4h2d4dAdTd2c3c 6hKhQs6s3s7s5d3d2d9dKdAd4h 5s9sTs8hKhJc4s6c4hJsAc2dKs Every line is made up out of pairs consisting of digit/uppercase letter and a lowercase letter. I want to look for all lines that have all pairs with the same lowercase letter grouped (next to ...
Since the letters are limited to just scdh, you could just filter out lines that have a different letter between two occurrences of a same letter with: grep -ve 's.*[cdh].*s' -e 'c.*[sdh].*c' -e 'd.*[sch].*d' -e 'h.*[scd].*h' Or with perl-like regexps if available: grep -Pv '([scdh]).*(?!\1)[scdh].*\1' Here, you'd b...
Finding all lines where pairs are grouped together with a regex using grep
1,676,672,757,000
I am trying to get the number of updates from the dnf without using sudo privilages. I guess dnf check-update is the first starting point but any idea how can I do this. It's important the solution is 1 line. Is something like this possible ?
It seems that this works: dnf check-update| grep -Ec ' updates$' since in each upgrade line there's a word updates at the end.
One line command for getting the number of dnf updates
1,676,672,757,000
As a fun side project, I'm building a serverless Todo application on AWS. I do a lot in the terminal, but my knowledge is basic. The command to add something into my DynamoDB table via the AWS CLI (v2.3.4) is this: aws dynamodb put-item \ --table-name tasks \ --item \ '{"task_id": {"S": "3495353e-726f-...
You could use jq to insert the date into the json object: aws dynamodb put-item \ --table-name tasks \ --item "$( jq -c '.created_at.S=(now|todate)' << 'EOF' { "task_id": { "S": "3495353e-726f-4e0e-b290-8014c03be971" }, "user_id": { "S": "aae3...
Within an AWS CLI command, add the ISO 8601 datetime
1,676,672,757,000
I have this output and would like to convert it into a Prometheus-like format by JQ. cat /tmp/wp-plugin.txt | jq .[] { "name": "akismet", "status": "active", "update": "none", "version": "5.0" } { "name": "performance-lab", "status": "active", "update": "none", "version": "1.4.0" } My goal is to get ...
Using jq: jq -r 'to_entries[] | .key as $k | .value | to_entries | map("\(.key)=\(.value|@json)") | "wp_plugins{\(join(","))}\($k)"' file or jq -r 'to_entries[] | .key as $k | .value | to_entries | "wp_plugins{\(map("\(.key)=\(.value|@json)")|join(","))}\($k)"' file This takes your original JSON file and starts by t...
Merge jq output into a comma separated string like
1,676,672,757,000
I have tried using jpegoptim and even tried the manpage but am stumped. Here is a file I want to reduce to 50k and even open to reducing quality of the data - Image: Filename: shirish.jpg Format: JPEG (Joint Photographic Experts Group JFIF format) Mime type: image/jpeg Class: DirectClass Geometry: 4624x3468+...
You can use ImageMagick to strip all metadata and decrease the quality. Check this answer for more info: quality in 85 progressive (comprobed compression) a very tiny gausssian blur to optimize the size (0.05 or 0.5 of radius) depends on the quality and size of the picture, this notably optimizes the size of the jpeg...
How to use jpegoptim to have files only 20kb in size?
1,676,672,757,000
I read this post: How do I run multiple background commands in bash in a single line? I understand the answer, but having the option to execute a set of commands through either {} or () makes to create this post. If the scenario(s) exists: when is mandatory use {} over () - and vice versa - and why?
The difference between both is that () create a subshell. For example, you can try this: cd $HOME ; ls The output with those commands will list the files and directories you have for the current user. Now, using subshell, you can try this: ( cd / ; ls ; ) ; ls What we are doing here is creating a subshell (cd / ; ls...
execute set of commands in group by {} vs () [duplicate]
1,676,672,757,000
I'm having trouble adding a user to a group: # useradd -aG group user # useradd -a -G group user # useradd -G group user --append It tells me that the -a option is an invalid or unrecognized. Can someone help me add the user to a second group (and not make him belong to it as the primary group)? Using Fedora 36. Than...
The useradd command is for adding a new user account. The usermod command is for modifying an existing user account - for example by adding it to a group usermod -aG group user
Cannot append user to group
1,676,672,757,000
I'm aware of the which command but when I run it on Java, I get the following path: $ which java /bin/java What I'm looking for, I think, is the Java path I get when I run the following Maven command: $ mvn -version Apache Maven 3.6.3 Java version: 11.0.14.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd6...
readlink -f /bin/java will trace the symlink all the way down to the actual executable. The result you get will be something of the form /usr/lib/jvm/java-11-openjdk-amd64/bin/java. Omit the /bin/java part at the end to get the JDK/JRE home path.
Which shell command returns Java's home path?
1,676,672,757,000
For some reason I have ended up using the 'local' (portable) version of Firefox, and it can check for updates from its dedicated window (Help - About...). Can that window be opened with one command?
There is no specific Firefox option or URL to open that specific window that I am aware of but you can automate key strokes to open that window using: xdotool search --onlyvisible --class firefox windowactivate --sync key --delay 500 Alt+h a That will search for a visible Firefox window, focus the window and send the...
How to open 'About Mozilla Firefox' (update) window with one command
1,676,672,757,000
I would like to compose a string of command line arguments in a variable, then use those to execute a command. I show a simplified example below. It's is a script called "listfiles." It reads a file called "ignore" of files not to list, then is supposed to list every file except those. What's the best way to accom...
Always use arrays to store things that are separate. Make sure you build a valid set of options for find. Don't embed extra sets of quotes in the arguments (this is ultimately what makes your command fail). #!/bin/bash readarray -t ignorepaths <./ignore ignoreopts=() for pathname in "${ignorepaths[@]}"; do ...
find files, exclude directories
1,676,672,757,000
There is a thing called Soft hyphen. Its unicode value is U+00AD and it cannot be seen in my text editor. Apparently, a few of my files are riddled with it: $ perl -C7 -ne 'for(split(//)){print sprintf("U+%04X", ord)." ".$_."\n"}' n­c U+006E n U+00AD ­ U+0063 c U+000A In between n and c, there is a soft hyphen. If yo...
Just use sed (I tested with GNU sed, I do not know if non-GNU seds can do it) and copy/paste the character into the sed expression. Here, I copied your echo n­c command and ran it, redirecting the output to a file which gave me a test file with the character of interest: $ perl -C7 -ne 'for(split(//)){print sprintf("U...
How to remove all soft hyphens (U+00AD) from a file
1,676,672,757,000
When starting, restarting an apache server is there a difference between the following commands? sudo service apache2 restart sudo service apache2 stop sudo service apache2 start AND sudo systemctl restart apache2 sudo systemctl stop apache2 sudo systemctl start apache2 I'm just learning a little bit about Linux ...
I'm just learning a little bit about Linux servers by playing around with the LAMP stack, but I want to know why certain guides use one syntax and other guides the other. using a sample file out of my /etc/init.d which is for an rlm license manager, the relevant code in that file related to start, stop, restart, an...
Is there a difference between these two Linux server commands? [duplicate]
1,676,672,757,000
I have an smb share that I see in the Files explorer as smb://whitebox.local/photos/ If I try to use commands on this smb share using the smb:// syntax, I get a "No such file or directory" error message: hippo@hippo-camp:~/Desktop$ ls smb://whitebox.local/photos/ ls: cannot access 'smb://whitebox.local/photos/': No su...
Applications using GUI frameworks such as Gnome or KDE let you access not only local files, but also various kinds of URL. On the command line, and in GUI applications that don't support URL, you can only access files. Files don't have to be local files: they can be files on a network share, but that share has to be m...
Bash commands using smb:// -> No such file or directory
1,676,672,757,000
I wrote the following command: lsblk -nl /dev/sdd -o MOUNTPOINT | awk '{if (NR!=1 && $1) { print 1; } else { print 0; }}' It is supposed to check if any of the paritions of the given device, in this case /dev/sdd are mounted. But for some reason, the script prints both 1 and 0? How does that make any sense? I need thi...
awk runs its code as a loop across every input line. You'll get either a 1 or a 0 for each non-empty line. You could If you want to determine whether or not a device has any mounted partitions, consider using this approach: device=/dev/mmcblk0 if [ -n "$(lsblk -nl -o MOUNTPOINT "$device")" ] then echo "Partitions ...
awk prints if and else case
1,676,672,757,000
I have managed to get the total number of users on the system with this: $ getent passwd | wc -l I need the number of users on the system with a certain first name (for example 'Josh') and whose usernames start with a 'b'. How? I don't know the syntax for this.
You can try something like: getent passwd|awk -F: '$5 ~ /^Josh([ ,.]|$)/ && $1 ~ /^b/'|wc -l
What is the shell command to tell me how many users there are on the system with a certain first name and whose username starts with a 'b'?
1,676,672,757,000
I want to run a set of commands from a bash script. How ever I don't know how to put the quotation in a bash script. The following is the bash script which I want to run, how ever in the cmake -DCMAKE_C_FLAGS I want to add another flag -gcc-name=/path/bin/gcc. I want to do it through a shell script and eventually run ...
Quote the whole value: cmake -DCMAKE_INSTALL_PREFIX=/g/g92/bhowmik1/installTF/ROSS \ -DCMAKE_C_FLAGS='-O3 -gcc-name=/path/bin/gcc' \ -DCMAKE_C_COMPILER=mpicc -DARCH=x86_64 -DROSS_BUILD_MODELS=ON ..
Add multiple options in cmake flag in a shell script and run the shell script
1,676,672,757,000
I am trying to add an extra header item to an existing email in a particular mbox, e.g. X-archived-to-crm: true,user,CRM-ID after it was archived, the CRM-ID is basically the id in the DB of the CRM. My MTA is sendmail, not sure whether this matters. I had a look mail, mailx but cannot figure out how to do it. I hav...
This can be done fairly easily with perl -i as an mbox file is just plain text. There are various mbox manipulation library modules for perl, but something as simple as this doesn't need them. The biggest difficulty is avoiding writing to the mbox file while something else is writing to it at the same time. The scri...
Any utility in Linux to add item to the header of an existing email in a particular mailbox?
1,676,672,757,000
my file: Informatica(r) PMCMD, version [10.2.0 HotFix2], build [1911.0401], Workflow run status: [Failed] Output I need is Failed Output I am getting is 10.2.0 HotFix2 Command used: grep "Workflow run status:" test.txt | cut -d'[' -f2 | cut -d']' -f1 If Workflow run status: comes in any field, my objective is to s...
cut -d'[' -f2 gets you the second [ delimited field. In Informatica(r) PMCMD, version [10.2.0 HotFix2], build [1911.0401], Workflow run status: [Failed] <---------- field 1 ---------> <------ field 2 ------> <------------ field 3 -----------> <field 4> You'd rather want the fourth field if its Failed you want. Howev...
Unix command to cut between strings
1,676,672,757,000
If I use man to view man pages, they are not interactive at all, I can merely change the visuals through a pager. With info I can view man and info pages with interactive links, including the links in "See Also" in man pages. But info strips all highlighting for man-pages and does not recognize other kinds of links, s...
I found the answer where I failed to look for a long time: vim It can view man pages and follow links, but even better, with https://gitlab.com/HiPhish/info.vim it will view info pages and fall back to manpages, all while staying interactive and colorful. I used the following shell line to use it as a simple viewer: i...
Is there a more interactive man and info pages viewer?
1,676,672,757,000
I have a bash script, /usr/bin/local/myscript. I run the file usually from an external software (in my case Autohotkey), basically I mean the script will be finished immediately and the window closes so I cannot see any logs on the window, info logs or error logs. So I do like to "script" the entire running steps for ...
But simply putting a script ~/script.txt in the first of the myscript file didn't work, I don't know what is going on, the next lines on the file didn't executed basically. For a shell interpreting myscript, script ~/script.txt is just a command that runs an external executable. The executable is script in this case...
Bash "script" command within bash files?
1,676,672,757,000
So, I'm creating this little convenience command for system information when bug reporting. alias clip="xclip -selection clipboard -in" alias bug="echo $(lsb_release -irs && uname -r && free --human --giga) | clip" The problem is/was two-fold, when I didn't do the echo $() it wasn't capturing the stdout of all comman...
Use a subshell: alias bug="(lsb_release -irs && uname -r && free --human --giga) | clip" This will send all three commands’ standard output to clip, without processing whitespace. Both aliases can be combined: alias bug="(lsb_release -irs && uname -r && free --human --giga) | xclip -selection clipboard -in" I wouldn...
how can I "pipe" all of these to xclip preservering newlines
1,676,672,757,000
Is there any way to have screen sessions that aren't visible via screen -ls command? If so, then what's the access method to these screens? Any screen that is created by a screen -S <Name> will be shown in the output of screen -ls.
These locations mentioned in man screen could be of interest: $SCREENDIR/S-<login> /local/screens/S-<login> Socket directories (default) /usr/tmp/screens/S-<login> Alternate socket directories. Example: % mkdir foo; chmod 0700 foo; % SCREENDIR=$PWD/foo screen -S foo -d -m sleep inf % screen -ls No Soc...
Creating hidden screen sessions which are not visible via "screen -ls" command
1,676,672,757,000
I have a folder with markdown files containing text with citekeys in the Pandoc format [@Name:2021]. I decided to remove the colons from my citekeys and would like to automatically delete them in my markdown files. The citekeys can have the following form: [@Name:2021] [@Name:2021, 10] [@Name:Title] [Vgl. @Name:2021] ...
perl is handy here: the replacement part of s/// can be evaluated as code: perl -pe 's/\[[^]]*@.+?\]/ ($cite = $&) =~ s{:}{}g; $cite /ge' file outputs [@Name2021] [@Name2021, 10] [@NameTitle] [Vgl. @Name2021] [Vgl. @Name2021, 20--30] If you're happy with the output, you can save the changes back to the file with per...
Remove certain character within a pattern of text
1,676,672,757,000
I have a directory AllData with some files like below: AllData |____ file_1to1000.track |____ file_1001to2000.track |____ file_2001to3000.track Based on file names I created directories with file names. for file in *; do dir=$(echo $file | cut -d. -f1); mkdir -p $dir; mv $file $dir; done And I wanted to create an...
Check: for file in ./*; do echo mkdir -p "${file%.*}"/cuffcompare/ && \ echo mv "$file" "$_"soft.track done to liner: for file in ./*; do echo mkdir -p "${file%.*}"/cuffcompare/ && echo mv "$file" "$_"soft.track; done Note: Remove echo at above when you were happy with dry-run result. ${file%.*} strips the ...
How to create multiple directories based on file names and change the file names in linux?
1,676,672,757,000
I have written a simple script to analyse BED files (a text file format used to store genomic regions as coordinates and associated annotations. The data are presented in the form of columns separated by spaces or tabs.) and in one of my arguments I have used awk. The problem is that my second variable of my script $2...
The problem here is that the shell is expanding $2 and $3; to avoid that, use single quotes: cat "$2" | awk -F"\t" 'BEGIN{SUM=0}{ SUM+=$3-$2 }END{print SUM}'
Conflict with the fields $ while using awk in my script
1,676,672,757,000
I'm more and more getting into trouble with my Debian 32 bit system, since some software such as the signal messenger are not written for 32 bit anymore. Operating System: Debian GNU/Linux bullseye/sid Kernel: Linux 5.8.0-2-686-pae Architecture: x86 I am not sure if this 32 bit system was installed rath...
You can run these commands, if x86_64 and 64-bit, the answer would be yes: $ lscpu | grep Arch Architecture: x86_64 $ lscpu | grep mode CPU op-mode(s): 32-bit, 64-bit From 32-bit, 64-bit CPU op-mode on Linux lscpu is telling you that your architecture is i686 (an Intel 32-bit CP...
Detect if the computers hardware is capable for a 64bit system?
1,676,672,757,000
I need to test whether any process is listening on a specific socket; fuser does not exist on the target system but lsof does. I run this command: lsof -tU /path/to/socket It lists the PID of the listener, which is great but lsof exits with a status of 1. I change the command to see what's wrong: lsof -tUV /path/to/s...
If you're on a system with a recent version of ss (like that from iproute2-ss190107 on Debian 10), you can use ss instead of lsof: sock=/path/to/socket ino=$(stat -c 'ino:%i' "$sock") && ss -elx | grep -w "$ino" sock=/path/to/socket if ino=$(stat -c 'ino:%i' "$sock") && ss -elx | grep -qw "$ino" then # yeah, someb...
How do I get lsof to stop complaining when testing for a socket?
1,676,672,757,000
My ps command works except on a particular version on Linux as you can see below. [root@failinghost ~]# ps -xef | grep -v grep | grep websphere Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ [root@failinghost ~]# ps -version ERROR: Unsupported SysV option. ********* simple selection ***...
You might not need x, -e is sufficient to select all processes: ps -ef This should work on any version of ps on Linux you’re liable to come across. Current versions of ps from procps-ng interpret the x option with or without a dash without warning; the older version of ps from procps in CentOS 6 adds a warning (but i...
ps does not support the -x flag on a particular version of linux
1,676,672,757,000
I see this command advised, whenever a person asks online about renaming all uppercase files to lowercase: find "$(pwd)" -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \; I understand the find "$(pwd)" -depth -exec rename part. Can someone breakdown and explain the regex command of rename - namely: 's/(.*)\/([^\...
The first s/, the last / and the unescaped / in the middle are the substitute operator and the separators, so we have the pattern (.*)\/([^\/]*) and replacement $1\/\L$2. In (.*)\/([^\/]*) the first (.*)\/ matches everything up to the last slash, that is, the path before the final filename. The last ([^\/]*) then matc...
What does \L$2 mean in perl rename tool?
1,676,672,757,000
I use ssh -p 54321 [email protected] to login a gate server and then ssh johnaddress to login the actual GPU server, now how do I combine these 2 commands in one using -J? ssh -J -p 54321 [email protected] john@johnaddress doesn't work ssh -p 54321 [email protected] -J john@johnaddress doesn't either
man ssh_config shows the syntax for the ProxyJump configuration parameter (which -J is a shortcut to): ProxyJump Specifies one or more jump proxies as either [user@]host[:port] or an ssh URI. In your case it becomes: ssh -J [email protected]:54321 john@johnaddress or, using the configuration file's option format: s...
ssh jump through a port
1,676,672,757,000
The following commands work % DEBUGCLI=YES exec zsh % set -xv % echo debug echo debug +zsh:2> echo debug debug However, when I try something like % exec zsh -c 'set -xv' It just close the terminal. I do not want to use exec zsh -xv. The reason is here. I am looking for one command instead of two so tha...
zsh -c 'set -xv' tells zsh to run an inline script that contains set -xv. After running set -xv, the script is finished and zsh exits (with the exit code of set). Just like zsh -c uname runs uname and finishes. exec zsh ; set -xv tell the current shell to execute zsh in the current process, so whatever command that la...
execute `set -xv` after invoking a new shell
1,676,672,757,000
I am using Ubuntu 16.04, but I believe my question applies to many distros, such as Debian, CentOS, and Red Hat. The manpage for netstat -l is: Show only listening sockets. (These are omitted by default.) and netstat -a is: Show both listening and non-listening sockets. With the -- interfaces option, show interfa...
Regarding the 2nd part of your question, netstat -plantu will show you only tcp and udp info, that is network connections established and listening ports. netstat -a will show you unix sockets also. That's lots of info, it's better to target what you need on the output. If you run a recent distro, you can use ss inste...
Does netstat -l include anything that netstat -a does not have?
1,592,644,129,000
I have a program that must work forever until kill -HUP command. But sometime this program can exit with an error code or it can be killed by OS for overusing memory. Is there any standard linux command which can monitor any command and restart them on exit? Something like this: forever my-command -with some parameter...
This is a SystemD unit file which would restart the command until it is killed by SIGHUP. If the program shall be allowed to exit with a success exit code then use Restart=on-failure instead. [Unit] Description=A program [Service] Type=simple ExecStart=/path/to/my-command -with some parameters Restart=always # Restar...
Is there a linux command which can work as forever: restart my programm if it exits with error code
1,592,644,129,000
I've just noticed that sending a foreground process to background with Ctrl-Z sets the $? variable to a non-zero value. Why is this the case? This behavior is bothering me, because I wanted to have a terminal prompt which changes color when a command errors, and I did this following this answer. However, this also me...
(assuming bash) Ctrl-Z does not send a process to background (as bg %JOB_NUMBER would), it suspends it. In order to do that a SIGSTP signal is sent to the process (you can do it yourself with kill -SIGSTP PID). SIGSTP is signal 20. The return value you see is 148, or 128 + SIGSTP. So, you should change the code in tha...
Why does sending a process to background set $? to a non-zero value? [duplicate]
1,592,644,129,000
when I run something like - # ss -atur I get lot of replies of opened ports such as - udp UNCONN 0 0 0.0.0.0:631 0.0.0.0:* udp UNCONN 0 0 0.0.0.0:mdns 0.0.0.0:* ...
The ss command provides an option to map ports to their corresponding processes: -p, --processes Show process using socket. The output will then contain an additional column, which maps each listed port to a specific process ID.
is there a way to map a port to an application or service?
1,592,644,129,000
I want to write a one line command line that Pings google.com non stop When the ping timesout (lost connection), echo an error message on screen
Using curl or ping but I'm not sure why do you want to do this. while curl -Lsf google.com >/dev/null || { printf 'Lost connection!' >&2; break; }; do :; done while ping -c 1 google.com >/dev/null || { printf 'Lost connection!' >&2; break; }; do :; done
How to write a one line command line that checks for internet downtime?
1,592,644,129,000
What I want to do is connect my PC to my terminal a DEC vt320 and be able to output the Linux console to it and for me to be able to type commands into the terminal and for it to send a reply on the screen. I wanted to connect to stuff from telnet but I don't know how to do it through serial. my serial connection is /...
It looks like Mint 19.3 uses systemd, so unless Mint has modified the systemd configuration from what the parent distributions (Ubuntu and ultimately Debian) have, the following commands should do the job. To start up a serial port for terminal-style login access immediately: sudo systemctl start serial-getty@ttyS0 ...
send linux console through serial
1,592,644,129,000
I have this CSV file: "mikecook1966","6days","","Classy1","7/2020" "kyndrion","1min","","Doominator handle","7/2020" "Ataca","Feb2,2020","","Soporte 30.5x30.5 VTX-DVR Speedy Bee","7/2020" I would like to leave in output results, where column 2 contains 2020. Example output: "Ataca","Feb2,2020","","Soporte 30.5x30.5 ...
If your CSV doesn't include escaped double quotes, you can use grep: grep '^"[^"]*","[^"]*2020' file.csv For more complex CSV, a CSV-aware tool is needed. perl -MText::CSV_XS=csv -e 'csv( in => "file.csv", filter => { 2 => sub{ /2020/ } } )'
Delete line fromo CSV file where columns is not specific string
1,592,644,129,000
I am running a python program via cron that runs every 1 minute. Occasionally, it will eat up a lot of CPU and I need the next cron job to not run if that's the case. I am trying if (( `~/cpu_usage.txt` < 60 )); then `cd /path/to/program && python myfile.py 100`; fi myfile has a print bob_here in the file and that ca...
Just lose the ticks and provide the full path to the python interpreter: if (( `~/cpu_usage.txt` < 60 )); then python /path/to/program/myfile.py 100; fi You don't need the ticks as the shell will execute the command following the then keyword as designed; the ticks will launch a sub-shell and the result/output is the...
execute an if statement via commandline
1,592,644,129,000
It is possible to pass resources to X applications in command-line by appending them with -xrm parameters. So, if I want Xmessage background to be grey, I can issue xmessage Hi -xrm "xmessage*background: grey". Things get tricky if I want to modify event translations. On my .Xresouces, this Xmessage*Translations:#over...
You need to put in single quotes : xmessage Hi -xrm 'xmessage*Translations:#override\ <Key>F10:exit(-1) \n\ <Key>q:exit(-1)' Otherwise, newlines get lost.
Trouble passing Translations resource to -xrm because of newlines
1,592,644,129,000
I'm going through the Linux From Scratch project and I want to verify each of the programs and libs are created properly before I move on from each step. (I searched here and google but pretty much everything I can find is regarding questions about echoing a var declared in the same line or dumping the output of ls to...
Expansions are performed before variable assignments, and command execution comes after. Use brace expansions instead, like ls -ld /tools/{lib,bin}/tcl*
Why does ls not recognize this declared single-line variable?
1,592,644,129,000
I have a python script that takes a path where a bunch of text files are located to process them somehow. Since there are too many files I want to use batches using a bash script to pass just some of the files on the path, say 100 at a time. Is there a simple way to do this. So for example my scripts is currently pyt...
With GNU xargs and a shell with process substitution support (ksh, bash, zsh), you can do: xargs -r0 -n100 -a <(printf '%s\0' ./*) python application.py -fp Example: $ xargs -r0n4 -a <(printf '%s\0' {1..20}) echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Without process substitution, you can also do: printf...
Bash: pass batches of files to python script
1,592,644,129,000
I have a document and I want to remove all the patterns so that I stay with only some information, the producer/creator of that document. I managed to replace patterns with one word "PATTERN" so that it becomes easy to remove them. How can I remove this word? Here are the commands I used: $ cat /path | tr \n \f | \ ...
Try the following: sed -i -e 's/PATTERN//g' filename From man page: -i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if SUFFIX supplied) -e script, --expression=script add the script to the commands to be executed
How can I remove patterns using sed command in a file?
1,592,644,129,000
as a newbie to linux kernel and all the commands, I am reaching out to you guys, hoping you can help me solve my issue. When running the next command sudo dmidecode -t 5 I get the following output: # dmidecode 3.0 Getting SMBIOS data from sysfs. SMBIOS 2.4 present. Handle 0x0084, DMI type 5, 46 bytes Memory Controlle...
This will list the supported speeds: dmidecode | awk '/^\t[^\t]/ { speeds = 0 }; /^\tSupported Speeds:/ { speeds = 1 } /^\t\t/ && speeds' This works by matching lines as follows: lines starting with a single tab mean that we’re not expecting speeds; lines starting with a single tab followed by “Supported Speeds:” me...
Filter dmidecode memory controller for supported speeds
1,592,644,129,000
I have a file.txt for example (it does not have the same number of columns for each row): 1 2 3 4 5 5 6 7 7 7 7 9 10 I have another file (file2.txt) that contains 2 columns a b c d e f I use this command: awk '{print $1,$(cut -f2 file2.txt)}' file.txt > final.txt I want to take the second column of fi...
Pure awk: awk ' FNR==NR{c[NR]=$2} FNR!=NR{$1 = $1 OFS c[FNR]; print} ' file2 file Output: 1 b 2 3 4 5 d 5 6 7 f 7 7 7 9 10
Putting a command inside awk to merge columns of different files
1,592,644,129,000
I am asking if there is a way to automatically put the output of a command into the middle of another. multimon-ng outputs: ZCZC-WXR-TOR-029037+0030-1051700-KEAX/NWS and i want that output to get sent to where i put three question marks : python2.7 easencode.py -z ??? output.wav can i do this with pipe and if so, how...
try python2.7 easencode.py -z $(multimon-ng) output.wav if you are in bash. $( ) construct will execute command and insert result (stripped of end of line) in current command. as per comment, you might whish to use "$( )" depending of expected result and importance of space.
Is it possible to put the output of one command into the middle of another [duplicate]
1,592,644,129,000
I'm in the terminal emulator. I want to open another terminal to run a specified command. gnome-terminal -e "zsh -c 'pwd; zsh;'" That runs pwd and zsh consecutively and successfully in another terminal. After pwd terminates, zsh launches and I can run other commands in that second terminal instance. However, when...
I tried this in bash Apologies in advanced if it does not work. I wrote a bash script named userInput.sh - this waits for user input and ends. ` ## trap ctrl-c and call ctrl_c() trap ctrl_c INT function ctrl_c() { echo "** Trapped CTRL-C" exit } read -p "Press any key to continue... " -n1 -s Now, when I run a...
How can I open terminal and run command automatically?
1,592,644,129,000
Concept: a terminal pager, like less for example, that interactively "folds" and "unfolds" the input file (as in emacs outline mode). Folded, a recursive directory listing might show only the directory names. Unfolded, it would show the full contents. As another example git log | pager might allow the user to toggl...
Put this in an executable file named "pager": #! /usr/bin/env bash TEMP=/tmp/file-$$.txt trap "rm -f $TEMP" EXIT HUP INT TERM echo '-*- outline -*-' > $TEMP cat "$@" >> $TEMP emacs $TEMP 0<&1 The initial line of the temporary text file arranges for emacs to enter outline mode. Then cat appends the zero-or-more spec...
Folding terminal pager
1,592,644,129,000
I am creating a file via this command: awk '{print $2 " "$7" "$8}' REACTOME_EXTENSION_OF_TELOMERES.xls | awk '$8!="No" {print $1 " " $2}' | awk 'NR>1' | awk 'BEGIN { OFS=", "; print "Name" " " "0" };{ print $0 " " "" }' The output is this: Name 0 WRAP53 0.08495288 NHP2 0.17606254 POLA1 0.25320756 POLD3 0.323...
Your entire awk pipeline can be replaced by awk 'NR > 1 && $8 != "No" {print $2, $7 - prev} {prev = $7}' REACTOME_EXTENSION_OF_TELOMERES.xls which outputs WRAP53 0.0849529 NHP2 0.0911097 POLA1 0.077145 POLD3 0.0705168 PRIM1 0.0576833 RFC5 0.0616153 POLD1 0.0546261
How to subtract every adjacent line from the 2nd column and keep the first one