New answers tagged

0 votes

gunzip multiple gz files with same compressed file name in multiple folders

You could use find. Presuming that your target directories A, B, C, and D live in /path/to/basedir: $ find /path/to/basedir -name '*.gz' -type f -execdir gunzip {} \; Or, simply, if you are in ...
  • 69.5k
0 votes

gunzip multiple gz files with same compressed file name in multiple folders

This bash script should do what you want: #! /usr/bin/env bash for dir in ./* ; do [ ! -d "$dir" ] && continue for i in "$dir"/*; do file=$(basename "$i&...
1 vote

How can i use a proxy server for whois command?

Traditionally, the whois command uses neither ftp nor http to connect to remote servers. It uses the whois protocol on port 43, and it isn't particularly amendable to proxies. Modern versions of whois ...
  • 27.4k
0 votes

Let `bash -c` keep on ready on prompt

Another way to do this is to use expect which has been implemented in many languages. In the original TCL one might use: #!/usr/bin/env expect # run the shell spawn -noecho bash # blindly send the ...
  • 33.1k
4 votes

Let `bash -c` keep on ready on prompt

If you want to get into an interactive mode, but execute some script beforehand. Or execute a script and remain in interactive mode. Then key --init-file is for you. Assuming you have hello.sh #!/bin/...
  • 2,393
0 votes

How to access the Evolution calendar data from the command line?

As said in another answer, syncevolution. Here is an example: assuming you have an email in your Evolution mail client, this example will export the calendar events ACCOUNT='youremail@someserver.com' ...
  • 101
0 votes

How to remove a single line from history?

If you have hstr (a way better reverse-i-search that can be installed with sudo apt install hstr), then it's really simple: Open your terminal and press Ctrl+r to search your history. Type some ...
  • 153
1 vote

Check the number of bytes on each line of a file

Try: expected=72 <a-file LC_ALL=C grep -nxvE ".{$expected}" >a-new-file Or: <a-file LC_ALL=C awk -v expected=72 ' length != expected {print FNR, $0}' >a-new-file length ...
0 votes
Accepted

error trying to build/make from source

/bin/bash: line 2: 186552 Killed build/genautomata ../../gcc/common.md ../../gcc/config/mips/mips.md insn-conditions.md > tmp-automata.c make[3]: *** [Makefile:2459: s-automata] ...
0 votes

Markdown Viewer

just use cat foo.md on the command line in linux and you will see the file displayed
0 votes

How to extract annotations from PDF files?

Have a look at https://superuser.com/questions/698811/how-to-export-comments-from-a-pdf-file where comments suggest pdfannotextractor.
  • 2,417
3 votes

Extracting json fields in a log line using awk or some other cli tool

jq is a common tool to manipulate JSON. jq -r .msg will return the decoded value of the msg key in the JSON document. You can use cut to get the JSON data by extracting the fields from field four ...
0 votes

How to delete an user account with terminal

A more modern way to do this is with the deluser command: sudo deluser --remove-all-files $USER_TO_DELETE See the manual page for details.
  • 243
0 votes

Unable to get terminal prompt when executing script via ssh

The echo "whatever" is killing the script at the echo -n ">> " line, since it is not accepting any input coming from the script - therefore the read env never happens. I do ...
1 vote

Is it possible to repeat part of a string that hasn't been executed yet in bash?

I’m old enough to remember hard-copy terminals (for you kids, imagine a printer with a keyboard) and I believe that this editor-style command line editing is a fad that won’t last much longer.    :-) ...
2 votes

Add an item to a list of piped items

If all you want is to list each visible name in the current directory, add c to the end of the list, and view the result in less: printf '%s\n' * c | less The rest of this answer deals with creating ...
  • 282k
10 votes
Accepted

Add an item to a list of piped items

The simplest would be (ls;echo c) | less
  • 3,447
5 votes

Add an item to a list of piped items

Yes, it's possible to achieve that. Here are two examples: Using pipes twice: ls | (cat;echo fuzz) | less Using input redirection: ls | less < <(cat;echo fuzz) In zsh shells you can also use: ...
1 vote

Duration of connections returned by ss

Unfortunately, you have to work at it. The following script is a hack to attempt giving you what you are looking for. #!/bin/sh BASE=`basename "$0" ".sh" ` TMP="/tmp/tmp.$$.${...
0 votes

MAC: Import .p12 certificate into the keychain via command line

