Skip to content
Advertisement

Tag: bash

output mountpoint on (usb)device detection

I want to create a bash script that will output the mount point from an inserted USB device. I have two commands (between “do” “and” done”) that work separately but not together in a bash script. The script looks for a UUID file use the $UUID filename in the lsblk command to extract the mountpoint The mount point must be

How to resize the block of a column

I have a single column of a file having many blocks and the blocks are separated by the > symbol. I want to resize all blocks to the same highest length by appending zero below them. My file is given below: file.txt and my expected output is given below I am trying to write a script, but it fails: Answer

Convert timestamp to date results in time out of range error

I`m trying to convert a timestamp to an ISO8601 datetime-string. E.g. The timestamp is fairly long, with nanoseconds precision, and when I use the full timestamp it returns the following error: date: time ‘1606982602015489365’ is out of range The expected result should be: 2020-12-03T09:03:22,015489300+01:00 When I cut the timestamp to this: 1606982612 the error is gone but I loose information!

Can we store “cd ..” path in a variable in bash file?

I am new to the bash my use case is to store the one previous directory in to a variable. Example: How can we add /local/ to any variable like $PREV? Answer You can use parameter expansion on $PWD which contains the current path: Or, use an external tool like readlink with command substitution:

Rounding of the millisecond part in Linux datetime

So I have the date format like this : 2019-10-19 23:55:42.797 and I want the millisecond part to be round of into the second so the output should look something like this: 2019-10-19 23:55:43 I have tried date -d “2019-10-19 23:55:42.797” “+%Y-%m-%d %H:%M:%S” but it’s giving me output like 2019-10-19 23:55:42 How should I do this in Linux bash shell?

Advertisement