New answers tagged command-line
0
votes
how to download a file using just bash and nothing else (no curl, wget, perl, etc.)
If you have python2:
/usr/bin/python2.7 -c "import sys; import urllib2; exec('try: response = urllib2.urlopen(\'http://localhost:8080/ping\');\nexcept Exception as e: sys.exit(1)')"
- 101
-1
votes
How do I delete files with the same names in multiple sub-folders from the command line?
First you need the list of files. You can use ls, find, fd... Save this to a text file: ls posterior_predictive_sim_*/ > all.txt. People complain about parsing ls, tl;dr is it doesn't matter here.
...
- 11
-1
votes
How do I delete files with the same names in multiple sub-folders from the command line?
With a loop:
for i in $(ls); do rm posterior_predictive_sim_$i/seq\[*.nex; done
Leaving this up just as a reminder to myself and others why NOT to do it this way - see cas's comments below
- 2,008
5
votes
How do I delete files with the same names in multiple sub-folders from the command line?
With just rm:
rm simulations/posterior_predictive_sim_*/seq\[[1-4]\].nex
The escaped \[ and \] are literal square brackets. The unescaped [1-4] inside them is a glob pattern that matches the digits ...
- 73.9k
0
votes
How to get the vmware version through linux command-line without accessing the ESXi server?
Please try the following command
vmware-toolbox-cmd stat raw text session | grep version
I found it in the comments section of another site.
0
votes
How can I join mp4 files in Linux without transcoding the files?
Write mp4 videos paths into file input.txt:
file '/path/to/video1.mp4'
file '/path/to/video2.mp4'
and then run this:
ffmpeg -f concat -safe 0 -i ./input.txt -c:v copy output.mp4
Just this!
- 327
-1
votes
Zsh script to recursively unrar into a folder with the same name
Did you try the unrar itself?
unrar x archive.rar
If the archive has directories and subdirectories - they would be recreated.
- 4,010
0
votes
How to verify a checksum using one command line?
Many software projects provide a checksum file some-release.zip.sha256 in addition to the downloadable file some-release.zip.
On one hand, the filename-checksum entries in .sha256 files use relative ...
- 562
-1
votes
2
votes
Accepted
Unrar all .rar files in a directory to a folder with the same name
set -e
cd dir
for rar in ./*.rar
do
[ -f "$rar" ] || continue
dir=${rar%.rar}
mkdir "$dir"
(
cd "./$dir"
unrar x "../$rar"
)
# maybe rm &...
- 17k
0
votes
Print text from terminal
Here's what worked for me:
I chose to install Manjaro "Full" which includes printer networking and printing support. From past experience, the "Minimal" install requires a non-...
- 723
0
votes
How to verify a checksum using one command line?
@Sasha has the right way. If you received a SHA256SUM file with the hash on the left and file path on the right, you can use this method:
sha256sum --check SHA256SUM 2>/dev/null | grep 'OK'
If not,...
- 190
0
votes
command that will take a file and separate each word so its on its own line
perl -nale 'foreach $word (@F) {print $word;}' file.txt
or even more briefly:
perl -nale 'for (@F) {print}' file.txt
The perl command line options are:
-n - process each input line, no printing
-a - ...
- 243
1
vote
How to remove blank lines from a file (including tab and spaces)?
Adding to @cuonglm's answer, some lines could have non printable color characters, so removing color before running ...| awk NF could be a good idea. In the below command, sed removes color from the ...
- 111
0
votes
How can I remove duplicates in my .bash_history, preserving order?
Extending Ali's answer.
The .bash_history file may or may not contain timestamps, and timestamped records can be mixed with non-timestamped if HISTTIMEFORMAT was switched on or off. This script ...
- 101
4
votes
Accepted
On what occasions should you use 'sh -c' instead of directly executing a program?
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 ...
- 16.2k
0
votes
How do I convert an epoch timestamp to a human readable format on the cli?
If UTC is your preference (for the sample epoch timestamp 1666666666),
$ # long options; Linux
$ date --date=@1666666666 --utc
Tue 14 Nov 22:13:20 UTC 2023
$ # short options; Linux
$ date -d @...
- 203
0
votes
How to create a keyboard shortcut to play/pause any audio/video running in the background?
I found the same as you: The command xdotool key XF86AudioPlay works from a shell, but not from a shortcut or application launcher. So I concluded that xdotool only works when executed from an ...
- 575
0
votes
How to remove the first X directories in path?
Using parameter expansion:
$ echo "/${PWD#*[a-z]*/[a-z]*/}"
/current/directory
See: http://mywiki.wooledge.org/BashFAQ/073 and "Parameter Expansion" in man bash.
Also see http://...
- 29.2k
5
votes
Why use "tail -n 1" for finding the nth line of a file in Unix?
head -7
Or its modern and standard equivalent:
head -n 7
prints the first 7 lines (or up to 7 if there are fewer) of the input.
piping that to tail -n 1 gets the last line out of those, so the 7th ...
- 505k
0
votes
Accepted
Split pdf document based on section
Stewart's answer gave me pretty much all the tools, but I made two important edits to their solution:
Use coherent pdf to preserve the table of content (pdftk just delete it),
Make the command split ...
- 278
4
votes
How to do formatted printing with jq?
jq can reference expressions inside string using \(foo)
[String interpolation - \(foo)][1]
Inside a string, you can put an expression inside parens after a backslash. Whatever the expression returns ...
- 141
0
votes
How to to resize an ext4 partition from the command line?
The easy way:
I had an issue with gparted not wanting to resize
#sudo parted had no such issue
Model: ATA CT1000MX500SSD1 (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/4096B
...
- 56
1
vote
How to read constant size buffers from a named pipe, and run a command for each buffer
I already tried this: { while :; do dd iflag=fullblock iflag=nonblock bs=65536 count=1 2> /dev/null | redis-cli -x PUBLISH myChannel ; done } < myFifo
It's working. But is highly CPU consuming. ...
- 128k
0
votes
Accepted
Renaming object or element in perticular range in a column of text file
I suggest:
awk '{gsub(/[^0-9]/,"",$1); if($1+0<21){$1="seq1"} else {$1="seq2"}; print}' file
gsub(/[^0-9]/,"",$1) removes all but numbers from first column.
- 11.8k
0
votes
Renaming object or element in perticular range in a column of text file
Both your description and your attempts look weird, but given the input and desired output I think you want this:
$ awk '(NR%2==1) ? $1="seq2" :$1="seq1"' file.txt
seq2 19301 20914 ...
- 5,991
4
votes
Accepted
Renaming column based on matching of second column in a text file
You first awk attempt:
awk 'BEGIN{FS=OFS=" "}($4 == /^NZ_JAHWGH/){$3==seq1}1' file.txt
fails because $3==seq1 is a test of whether $3 is exactly equal to the value of the variable seq1. ...
- 228k
2
votes
Renaming column based on matching of second column in a text file
How about sed?
sed -e "s/seq.* NZ_JAHWGH/seq1 NZ_JAHWGH/" -e "s/seq.* NZ_CAJGBF/seq2 NZ_CAJGBF/" file.txt
- 4,010
2
votes
Split pdf document based on section
I like using pdftk for this type of work.
If I create a basic document using Latex, it might look like this:
\documentclass{report}
\usepackage{blindtext} % For lorem ipsum text
\usepackage{hyperref} %...
- 11.8k
0
votes
What is the -l (lowercase L) switch of the ssh-agent command?
It's an undocumented flag related to integration with macOS's launchd. It's discussed further in this Stackoverflow post: What is -l flag in macos ssh-agent?
Community wiki
1
vote
Split pdf document based on section
I had used python libraries py_pdf_parser and pdfplumber to achieve something similar last year. On top of that, I used MathPix API (which is paid but minimal fees) to do final conversion to latex.
...
- 4,415
1
vote
Select area on screen with pointer
A minimal option is xrectsel. It is available on Arch Linux through AUR.
Allows you to draw a simple rect on screen and outputs the following:
$ xrectsel
1643x627+564+445
-2
votes
Create nested directories with the same user/group in a single command
You can create nested directories with the same user/group in a single command using the mkdir command with the -p flag
mkdir -p -m 755 /path/to/parent/directory/{child1,child2,child3}
0
votes
Choose columns with sort and cut in a csv with a comma delimiter ',' ignoring data on quotes with comma "text,text"
Using GNU awk for FPAT you can identify the fields:
$ awk -v FPAT='[^,]*|("([^"]|"")*")' '{for (i=1; i<=NF;i++) print i " <" $i ">"}' file
1 <&...
- 27.3k
0
votes
Accepted
Create nested directories with the same user/group in a single command
I can not add a comment, therefore I post this as an answer.
Have a look at install, see man install(1).
install -d -g myUser -o myUser new-1 new-1/new-2 new-1/new-2/new-3
Or, if you don't want to ...
0
votes
Get list of subdirectories which contain a file whose name contains a string
As long as you don't have more than one file matching per directory (otherwise you will have duplicates), in bash you can leverage from the for construct and on variable expansion (as in the example ...
- 101
1
vote
Accepted
Separate variable scope spawning commands under job control
In zsh, you can use an anonymous function, but you still need to declare variables as local.
For instance:
$ () { local t; for t in 100 200 300; do sleep $t & done; }
[2] 4186
[3] 4187
[4] 4188
$ ...
- 505k
-2
votes
How many services are listening on the target system on all interfaces? (Not on localhost and IPv4 only)
netstat -tnl | grep ":.*[1-9]" | grep -v "127.0.0.1" | wc -l
- 1
0
votes
How can I install ncdu on Red Hat?
On Amazon Linux 2:
# amazon-linux-extras install epel
# yum install ncdu
- 361
Top 50 recent answers are included
Related Tags
command-line × 6035linux × 1001
bash × 936
shell × 672
shell-script × 405
text-processing × 321
terminal × 300
files × 270
grep × 230
ubuntu × 219
find × 197
awk × 184
sed × 174
command × 167
macos × 143
debian × 140
scripting × 135
networking × 120
zsh × 118
ssh × 116
pipe × 112
directory × 96
ls × 95
process × 90
regular-expression × 79