You will need to convert it to .pem format first. You can do so with openssland then try and import it. To convert the certificate, you can use this command $ openssl pkcs12 -in certificate.p12 -out ...
  • 2,187
0 votes

Disabling KWin compositor from command-line

When I turned on compositing, it broke the setting window so I couldn't turn it back off again. I logged in using gnome/mate, opened plasma-open-settings and was able to disable it again.
  • 203
0 votes

How to remove the final \n?

I can only think of this "trick" solution right now. It works because you echo something without the following newline, and the something is the output from ps in this case. echo -n "$(...
1 vote

How to remove the final \n?

There are quite a few ways to do that in Bash. For example, pipe this command: head -c-1 to remove the last byte from the output.
  • 731
0 votes

Efficiently delete large directory containing thousands of files

This is not applicable to most cases, but a trivial and instant way of fast deletion is renaming the directory and deleting in the background. In my case, I often need to recreate node_modules or a ...
2 votes

How to remove the final \n?

You can just make awk not print the last newline. Converted to printf, only print newlines before strings, except the first string. ps -au | awk '{if (NR > 1) { print "" }; printf("%...
  • 464
2 votes

How to remove the final \n?

There is a simple tool designed to solve problems like this: truncate -s -1 But better confirm that there is a trailing newline first: [ -z "$(tail -c1 file)" ] && truncate -s -1
0 votes

How to remove the final \n?

I always use Python to do this, create a .py file with below code: from pathlib import Path contents = Path("myfile.txt").read_text(encoding="UTF-8").splitlines() Path("...
0 votes

How can I create a .txt file containing data being generated in real-time in Linux terminal when a program is running?

I'm not sure I understand your problem well, but if you can launch your command from terminal, it is possible to use redirections: ./yourprogram > path/to/your/logfile.txt or, if you want to ...
  • 23
1 vote
Accepted

How to send a command to tmux-session of remote-device (using ssh)

In the comments, we've confirmed that the intended command, ssh remote "tmux send -t main.0 'echo asdf' ENTER" ... works when remote is not the local host. We have also confirmed that the ...
  • 282k
0 votes

get age of given file

If you just want output as 12d or 12 days I use this... filename=/path/to/your/file.txt now=$(date +%s) modified=$(date -r "$filename" "+%s") delta=$((now-modified)) printf '...
2 votes
Accepted

Is it possible to repeat part of a string that hasn't been executed yet in bash?

You could use the line editing function to grab the mkdir argument and paste it to the end of the line. (I use vi-style line editing so that would be very straightforward: ESC to enter editing mode, ...
  • 94.2k
1 vote

How to use output of multiple commands in last execution command while chaining commands?

I guess, from reverse-engineering your attempted solution and the other answer, that you want n₁ + n₂ + … lines of output, like blue: sky blue: berry blue: jay red: stop sign red: cardinal red: tomato ...
1 vote

Is there a way to add a "description" field / meta-data that could viewed in ls output (or an alternative to ls)?

The modern file systems, including ext* family has ability to create extended attributes to files. They could be managed by xattr tool # set a comment xattr -w user.comment "The cool file" ...
  • 2,393
1 vote
Accepted

Within an AWS CLI command, add the ISO 8601 datetime

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' { ...
1 vote

Within an AWS CLI command, add the ISO 8601 datetime

As the error message highlights, the JSON is invalid. So, as to be expected, the command you wanted to be executed never was – how was the shell supposed to know which parts of the command line you ...
1 vote
Accepted

How to use output of multiple commands in last execution command while chaining commands?

You'd need something like: export REPO az acr repository list -n registry -o tsv | while IFS= read -r REPO; do az acr manifest list-metadata -r "$REGISTRY" --n "$REPO" --...
0 votes

How to timeout firefox kali linux

The programm timeout is part of GNU coreutils and does exactly what you need: timeout 10 firefox
  • 11.4k
0 votes

How to extract annotations from PDF files?

I have a similar need and wanted to use python3, so I started developing an extract-pdf-annotations.py with my other tools at https://github.com/foleyj2/teaching-tools You might find it useful.
1 vote
Accepted

paste command puts data from csv files vertically line by line instead of horizontally next to each other

Most likely, your original files have \r\n end of lines. If it is so, the final file would have an extra \r between each line segment. Try using tr: paste -d "," *csv | tr -d "\r" &...
  • 2,393

Top 50 recent answers are included