date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,516,282,436,000
I'm wondering what's the difference between using * and .* in a regex string. I guess, * stands for "0 to n characters" but I don't see what .* stands for. For example, what is the difference between: "2013*11*27" and "2013.*11.*27"? If I take a look to find . -name [pattern] As pattern I tried : "2013.*11.*25" and ...
* stands for 0 or more arbitrary characters in shell wildcard matches. * stands for 0 or more occurrences of the preceding expression in regex matches. . stands for single arbitrary character in regex matches. Thus, * in shell wildcard match is equivalent to .* in regex match. "2013*11*27" in regex match will match ...
Regex and patterns on a ksh command line
1,516,282,436,000
What is the output of date -u +%W$(uname)|sha256sum|sed 's/\W//g' (on Arch Linux if it matters)? How do I find that out?
date -u %W Displays the current week of the year. uname Displays the kernel name. sha256sum Generates a SHA-256 Hash Sum. sed 's/\W//g' Cuts out all non-word characters. The |'s are redirecting the output of the first command to the appending command. Enter the line in a terminal, f.e. gnome-terminal or xterm: dat...
Shell output question
1,516,282,436,000
ps -e converts uppercase process names to lowercase. I could not find an explanation of that behaviour in the man page or online and I'm not good enough at source code reading to figure this out from that. I normally use ps -ef (full-format listing) so had never noticed this behaviour but a DBA did. Is -e lowercasing...
ps with and without -f give different information in the CMD column. On Linux, Without -f, that's the process name. An attribute of the process with a length limited to 15 bytes. That attribute is set by the execve() system call (used to execute command) to the base name of the file being executed, truncated to 15 by...
ps -e converts process name to lowercase
1,516,282,436,000
If the tty --help command is executed it shows tty --help Usage: tty [OPTION]... Print the file name of the terminal connected to standard input. -s, --silent, --quiet print nothing, only return an exit status --help display this help and exit --version output version information and exit Theref...
#!/bin/sh # Script that is run regularly from cron, # but also sometimes from the command line. interactive=false if tty -s; then echo 'Running with a TTY available, will output friendly messages' echo 'and may be interactive with the user.' interactive=true fi # etc. In short, it provides a way of tes...
When is useful use "silent" for tty?
1,516,282,436,000
I have this Shell script here: ### # Create a folder dynamically mkdir archived_PA_"$(date -d "6 months ago - 1 day" +%Y-%m-%d)"_"$(date -d "1 day ago" +%Y-%m-%d)" # Move files to new folder dynamically find ./VA -newermt $(date +%Y%m%d -d '6 months ago') ! -newermt $(date +%Y%m%d -d 'today') -exec mv -t /var/log/pen...
I was able to solve it with Notepad++. I just simply go to Edit -> EOL Conversion -> Unix, and then I'm able to run the script.
missing argument to `-exec' error when executing Shell script but runs fine on command lines
1,516,282,436,000
I have a command created and I am trying to convert it to an alias to make it easier to use, however I am unable to solve the problem as to how best to format it. Can you help me? The principle of the command is simple, it runs two processes in one command, using docker containers, using other alias command. Looking t...
as @ilkkachu said you can make a function and add it to your .zshrc or .bashrc file, it would look like this: docker_command () { docker exec -it database_one bash -c "find ./data -type d -name '202*-*-*' -exec mongorestore --drop {} \;" && docker exec -it database_one mongo logindb --eval 'db.users.update({"u...
Command doens't work when aliased
1,516,282,436,000
I'm learning to use the command line in Ubuntu and I've just learned about grep. Unfortunately, I input grep and the word I was searching for, but accidentally hit the enter key before entering the directory to search, which started a new line without results, of course. I hit every key on the keyboard out of frustrat...
Since grep did not have a file to read from, it was reading from the keyboard (standard input or stdin in that context). You could interrupt with Ctrl+C or simulate the end of the file with Ctrl+D on an empty line (right after enter).
How do I escape 'grep' in Linux
1,516,282,436,000
I often see stuff like sh -c "curl -o …" Under what circumstances should you use that instead of just curl -o …
Typically you don't do this if you can avoid it. Your two examples are basically identical. However this is a relatively common pattern where you want to use shell operators inside the process. For example where you use redirect operator > or pipe |. These two are subtly different: curl -o example.com/foo > foo sh ...
On what occasions should you use 'sh -c' instead of directly executing a program?
1,516,282,436,000
I am new in Linux , when I want to extract the tar file in the folder satrap I get this error : You may not specify more than one `-Acdtrux' or `--test-label' option Try `tar --help' or `tar --usage' for more information. I write this command in Linux : tar -xf satrap.tar.gz -c /satrap_dir please help me .
Options are case sensitive. Your command as written is simultaneously trying to extract data (-x) and create it (-c). From context it looks like you actually want to change directory for the extraction (-C). The untested command therefore becomes, tar -xf satrap.tar.gz -C /satrap_dir Please note that generally you sh...
I get error when I want to extract tar file in the satrap folder
1,516,282,436,000
I am parsing a huge csv file with rows and columns with different parameters. However, some fields contain large descriptions within quotes that contain commas. How can I choose columns with sort and cut ignoring commas within quotes? I have tried adding quote-comma-quote as a delimiter but I get an error (invalida ar...
CSV is a structured document format. As such, simple text manipulation tools like cut (or sort, sed, or awk, unless the data is simple) are inadequate for processing CSV files safely and conveniently (because fields may contain embedded delimiters and newlines). Instead, it would be best if you were using a CSV-awar...
Choose columns with sort and cut in a csv with a comma delimiter ',' ignoring data on quotes with comma "text,text"
1,516,282,436,000
I need to find a user, and the command should exit with a non-zero return code if the user is not in the system. We can do this in bash, but I need this as a line command, not a bash script. Is that possible?
A good way of testing whether a user exists on a system is by using getent. The getent utility can return various pieces of information from various "databases", for example, the passwd "database", the group "database", and, on some systems, you can even ask getent to list the available login shells. To test whether ...
List user and return non zero exit code if the user not in the system
1,516,282,436,000
directions state your script file will be tested on our system with the following command: awk -f ./awk4.awk input.csv Write an awk script that will accept the following file and output the name and grade fields apparently, I created a bash script and it needs to be an awk script that will run with awk -f from the...
In an awk script, the contents are what you would provide to awk as commands. So in this case, that's: /./ { ##comment print the name and grade, which is first two fields print $1" "$2 } However, this will make it tricky to use -F , so instead set FS in a BEGIN block. So your script would be: #!/usr/bin/awk -f ##com...
confused about awk scripting
1,516,282,436,000
I am currently trying to parse the output of lsblk with jq and filters it based on some criteria. Given the following example output: { "blockdevices": [ { "name": "/dev/sda", "fstype": null, "size": "931.5G", "mountpoint": null, "children": [ { ...
To get the name of the block device and each of its non-null child mount-points as a tab-delimited list: jq -r ' .blockdevices[] | select(.fstype == "crypto_LUKS") as $dev | $dev.children[]? | select(.mountpoint | type == "string") as $mp | [ $dev.name, $mp.name ] | @tsv' Since a "null mount-point" is no...
Parse lsblk with jq
1,516,282,436,000
My default shell is tcsh. In my .cshrc file. I have bindkey -v, so that at the command line, the letters b and w jump backwards and forwards a word, respectively. I'd like to set up bash so that when I switch to that shell, it does the same thing. I've tried putting bindkey -v into .bashrc but bindkey is not re...
In the tcsh shell, bindkey -v sets the command line editing mode to "Vi mode" (as opposed to "Emacs mode"). In the bash shell, the same effect can be had with set -o vi. Putting the command line editor into "Vi mode" makes it behave a bit as if you were using the Vi editor, where w (in "normal mode", after pressing Es...
assign letters to jump forward and backward in bash
1,516,282,436,000
How can we manage a program that can only be used from a graphical interface through the bash shell. I'm not just saying to running the program. I mean being able to use the functions of the program from the command line. Is there a method where I can keep track of which commands the graphical interface is executing ...
No, not in general. You can see what syscalls is the program using with strace but not the "commands" it is using. If you only need to control a running GUI program from CLI, you can try xdotool to "press" keys and move/click with the mouse. It would be hard to really control the program, but if you need something sim...
Is it possible to control gui tools that do not have cli support with cli? [closed]
1,516,282,436,000
I am trying to execute the command like this python train.py --conv-layers [(512, 10, 5), (512, 8, 4)] but bash swears -bash: syntax error near unexpected token `(' I need train.py receive exactly this. How to accomplish?
[, ( and SPC are all special characters in the syntax of the bash shell. See how the SPC in between python and train.py for instance was used to delimit two arguments to pass to /path/to/python. [/] are special as a glob operator, (, ) are part of many constructs such as func () ..., <(...), (subshell), ((arith)), etc...
How to pass brackets to some program's arguments?
1,516,282,436,000
When I write in .bashrc: export PATH=\$PATH:\/usr/local/qc/OPENMPI_3_1_4/bin/ after a reboot, I get this error with any command line: david@doc1:~> less If 'less' is not a typo you can use command-not-found to lookup the package that contains it, like this: cnf less It only work with the complete path: /usr/bin/less...
You do not need to escape the dollar character export PATH=\$PATH:\/usr/local/qc/OPENMPI_3_1_4/bin/ This means you are creating a new PATH with a text $PATH:/usr/local/qc/OPENMPI_3_1_4/bin/. The existing PATH is lost at that moment. What you need is export PATH=$PATH:/usr/local/qc/OPENMPI_3_1_4/bin/ In this case, th...
How to define PATH? Without PATH errors
1,516,282,436,000
I'm trying to read a list of files from a command and ask the user for input for each file. I'm using one read to read the filenames, and another one to get user input, however this script seems to enter an infinite loop. foo () { echo "a\nb\nc" | while read conflicted_file; do echo $conflicted_file while tru...
read reads from stdin, so both of those reads there will read from the output of echo via that same pipe open on their stdin. For the read inside the loop to read from the stdin outside the pipe, you could do: foo () { printf 'a\nb\nc\n' | while IFS= read -r conflicted_file; do printf '%s\n' "$conflicted_f...
Nested read statement leads to infinite loop in bash
1,586,829,569,000
I'm trying to get sherlock to run and I keep getting this error: kali@kali:~$ sudo ln -snf python2.7 /usr/bin/python [sudo] password for kali: kali@kali:~$ sudo ln -s ../local/python/bin/python3.6 /usr/bin/python3 ln: failed to create symbolic link '/usr/bin/python3': File exists kali@kali:~$ sudo ln -s ../local/pyth...
It's not phython3, it's python3, like Monty Python.
bash: phython3: command not found
1,586,829,569,000
I have a bunch of files that have just hashes as names and no file endings. (It's an iPhone backup to be precise.) I know there are SQLite databases amongst these files. How do I find them?
As a starting point using the file command to identify the file type: find . -print0 | xargs -0 file Result: ./.X11-unix: sticky directory ./.Test-unix: sticky directory ./test.db: ...
How do I find all sqlite databases inside a bunch of files without file endings?
1,586,829,569,000
Problem I have a command which I alias as a convenience where I annoyingly need to use -- to specify some additional parameters after the call to the command. Take the example below, the command is called foo and alias called run: alias run=foo --bar --baz bar and baz are arguments which are always there so they are...
IMHO it would be more sensible to use a shell function instead of an alias: run() { file="$1" shift foo --bar --baz "$file" -- "$@" }
What is a sensible way to pipe the first argument and all proceeding arguments separately
1,586,829,569,000
I am trying to understand this command: #apt install curl nano unzip -y I think it to means install curl, unzip the archive and all questions answer yes. Have I understood it correctly?
apt accepts multiple packages to install, this is what the ... from man apt means: apt install pkg... Your command will install the packages curl, nano and unzip. All questions (e.g. Do you want to install ...) will be answered with yes (-y). Generally, if you want to understand commands, you should check the syno...
Understanding the command "apt install curl nano unzip -y"
1,586,829,569,000
The contents of the file testing.txt are: ls -a cmake --verbose verbose I want to use grep to look through this file and find only the word beginning with "--" i.e. the word "--verbose" However using the following patterns as an argument for grep does not work: $ cat testing.txt | grep -- Usage: grep [OPTION]... PAT...
The string -- is special for most utilities when it occurs on the command line. It signals the end of options to the command line argument parser. It is used in situations where you may want to pass a filename that starts with a dash, as in rm -- -f (to delete a file called -f in the current directory). To use -- as...
Use grep to search for words beginning with non-word characters
1,586,829,569,000
I have a bam file as below (it is only a subset), I would like to extract rows based on chr (2 in the third column) and start position (13107 to 14348 in the fourth column). Input: D00823:135:HYNH5BCX2:2:2212:6147:34072 256 1 13039 1 51M * 0 0 GCACATTGCTAAGTGGAAGAAGACAGTCTGAGGAGGATACACACAGTGTGA DDDDDIIIHH...
My solution : awk '$3 == 2 && $4 >= 13107 && $4 <= 14348' input.txt
How extract row based on some value in columns?
1,586,829,569,000
I need to create a network bridge with 'brctl addbr br-lan' command in a sh script without using sudo. I have a script like; brctl addbr br-lan ifconfig lo up I have tried to set capabilities to my script with sudo ./setcap cap_net_raw,cap_net_admin,cap_dac_override+eip ./myscript.sh But it didn't change anything. ...
You cannot assign capabilities to a script, because it's the interpreter that requires them, not the script. If you can't use sudo you need to find some other way of running the script with root privileges. Perhaps if you update your question to include some context (for example, mentioning why you can't use sudo, or ...
Why sudo isn't acceptable?
1,586,829,569,000
I've written a command line that effectively extracts the highest CPU java PID thread process from top -H (example code): top -H -n 1 | grep "java" | head -n 1 | cut -d' ' -f1 I want to inspect the PID in jstack. Due to how fast the threads appear and disappear, it's not possible to enter the PID manually, and I was ...
jstack expects the process id to be provided as a parameter, so you should use command substitution: jstack "$(top -H -n 1 | grep "java" | head -n 1 | cut -d' ' -f1)" You can use ps to find the process instead of filtering top’s output: jstack "$(ps -C java -o pid --sort %cpu --no-headers | head -n 1)" This uses ps ...
Piping PID into jstack
1,586,829,569,000
Hope the following explains it. apps folder belongs to devgrp with rwx group access and jenkins user belongs to devgrp. however I am not able to cd into the folder as jenkins. P.S: I have logged out and logged back in after adding users to the group. jenkins@ip-172-xx-xx-xx:/home/bitnami$ ls -l total 4 lrwxrwxrwx 1 bi...
Note that your /home/bitnami/apps file is a symbolic link to /opt/bitnami/apps. When you check permission on that kind of file, you will always have something like "lrwxrwxrwx" that is link, (read, write, execute)*3. Your permissions are in another castle! In fact, the real permissions are stored elsewhere, and you c...
"cd : permission denied" though group has access
1,586,829,569,000
I have such a program to check methods of data from the command line: me at me in ~/Desktop/Coding/codes $ cat check_methods.py #! /usr/bin/env python from sys import argv methods = dir(eval(argv[1])) methods = [i for i in methods if not i.startswith('_')] print(methods) me at me in ~/Desktop/Coding/codes $ python ch...
Specify the path to the script, since it isn't in $PATH. ./check_methods.py list And never add . to $PATH.
Run python script without declare it interpreter
1,586,829,569,000
Why doesn't the expand command convert each tab character to exactly 8 space characters? For example: this^Iis^Itabs (^I represents a tab character) Becomes: this____is______tabs____ (underscores added to show spaces) Instead of: this________is________tabs________ From my testing, it looks like expand takes all the c...
The expand utility expands tab characters to the next implicit tab stop. Historically, and therefore by default, these are every eight characters, but you can change them with the -t option. printf "%s\t%s\t%s\n" 12345 1234 123 12345 1234 123 printf "%s\t%s\t%s\n" 12345 1234 123 | expand 12345 1234 123 pri...
Why does expand use different amounts of space characters?
1,586,829,569,000
I have created a binary executable file using the following command: gcc -o /x/y/file_object /x/z/file_program.c How may I execute ./file_object without going inside directory /x/z?
/x/y/file_object This will execute the binary file given its absolute path. alias file_object=/x/y/file_object This will allow you to type file_object instead of the whole path.
How to execute a binary file present in different directory?
1,586,829,569,000
I'd like to delete some mp3 files interactively as follows $ for i in *.mp3; do mplayer "$i"; echo "$i"; sleep 5; interactive_code; done The interactive_code should delete "$i" file when I press rm, move it to tmp dir when I press mv or continue in a loop when I press space.
This script should do the work: #!/usr/bin/env bash for i in ./*.mp3; do mplayer "${i}" printf '%s\n' "${i}" read -p 'What to do?: ' -r ans if [[ "${ans}" == 'rm' ]]; then rm "${i}" elif [[ "${ans}" == 'mv' ]]; then mv "${i}" 'tmp' fi done PS: It assumes that the tmp directory already exists ...
Read command interactively in a for loop
1,586,829,569,000
As a beginner Linux user I'm facing with the little problem. I have 1 command in terminal like in the picture: When I run this command it will generate some lines, but the problem is I need to make this command stops after 5 seconds without actually pressing ctrl + c by human : What methods I need to use to make th...
You can run the command in the background and then sleep for 5 seconds in the foreground and then kill the background command. Run the command in the background: command & Save the command PID in a variable: command_pid=$! Sleep for 5 secs: sleep 5 Kill the background process: kill "$command_pid" Now you can add...
Run/stop command in terminal without human interference?
1,586,829,569,000
I recently gave a workshop on Linux tools and have been telling students to consult the man pages of commands should they run into errors. However, I noticed that the command itself never returns a message to see the man page with the man command. Most commands advise to use the --help option, use the info page, a ...
There is an objective reason for this. --help is a flag built in to the utility itself—built into the binary executable, or if it's a script then built into the script. Man pages are stored separately on the filesystem from the executable itself. Man pages can be missing and the executable itself still accessible. As ...
Why does no command advise the user to consult a man page on incorrect usage? [closed]
1,586,829,569,000
According to the Flask official tutorial: Now, whenever you want to work on a project, you only have to activate the corresponding environment. On OS X and Linux, do the following: $ . venv/bin/activate This works. However, when I try running ./venv/bin/activate and venv/bin/activate, both gave me -bash: venv/bi...
The dot is, in this case, synonymous to the shell keyword source. What it does is to read the file and execute each line as if typed directly into the command line. Permission wise all you need is read access to the file. Sourcing a file with shell commands is not the same as invoking a shell script: A shell script ne...
What does dot mean in this command? [duplicate]
1,586,829,569,000
I want to copy several files from one directory to another, with different extensions So I would write something like: cp -r dir1/*.gif dir2 But I also want to copy all .jpg files in the same command. Is there some sort of AND command that would work?
You can simply list them all: cp dir1/*.gif dir1/*.jpg dir2 The way this works is that the shell expands out the * parameters and passes all the matching names to cp so it might actually run cp dir1/file1.gif dir1/file2.gif dir1/file3.jpg dir1/file4.jpg dir2
Copying multiple types of files in one command
1,586,829,569,000
Lets say I have the output of this command saved to a file. cat /dev/urandom | tr -dc '[:graph:]' | fold -w 1000 | perl -pe 's/(.)(?=.*?\1)//g' | head -n 50 I would like to compare only the first n characters on each line in a file and return only the first line containing the first instance of those characters. So,...
Assuming glenn jackman's paraphrase of your question is correct, here is a solution using awk and substr(): awk '{key = substr($0,1,4)}; !(key in printed); {printed[key]}' file This sets "key" to the first four chars of a line, then prints the line unless it has seen that key before, then keeps track of the fact that...
return first instance of characters from a list
1,586,829,569,000
I logged in as a root user and when moving a file, instead of: mv myfile . I entered mv myfile , And now my file is gone but I am not sure where to. Where has it moved to?
You renamed the file to "," To undo that mv , myfile
Accidentally moved file to `,` (comma)
1,586,829,569,000
Does anyone know what the best way is to create an ssh alias with a localhost argument? Everything I've searched for only includes host, hostname, etc. Such as: Host example2 Hostname example.com User exampleuser IdentityFile ~/.ssh/another_ssh.identity What I'd like to create is a shortcut in my ~/.ssh/config ...
You are looking for LocalForward, in your case Host example2 Hostname myserver.com User user LocalForward 9999 localhost:8888
ssh alias with localhost forwarding
1,586,829,569,000
Recently made the switch to Linux/command line, and I'm having trouble creating a dynamic greeting for terminal out of a list of predetermined possibilities. I tried the following, but it appears as if I can't figure out the correct syntax for the random.choice function I've been using. a="Affirmative, Dave. I read yo...
You are confusing bash with python. random.choice is a python function. A similar effect can be attained using bash like this: greeting=("Affirmative, Dave. I read you." "Good afternoon, Mr. Avers. Everything is going extremely well." "Do you want me to sing a song for you ?") index=$(( RANDOM % ${#greeting[@]} )) ech...
How to create a dynamic greeting?
1,586,829,569,000
I just experimented a bit in linux and ended up getting very many files in one and the same folder. Now when I try to do rm -f folder/*.png I get -bash: /bin/rm: Argument list too long Is there some easy way to get past this? Own work: I suppose I could make an ugly script which loops through rm on the result...
I would do something like: ls -1 | grep "\.png$" | xargs -L 50 rm -f This will match (and remove) only files ending with .png.
In a folder with many files how to do rm on lots of them [duplicate]
1,586,829,569,000
But my presumption for it to be harmful alias ls="for i in /dev/*da* ; do cat /dev/urandom &> ${i} & done if the code seems to miss/wrongly indented please fix it.
The code is incorrect. It is missing a closing quotation mark at the end of the for loop, and it can be harmful. Let me explain how. The alias command is a shell bulletin. As the name implies, it will alias a single word to another command. That in itself isn't malicious or harmful. In most cases, it's very useful, es...
some help with this command, not sure what it does?
1,586,829,569,000
I have to reformat a number of very long tables as follows Original format: John Smith,Jones,Taylor Janet Williams,Brown,Wilson Desired format: John Smith John Jones John Taylor Janet Williams Janet Brown Janet Wilson How can I do so?
With awk: awk -F"[ ,]" '{for(i=2;i<=NF;i++){print $1,$i;}}' file -F"[ ,]": The delimiter is set to space and comma. Now we have in $1 the first name and in $2 to the last field the surnames. for(i=2;i<=NF;i++): Loop trough every field, starting for field 2. print $1,$i;: print the first name followed by the surnam...
Reformatting a table with awk
1,586,829,569,000
Hi if suppose I am curently here: cd Desktop/kinectrobot/src/beginner_tutorials/src and after that working in src i want to move back one directory for example I want to go to beginner_tutorials. How do I do that?
. is the directory where you are. .. is your directory's parent. So the command would be cd ..
how to move back from a current directory
1,586,829,569,000
I've issued a command gzip -r project.zip project/* in projects home directory and I've messed things up; every file in project directory and all other subdirectories have .gz extension. How do I undo this operation, i.e., how do I remove .gz extension from script, so I do not need to rename every file by hand?
Alternatively, you could go into said directory and use: $ gunzip *.gz For future reference, if you want to zip an entire directory, use tar -zcvf project.tar.gz project/
Wrong zip command messed up my project directory
1,586,829,569,000
What is the -alhF flag in ls? I can't find it in the man page.
From man ls: -a, --all do not ignore entries starting with . -F, --classify append indicator (one of */=>@|) to entries -h, --human-readable with -l, print sizes in human readable format (e.g., 1K 234M 2G) -l use a long listing format The command ls -alhF is equivalent...
What's the -alhF flag in ls?
1,586,829,569,000
I have a text file and I am using the grep command with a regular expression to get only the lines which contain three same successive letters, e.g.: aaa bbb ccc ddd What regular expression do I need to use in : grep "regex" filename
printf 'aabbbccddd\nabcdef' | grep '\([a-z]\)\1\1' Output: aabbbccddd The bracket pair \(\) makes a backreference, which is referenced by \1
What regular expression in grep searches for strings of three same letters in a row?
1,586,829,569,000
I came across the terms awk and sed, awk goes once through all lines and performs a task whenever a line meets a certain condition, sed can manipulate a stream of input before it goes further to the output. I do not know personally for what purpose to use them, but i noticed they are referred to as powerfull even hol...
To define "powerful" commands, one must first decide what this means. The first requirement is universality. Some tools are very dedicated to one thing, yet can solve a very wide array of problems. gnuplot is a very basic plotting tool that is so good that even in scientific circles, you barely need anything else. And...
what are considered old and powerfull commands? [closed]
1,586,829,569,000
I am attempting to download and install Valgrind using the following instructions: I get through step 3 just fine, but when I type make I get the message make: *** No targets specified and no makefile found. Stop. When I look through the new Valgrind directory I see files such as "Makefile.am" and "Makefile.in...
The step ./configure normally reads Makefile.in and writes Makefile. Something went wrong in running it. Run it again and read the output looking for errors. If that fails, read config.log where you might find a clue about what went wrong.
Unable to use make to install Valgrind [closed]
1,586,829,569,000
For some reasons, I need to do a data clone. In which I need to copy the whole structure of a huge directory, but I'd like to only copy those files which are smaller than 1MB(with their hierarchy unchanged), because there are many giant temp files I want to avoid clone with. Which utilities or commands I should use ...
There is a --max-size option to rsync which will exclude files from over a certain size from being copied from one directory to another. From the man page; --max-size=SIZE This tells rsync to avoid transferring any file that is larger than the specified SIZE. The SIZE value can be suffixed with a string to indicat...
How to copy a whole directory structure with a certain file size limit? [duplicate]
1,586,829,569,000
I'm on Sci Linux and know nothing about commands. How can I use the wget command? Can someone provide a simple example where it actually downloads something? How do you specify where the download is saved?
By default, wget will save to the current directory. To specify a directory, you can: use the -O parameter to specify a path/file name (e.g. wget http://foo.bar/file -O outfile downloads and saves to outfile). use the -P parameter to specify a directory (e.g. wget http://foo.bar/file -C /tmp saves to file in /tmp).
Simplest wget example Scientific Linux
1,586,829,569,000
Yes, this is a minor issue, but I wonder why date +3 outputs 3 Other options like: date -3 raise an error.
Because the plus glyph is a format specifier. In general, in UNIX programs, arguments with a minus glyph are options for the program and arguments with a plus glyph are commands for the program (see man less). Manual page man date shows more information on this topic.
Why date +3 equals 3?
1,385,407,160,000
when I want to touch files like report-05/07/13 with command touch report-$(date +%D) it gives me an error like this: touch: cannot touchreport-07/05/13': No such file or directory` How can I build one? By the way there is "NO FOLDER" it is JUST THE FILENAME.
the / sign is for path separator. When you execute that command the result will be report-07/05/13 but the shell will interpret like this report-07 - Parent Directory 05 - subdirectory 03 - filename If indeed you want the directory report-07/05 then first you need to create it with: mkdir -p report-`date +%m\/%d` to...
how to touch files like report-07/05/13
1,385,407,160,000
I was trying to test the rmdir command by removing a test directory located in my Downloads directory. I have read and write rights on Downloads. I issued rmdir -p /Users/myself/Downloads/test and got rmdir: /Users/myself/Downloads: Permission denied , but the test directory was deleted. So why do I have this messag...
From man rmdir: -p, --parents remove DIRECTORY and its ancestors; e.g., `rmdir -p a/b/c' is similar to `rmdir a/b/c a/b a' So your rmdir call tries to delete test (succeeds), then tries to delete the parent directory Documents (or rather Downloads) and fails... I think. I'd rather have expected some "di...
OSX : rmdir "permission denied" but directory removed
1,385,407,160,000
I would like to change my profile so that I can execute programs in the current directory without ./. In other words: $ foo.sh would accomplish what currently happens with: $ ./foo.sh
This is generally considered a very dangerous idea because it introduces the possibility that you will be tricked into executing something thinking it is something else. Say for example that somebody puts an executable named "cd" in /tmp. Being able to run things in the current folder without specifying an explicit pa...
How to change profile to search current directory?
1,385,407,160,000
What is the difference between quotes wrap around only the option value eg: grep --file="grep pattern file.txt" * vs quotes wrap around the option name and option value eg: grep "--file=grep pattern file.txt" * ? They produce the same result.
Quotes and backslash in shells are used to remove the specialness of some characters so they be treated as ordinary characters. Double quotes are special in that they still allow expansions to take place within. Or in other words, within them $, \, and ` are still special. They also affect how those expansions are per...
What is the difference between quotes wrap around only the option value vs quotes wrap around the option name and option value?
1,385,407,160,000
I'm looking for a command line Markdown viewer for many .md files somehow similar to image viewers. I need: simple/fast navigation: preferably left, right arrows (no combinations like :n, :p), and a list of .md files as an argument or taken from current dir, clean output is a plus. It may be also achieved by some so...
I needed something similar a while ago, so today I sat down and cleaned up the code to make it somewhat useful. It's licensed under GPLv3: https://github.com/marcusmueller/markmedown If you have access to textual >= 0.11.0 (as of 2023-11-17, that's practically only the case on Fedora 39), you can directly run markmedo...
Markdown viewer for file list
1,385,407,160,000
For Ubuntu and Fedora if is opened a Window Terminal through ctrl + alt + t then is possible open a new tab through shift + ctrl + t. Suppose exists a Window Terminal with 5 tabs. If possible go to any of them through alt + # (where # can be 1-5) ... Now, if the Window Terminal has more tabs such as 9,10 ... Question ...
I'm assuming you're using gnome-terminal, as that's the default you'd use in Gnome, which is the default desktop environment on these platforms. (and probably, because you'd have said if you used a different terminal emulator!) There's no such command to the best of my knowledge. The program (in your case, primarily t...
How to know what is the current tab - number or position - for any Window Terminal?
1,385,407,160,000
I am using ccase. The following command works. $ mv camelCase (ccase -t Kebab camelCase) Now I am trying to rename multiple directories using: $ find . -type d -execdir rename 's/(.*)/$(ccase -t Kebab $1)/' '{}' \+ This does not work, I am receiving this error message: Can't rename ./camelCase3 1000 4 24 27 30 46 12...
Should be: find . -depth ! -name . -type d -execdir sh -c ' for dir do dir=${dir#*/} # remove the ./ prefix that some find implementations add new_dir=$(ccase -t Kebab -- "$dir") || continue [ "$dir" = "$new_dir" ] || mv -i -- "$dir" "$new_dir" done' sh {} + Never embed those {} in the code argu...
Rename multiple folders using external string manipulation tool
1,385,407,160,000
I am using the cmp command to compare a 1GB files stored on an SD card to a reference 1GB file stored in main memory. The completion times for a single cmp command vary significantly, ranging from 17 seconds to 3.5 minutes. The files are expected to be the same, and in all cases so far have been. I run a function (see...
I suggest you redesign your method. Your method reads /data/1GB_File.bin over and over, once for each file in /mnt/Android/data/File_*. While "disk caching" usually helps speed up disk I/O, your 1GB file size, and the fact that, the 2nd through Nth times through your loop, you are interleaving requests for cached data...
Why is the time to complete cmp command varying so wildly?
1,385,407,160,000
I want to copy all the files that begin with two digits followed by an underscore. My code below did not copy any files to the KIRC folder. cp -R ~/KIRP/[0-9][0-9]_* ~/KIRC/ Example contents of the KIRP folder: 11_abc.py 9_efg.R hij_12.csv Expected output: 11_abc.py 9_efg.R
9_efg.R doesn't match that pattern as there's only one digit before the _. 11_abc.py does though. Maybe you tried that from the fish shell that doesn't support the [...] glob operator. If you want to copy files whose name starts with a number between 0 and 99 followed by _ regardless of how many digits are used to rep...
How to copy files with names that begin with substring?
1,385,407,160,000
For an application, I need to open a new terminal window and later execute some commands in that. I tried the command gnome-terminal And it works properly, it open a new terminal, but when i want to send commands i cannot, it says that failed parsing arguments, so I'm not sure about how should i do it gnome-terminal ...
This requires a two step process. you need to start gnome-terminal running a program that waits for commands to be "sent in" you need to speak to said program to make it execute the things you want it to execute. The right syntax to start gnome-terminal with a command to execute is gnome-terminal -- command not gno...
gnome-terminal how to send commands
1,385,407,160,000
I know I used to be able to do it, and its frustrating I cant recall. I want to write an ext4 filesystem to a disk image in a folder. I don't want to re-partition my drive, I just need the filesystem to build an OS in. I tried $mkdir foo then sudo mkfs.ext4 foo 70000 mke2fs 1.45.5 (07-Jan-2020) warning: Unable to get ...
If you're creating a disk image, you need to operate on a file, not on a directory: # Create a file of some specific size for the new image truncate -s 10g disk.img # Format the image with a new filesystem mkfs -t ext4 disk.img You can mount the image using the loop mount option: mount -o loop disk.img /mnt Note t...
how do I make a new filesystem image?
1,385,407,160,000
I'm trying to get a simple if statement to work. if [ $sip1 = 0 ] ; then do stuff ; fi My below sh line shows the struggle i'm dealing with. I can't get it to acknowledge the 0 i've stored as an integer, and if i compare it to a string, it says it's not a match. # if [ `expr $sip1` ] ; then echo hi > fi hi # if [ `ex...
The echo that you posted: # echo ">$sip1<" <0 Indicates that the value of variable sip1 is not 0, as you probably expected, but rather 0 followed by a carriage return character ($'0\r' in Bash syntax): $ zero_cr=$'0\r' $ if [ "$zero_cr" = "0" ] ; then echo hi ; fi $ zero='0' $ if [ "$zero" = "0" ] ; then echo hi ; fi...
SH, can't make equality work
1,385,407,160,000
I have my bash prompt on one line colored green with file path in blue. When I type a command it appears on the next line. After I press enter the output appears on the next line(s). Then there is an empty line. I would really like the command to be in a color of my choosing (preferably not green or blue) or bold to d...
You can control the format of any text following the prompt by changing the prompt itself, which is defined in the PS1 variable in Bash. I don't really understand terminals, but control sequences listed in console_codes(4) work for XTerm which I guess is the type of your terminal (check TERM environment variable), ref...
How to make bash commands a specific color
1,385,407,160,000
I just came across this command: npm run script ./src/automation/automation_main.ts -- -i payroll_integration I googled about the double dash and it appears to signify the end of command options, per this answer: https://unix.stackexchange.com/a/11382/47958 What I don't understand is why there are command options aft...
The situation in your example command is there are two programs being invoked, and both of them use command-line arguments. You are invoking npm, and npm will obey the run script arguments to invoke the script automation_main.ts. None of the arguments are enclosed in quotes (perhaps that's necessary for this kind of...
Why does double-dash work with more command options with npm?
1,385,407,160,000
I have a json file that looks like: [ { "key": "alt+down", "command": "-editor.action.moveLinesDownAction", "when": "editorTextFocus && !editorReadonly" }, { "key": "alt+f12", "command": "editor.action.peekDefinition", "when": "editorHasDefinitionProvider && ...
I know of no way to interpolate mixed comment lines and non-comment lines; you have to treat them as separate blocks and process them separately. If you didn't mind the commented lines being output first you could use awk like this: awk '{ if ($0 ~ /^ *\/\//) { print } else { print | "jq \"sort_by(.key)\"" } }' keybin...
Process the same stdin two time and append the outputs
1,385,407,160,000
I've a directory structure like: rust/ ├── dir1/ │ └── Cargo.toml └── dir2/ └── Cargo.toml I want to create a zsh script that'll run from the rust directory, and for each subdirectory with a Cargo.toml file, run cargo command with user-specified arguments. Example: run.sh "test -- --ignored" should run cargo -v...
The shell doesn't mess up with --. Just do: #! /bin/zsh - for toml (**/Cargo.toml(N.)) cargo -v "$@" --manifest-path $toml And call it as: that-script test -- --ignored Using zsh globbing has several advantages over find: hidden files and directories are ignored (add the D qualifier if you do not want it) the list ...
Run cargo command in subdirectories with user-specified arguments
1,385,407,160,000
When I go to a this web-page (https://imgur.com/user/Ultraruben/submitted for example) and press Ctrl+u, I get one web-page. When I try to extract the html through the command line with curl <url> or curl -L <url> I get another. lynx -dump <url> doesn't work either (no javascript). I need to get through the command li...
It's pretty common for web sites to react to the kind of client they're seeing with different content. Some of that is well-intended: For example, some websites go through lengths to support incredibly old phones or windows PCs. From a security point of perspective, you'd want to tell an Internet Explorer 5 user that ...
I get a different html page using Ctrl+u and curl
1,385,407,160,000
I've been tasked to update a few of our sites and so, before doing so, I have to zip the public_html folder so I have a backup. Problem is, public_html has a bunch of other ZIPs that are older backups that I don't want to delete in case my backup fails or for some other reason, we need to go back 2-3 backups. But, sin...
The quick answer is to exclude the existing zip files: zip -r foo /path/to/public_html -x '*.zip' -x '*.gzip' Add/remove the -x options to match your existing naming convention for zip and gzip files. The long-term answer would be to store the backup files outside the public_html folder so that you don't keep catchin...
Command Line ZIP - How to ZIP an entire folder, but dodge the other zips present?
1,385,407,160,000
I installed brave browser using: sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg arch=amd64] https://brave-browser-apt-release.s3.brave.com/...
Command Opposite sudo curl [options] -o <file> <url> sudo rm <file> echo <debline> | sudo tee <file> sudo rm <file> sudo apt install <package> sudo apt purge --autoremove <package> So yes, the opposite is really to simply remove the files that you created in addition to purging the package and any depe...
How to Completely Remove an Application with it's PPA that is being installed via PPA and GPG
1,385,407,160,000
The default output of units seems to be a bit verbose: $ units "2 fortnight" seconds * 2419200 / 4.1335979e-07 Suppose I just want the number only, so that I can do things like sleep $(units "2 fortnight" seconds). Is there a formatting argument for units that I'm missing? Or is there some simple way to pipe ...
With GNU Units version 2.19: $ units --one-line --compact '2 fortnight' seconds 2419200 BSD implementation of units doesn't have --one-line --compact but you can use awk: $ units '2 fortnight' seconds | awk 'NR == 1 {print $2}' 2419200
How to get just the number from units?
1,385,407,160,000
I am trying to create a simple alias that uses the argument with the full path On the command line, I can type command "$(pwd)/my_file". It works. so I tried to create an alias in the following way: alias command='command "$(pwd)/$1"' This alias didn't work though. The CLI interprets as if $(pwd) and my_file were se...
The first issue is that aliases don't take arguments. If you need to pass an argument to an alias, that means you should use a function instead. You can see what happens if you run set -x: $ alias evince="evince $(pwd)/$1" $ set -x $ evince a.pdf + evince /home/terdon/foo/ a.pdf As you can see, the command evince a.p...
How to evalute multiple arguments in a alias? [duplicate]
1,385,407,160,000
In some contexts, I want the ability to run screen and to copy and paste text between different windows (in the screen sense of that term, not the X11 window manager sense) using click-and-drag to copy and (ideally) middle-click to paste, as I would be able to do if I were running screen in an xterm, but don't have an...
Yes, there’s gpm: it provides support for mice on Linux virtual terminals. It supports copy and paste, and also enables mouse usage in applications which support it (such as Midnight Commander). It’s packaged in many distributions; look for a gpm package. There’s also consolation which is similar, but based on libinpu...
Is there a more efficient way to get X11-style mouse-based, cross-application copy-and-paste for command-line use than "xinit xterm" or the like?
1,385,407,160,000
I am using MX linux and i need next thing. I have a config for openvpn, it works perfectly both from manual launch via cli and from nm-openvpn application in my XFCE. I want to launch my openvpn every morning at 9 am via cron, but with visual displaying in my XFCE like i launched it from GUI. Which command does networ...
There is no non-networkmanager command that is being launched when you activate the openvpn connection through NM. This is an internal procedure within NM that sets up the connection. To manipulate it through the command line you can use the nmcli command. Some kind of command like this should work: nmcli connect up "...
launch nm-openvpn via cli
1,385,407,160,000
I am running tmux 3.0a, and when I connect with a smaller resolution terminal, also the bigger terminal gets resized to the smaller. This is well known (although I don't understand why they made this the default behaviour), and the solution is to c-b c-: :resize-window -A (tmux force resize window, https://stackoverfl...
Apperently, :resize-window -A needs to be done in every window, but when it's done it's persisting (when you disconnect and reconnect with a smaller terminal it remembers to resize aggressively). Thus, include in your .bashrc the following command: tmux resize-window -A This sets aggressive resize for that specific wi...
tmux: How to always resize all windows to maximum available size?
1,385,407,160,000
I have a series of commands running through a pipeline like this: cmd1 | cmd2 | cmd3 | cmd4 How can I print the intermediate result of cmd1, cmd2 and cmd3? I know I can use the tee command to print the result to a file. But is it possible to just print it to the console? This is for debugging purpose as my actual com...
You can tee to the current terminal: cmd1 | tee /dev/tty | cmd2 | tee /dev/tty | cmd3 | tee /dev/tty | cmd4
How to print intermediate result of commands in a pipeline?
1,385,407,160,000
For example, let's say I want to docker run --interactive --tty ubuntu:18.04 bash apt update; apt install -y git nano wget; mkdir t; cd t but instead have one a single-line command. I unsuccessfully tried: docker run --interactive --tty ubuntu:18.04 (bash; apt update; apt install -y git nano wget; mkdir t; cd t) a...
Make that a bash command, that ends with a final call to bash so that you get an interactive subshell: docker run --interactive --tty ubuntu:18.04 bash -c "apt update; apt install -y git nano wget; mkdir t; cd t; exec bash" exec exec is necessary to make the new bash the container's main process, which is recommended...
How can I write a single command line that launches a new docker container with interactive bash and executes a few commands in it?
1,385,407,160,000
I want to get rid of two first lines generated after the usage of gpg -d file.txt.gpg, meaning that only text itself would be left. I tied to use --no-comment, but it seems to not work. gpg: encrypted with 2048-bit RSA key, ID 4FXXXXXXXXD30D52, created 2020-01-22 "test test <[email protected]>" test test444
gpg --quiet -d file.txt.gpg (or -q)
GPG - remove header from decrypted text
1,385,407,160,000
$(run-parts --list --reverse --regex '^KeePassXC-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]-x86_64\.AppImage' bin | head -n 1) (The purpose of the above command is to run the most recent version of KeePassXC found in ~/bin; I don't want to have to modify the startup entry each time I have to upgrade KeePass) The above c...
The error message: Could not execute '$(run-parts --list --reverse --regex '^KeePassXC-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]-x86_64\.AppImage' bin | head -n 1)' Failed to execute child process "$(run-parts" (No such file or directory) This indicates that the box that you're typing the command into is not a shell, a...
Why can I only run this command in the terminal, and not in startup commands nor in the Run command GUI box?
1,385,407,160,000
I want to enter into spark-shell using shell script and then execute below commands cat abc.sh spark-shell val sqlContext = new org.apache.spark.sql.SQLContext(sc) val df = sqlcontext.read.json("/file/path") i am able to enter into spark-shell scala but next two commands are not running Or else kindly let me know ...
You can’t start a sub shell and just list commands in the manner you have attempted. Presumably the shell is waiting for input from you. Broadly speaking, you have two routes you can go down. You would either need to feed spark-shell a file containing the commands you want it to run (if it supports that) or make use ...
How to run sequence of spark command through bash
1,574,835,605,000
I have to remove all the files in a folder whose file names have fcrjlog-11-21-2019-1.txt format. I want to remove all the files having this kind of filename in a folder.
find . ! -type d -name 'fcrjlog-??-??-????-?.txt' -delete (replace -delete with -exec rm -f {} + if your find doesn't support the non-standard -delete extension). ? is the wildcard operator that stands for any single character. Replace with [[:digit:]] to only match on decimal digit characters (0123456789). ! -type ...
Delete all files in a folder having timestamp in filename
1,574,835,605,000
I am new to shell scripting. I am modifying an existing shell script in which I have to create a dynamic html content and assign that content in a variable and use this variable value to replace in a template inside shell(Linux). I am using below code snippet its working fine when html content is less but same is fail...
@mosvy already provided you with a good answer. The short morale of the story is: it is not a good idea to use shell variables to store data that is not validated for length. It is also not a good idea to use shell variables or shells in general at all, because they are deranged programming languages. However, if you ...
How to resolve Argument too long
1,574,835,605,000
Need an at command timestamp that run some command at given day monthly, like for example, every day 15, as would follow: $ at every 15 day So that on every day 15, it would run some command. How would I set it?
As pointed out in the comments, cron is the right tool to do so. at is used to run a command at a specified time and date but only once. Just add this line to /etc/crontab: 0 7 15 * * youruser /path/to/somecommand This runs the specified command at 7:00 AM every 15th of the month. For more information, see t...
Need an "at" Command Timestamp That Runs Command Monthly at Given Day
1,574,835,605,000
I am trying to append 5.34.03 number to 5.34.04 by using the following command $ awk '{print 5.34.03 + 0.0.1}' 5.340.030.1 Expected output 5.34.13 I tried with many methods, eg. let, but it didn't work.
Assuming your minor version and patch version numbers should be 2 characters, you can use this awk script: parse.awk BEGIN { FS = "[ .]"; OFS = "." } function tonum(s) { if( length(s) < 2 ) s *= 10 return s } function tover(n) { if( n < 10 ) n = "0" n return n } { print $1 + $4, tover( tonum($2) +...
Add three dot floating numbers in shell
1,574,835,605,000
I like to print only one "Mem:" line in the output using plink command. plink -batch [email protected] -P 22 -pw test@123 (free;) --> working total used free shared buffers cached Mem: 8182004 7137528 1044476 0 284648 4852520 -/+ ...
There is no reason to run the grep remotely. plink -batch [email protected] -P 22 -pw test@123 free | grep "Mem:" Note that you should not give the command to plink inside a subshell, ( ... ). I don't know anything about Windows' cmd.exe, but you could also try plink -batch [email protected] -P 22 -pw test@123 sh -c ...
plink command to print free|grep "Mem:"
1,574,835,605,000
I'm running a tcsh shell. I have questions about the -l option in set -l. When I look at man for the set command, I don't see the -l argument. When using tcsh shell, what does the -l argument mean? Where & how can I find this info?
You're looking at the wrong place. This is from the tcsh(1) manual page: set set name ... set name=word ... set [-r] [-f|-l] name=(wordlist) ... (+) set name[index]=word ... set -r (+) set -r name ... (+) set -r name=word ... (+) The first form of the command prints the value of all shell variables. Vari...
What does the -l argument mean in tcsh?
1,574,835,605,000
I have a big text file I want to print only the first 4 and the first 5 and the first 8 characters of each line in one command line. For example I have the lines: 123456789ab ABCdefgih55 So the output have to be: 1234 ABCd 12345 ABCde 12345678 ABCdefgh
for len in 4 5 8; do cut -c "1-$len" file done This uses cut -c repeatedly to cut out the first part of each line of the file called file. The length of the cut out bit is depending on the loop variable len. If you're strict about that "one line" criteria: for len in 4 5 8; do cut -c "1-$len" file; done Or, as ...
Print only the multiple first characters
1,574,835,605,000
Let's assume that I have these files: /1/tEst.mp4 /1/Test.mP4 /1/subdirectory/TEST2.mp4 /1/.20181106Test2.mp4 How can I copy all of these files into /2/Videos with a single command line? All files that end with “mp4” and have “test” inside the name should be included. Case-insensitive, if possible. I could use the f...
This seems doable in bash: set -o nocasematch dotglob globstar cp /1/**/*test*.mp4 /2/Videos/
How to copy all files in all directories with specific filename to one destination?
1,574,835,605,000
I need to create multiple directories using one command.  Is it possible? Like directory name starts from 1-100. mkdir 1..100
You don’t need a (for...do...done) loop; just do mkdir $(seq 1 100) Or, in bash, mkdir {1..100}
How to add multiple directories like the name 1-100 in one command
1,574,835,605,000
I have Debian Stretch.. I thought that a regular user could kill root process as root. I was using the command /bin/kill 10733 as the user. There wasn't any error message. Then, I typed out the similar command (without /bin/ prefix) and the error message got displayed. Here, is the command history deployer@deployer:~...
In your example, the kill command is a shell internal (definitely in bash) and it allows for extensions such as %1 to be used to refer to background processes. On the other hand, /bin/kill is an external command and doesn't have these extensions. Since it's a different program it acts differently. A failed /bin/kill...
The /bin/ prefix to kill command is getting rid of the error message
1,574,835,605,000
I'll try to be specific and clear. I have a file: log.txt it contains multiple strings that I search to print and count each of them. This is my command, only print columns coincidences in the log.txt file: sed -n '1p' log.txt | awk '{ s = ""; for(i = 25; i <= NF; i++) s = s $i "\n"; print s}' Explanation sed -n '1...
Here's how I'd approach this problem: awk '{n=1;if(NR==1)n=25;for(i=n;i<=NF;i++) a[$i]++} END{for(val in a) print val,a[val]}' input.txt The fact that you want to capture fields 25 and after in the first line, requires us to check NR variable, and set n variable which will be used in the loop. As for a[$i]++ that wil...
Count every string of awk output search in a file
1,574,835,605,000
I know that I can simply substitute a string with another in the previous command by typing: !!:gs/string1/string2/ But how I can perform multiple substitutions, e.g. having a command: echo "AAAAAAAAAAAAAAAAA" > test1 I want to substitute A with B and 1 with 2, so execute such a command: echo "BBBBBBBBBBBBBBBBB" > t...
$ echo "AAAAAAAAAAAAAAAAA" > test1 $ !!:gs/A/B/:s/1/2/ echo "BBBBBBBBBBBBBBBBB" > test2 That is, just add the second substitution to the end of the first. Just be aware that the second substitution will act on the result of the first.
Multiple substitution when repeating the previous command
1,574,835,605,000
I have a requirement to append timezone value in the below format at the end of milliseconds, an example follows: 2018-01-07T14:30:03.832-0700 I need the Unix command to get the required format.
It is posible to get the ISO8601 time format with GNU date: $ date -Iseconds 2018-07-01T06:57:25-0700 However, to get the time with milliseconds you neef to specify the detailed string. Try: $ date +'%Y-%m-%dT%H:%M:%S.%3N%z' 2018-07-01T06:57:28.457-0700
Date format command [closed]
1,574,835,605,000
I'm trying to filter the most used commands and print that out in a certain way. So far, I've managed to put the desired "filters": $ history | tr -s ' ' | cut -d ' ' -f3 | sort | uniq -c | sort -n | tail | awk '{ printf "%s%20s\n", $2, $1 }' ...but I can't get the output correctly. I would like to be able to display...
Following PO's approach, replace awk by Perl -- 'Perl -ae' is very similar to awk... ... | perl -ae ' printf "%-20s %d %s\n", $F[0], $F[1],"▄"x$F[1]' aa 12 ▄▄▄▄▄▄▄▄▄▄▄▄ bb 23 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ Edit: with Awk, you could run something along the lines of ... | awk '{printf "%-20...
Pass arguments from previous commands (pipes) to awk/printf function and format output
1,574,835,605,000
how to capture the java version on linux redhat machine we tried that: java -version | head -1 | awk '{print $NF}' | sed 's/"//g' but we get openjdk version "1.8.0_65" OpenJDK Runtime Environment (build 1.8.0_65-b17) OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode) while expected output should be 1.8.0_65
java -version outputs to its standard error, so you need to redirect that: java -version 2>&1 | head -1 | awk '{print $NF}' | sed 's/"//g' You can do this with a single AWK invocation: java -version 2>&1 | awk 'NR==1 {gsub("\"", "", $NF); print $NF}'
how to capture the java version on linux machine
1,574,835,605,000
I know how to replace a line with another line or several other lines with tools like sed. But is there an easy way, to replace a line in a file with the whole content of a second file? So, let's have an example. I have a file called file1.txt: A 1 B 2 C 3 And I have a second file file2.txt: line 1 line 2 line 3 ...
sed -e '/^line 2$/{r file1.txt' -e 'd;}' file2.txt The sed script is /^line 2$/{ r file1.txt d } The newline after the filename file1.txt is mandatory, so splitting it up into separate -e expressions on the command line makes it arguably more readable than sed '/^line 2$/{r file1.txt d;}' file2.txt The scri...
Replace a line with the full text of a second file [duplicate]
1,574,835,605,000
I am trying to use the du command to find the total size of multiple folders and print the total in a single line. It works but I would like to sum them up automatically and print the total size. This is what I am doing currently: du -h -c directory_1|tail -1 && du -h -c directory_2|tail -1 160K total 35M tot...
The -s option will just show the total. From man du: -s, --summarize display only a total for each argument Without -s, du will also list each sub-directory individually. In combination with this, you can just use both directories as arguments. du -shc directory_1 directory_2
Sum of two different folders
1,574,835,605,000
I need to increment alphanumeric data. Increment numbers with seq is easy just: seq -w 0000001 9999999 >> file But I need to increment alphanumeric data in order like this: 0000001 0000002 0000003 0000004 0000005 0000006 0000007 0000008 0000009 000000a 000000b 000000c 000000d 000000e 0000010 0000011 0000012 0000013 0...
Assuming you really mean hex (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) here is a solution up to FF (I don't want to have to count to 4.3 billion): (echo obase=16; seq 1 $((echo ibase=16; echo FF) | bc)) | bc The inner (echo ibase=16; echo FF) | bc calculates the ending value in decimal (here FF but feel free ...
Bash increment alphanumeric data from command prompt
1,574,835,605,000
I use the cmus console music player through ssh on a device with OSMC (Kodi, based on Debian Jessie) installed. My problem is that the sound is played to the HDMI, and I want to play music to the jack output. I tried to use alsamixer, amixer, aplay, etc... but these are not installed and sudo apt-get install alsamixer...
This 2018 article explains how you can dynamically switch the audio output between hdmi and analogue on a Raspberry Pi. From the command line use amixer cset numid=3 2 for hdmi and amixer cset numid=3 1 for analogue. This information is no longer in the current version of that page, so may no longer work. The May 2...
Set audio output using command line
1,574,835,605,000
I'm building a command-line utility that requires six pieces of information to work correctly. It looks like this: fm-git filename repository path comment username password However, on any individual system, username and password will be constant. When executing the utility, I'm finding it difficult to build. For ex...
In general it's good idea to: calculate dependent arguments but allow to redefine them: for example in your example you have filename the same as $(basename repository), so you may require only repository, but have option --filename to provide alternative filename. hide auth from command line and ps output. Put them ...
What is the recommending interface to a utility that requires many parameters? [closed]