New answers tagged

0

I had a similar situation with some headphones I own that I constantly swap between my computer and phone. I created this bash script and placed it in a folder on my path so I can connect / disconnect from these headphones via the command line (and via a launcher I built). Here is the script that uses bluetoothctl to connect / disconnect. I used the MAC ...


5

Let’s split this up: tr '\0' '\071' < /dev/zero reads from /dev/zero, which produces zero bytes, and replaces all zero bytes ('\0') with bytes containing 71 in octal ('\071'), i.e. the digit 9 in ASCII, or 0x39 in hexadecimal (which is what hexdump shows). The result is a never-ending stream of 0x39 bytes. dd of=/dev/sda bs=1M conv=fsync 2>/dev/null ...


0

But I can't figure out exactly what the command is intended to accomplish It replaces null bytes with 071 (0x39 57 00111001) bytes. No idea how it can be useful. Normally if you want to check the drive health you use other patterns, e.g. 00000000 0000 0x0 11111111 0377 0xFF 01010101 0125 0x55 10101010 0252 0xAA All these values are used by e.g. badblocks


0

My answer was incorrect; it will be deleted.


0

You can use the -exec switch to run dirname and get the directory name instead of the file name. This has the added benefit of being POSIX compatible. find . -name "*file*" -exec dirname {} \;


0

The zip archive contains a pdf file (E7A70v1.0.pdf), not a plain text file. Pdf files may (and probably do) contain binary data mixed with text. You want to extract the pdf file with unzip E7A70v1.0.zip, and then use a pdf viewer to read the file you have extracted. You have your choice of viewers, but evince is a good one, and comes with most Linux ...


3

The output contains (among other things) a valid escape sequence telling urxvt to print the current screen: ESC[i


0

You may try this: This solution assumes a lots: that your ultimate goal is to quickly determine the biggest directory (NOT counting its subdirs) to for exemple find quickly where you should do some cleaning up to free space (an often needed thing) that the filenames do not contain spaces/tabs/newlines/etc that the size of a file is always in the 7th field ...


1

As others have said, it is just a slow process. We have multi user machines and the worst is when a disk runs low and several people start du at the same time. So, we use a cached view of the disk usage (we run it twice a day). There are lots out there, but my faviourite from a visual perspective is duc http://duc.zevv.nl/ Indexes are generated from cron ...


0

Sounds like an issue with the paths. Check that the paths, that the installer uses, include the paths to your binaries that you say exist. That is to say, the installer is looking in the wrong places (i.e. directories), or put another way, the binaries are not where the installer expects them. There is probably an environment variable that needs the correct ...


0

Throwing another one on the pile... csvprintf It works like printf(1). For example, with this input: FirstName,LastName,IdNumber George,Washington,1 Betsy,Ross,2 And this command line: $ cat input.csv | csvprintf -i '%{IdNumber}04d: %{LastName}s, %{FirstName}s\n' You get this output: 0001: Washington, George 0002: Ross, Betsy Disclaimer: I wrote this


0

Bash can save the output of non-interactive commands, which you can then open in an editor using Ctrl-G and yank the field(s) you need into the current command line: https://asciinema.org/a/395092


0

It is very ease to expand ext4 partition with growpart. Backup current partition table sfdisk -d /dev/sdb > sdb_partition_bak.dmp Execute dry-run to see what will be changed. If you don't have this tool. Run apt-get install cloud-utils growpart -N /dev/sdb 1 If everything is fine growpart /dev/sdb 1 Resize file system. It may take 10 seconds ...


0

Well it seems i found the answer with a stroke of luck, this code works: ARRAY=( M4d W0rld ) sed '/^#/!s/ARRAY=(.*)/ARRAY=( '"${ARRAY[*]}"' )/g' test.txt The asterisk was very important apparently, but what is the difference with the @ symbol? Also why the extra double quotes?


1

Not sure if this is a good solution, but based on https://stackoverflow.com/questions/4233808/piping-data-to-linux-program-which-expects-a-tty-terminal it seems like unbuffer accomplishes this. unbuffer exa | less will show colors.


1

From comments it was made clear that the user had one or several lines in their ~/.bash_profile file saying PATH=~/bin:PATH This would clear the PATH variable, resetting it to a list of paths that are not generally useful. This would easily be remedied ty prefixing PATH with $ in the value assigned to the PATH variable: PATH=~/bin:$PATH This prepends ~/bin ...


0

got this issue on Ubuntu 20.04, got it fixed: sudo apt-get install nvidia-settings sudo ubuntu-drivers autoinstall sudo reboot


4

Looking at http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html it shows that you can do this by giving the %~ prompt expansion in PS1 an integer right after the percentage sign. PS1='%F{cyan}%1~ %B%F{yellow}λ%f%b ' The 1 after the percent will get you what you want.


2

I tried the following to change locale. It also outputs ascii code draw lines same as --charset=ascii. > LANG=C tree


1

You could use $ to match the end of the line: sed -i "/callbacks:$/a\ \ - 'https://d1.example.com/callback'" a.yaml


2

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 Sockets found in /var/...


0

There is no day number 0 in a month and there is no month 0 in a year. Days and months start from 1. Try one of these instead: touch -d '1/1/0 0:0' foo touch -t 000001010000 bar


1

Did you try archivemount to mount your archive on a mountpoint, rename your directory, then unmount the archive? $ archivemount archive.tar /mnt/archive $ ls /mnt/archive /mnt/archive/archive/file1 /mnt/archive/archive/file2 $ mv /mnt/archive/archive/file2 /mnt/archive/archive/file3 $ ls /mnt/archive /mnt/archive/archive/file1 /mnt/archive/archive/file3 $...


0

I figured it out and made a simple package called tempcolor. Now, I'm able to even create keyboard shortcuts to change color temperature incrementally. install place the contents of the repo wherever you want to; make tempcolor executable: chmod +x ./tempcolor; feel free to create a symbolic link for tempcolor. be it in /usr/bin; or be it in $HOME/.local/...


0

You can also try the split command. While it is commonly used to split files, you can use it for this as well: split -b 4 --filter='cat;echo -n " "' <<< 'foobarbazblargblurg' I mean it works, but YMMV.


1

qpdf works great and is super fast!: Tested on Ubuntu 20.04 with qpdf version 8.0.2 (see qpdf --version), but I suspect it would work fine on Ubuntu 18.04, 16.04, and 14.04 too, since I've used qpdf in other ways on all of those systems as well. sudo apt update sudo apt install qpdf # Rotate in.pdf +90 deg and save as out.pdf qpdf --rotate=+90 in.pdf out....


0

If your implementation of ip supports the --json output format switch, then I'd suggest something like sudo ip -d link show vxlan_10 | jq -r '.[] | to_entries[] | "\(.key) \(.value)"' Ex. (I don't have a vlan interface, so this shows a regular wireless interface): $ ip --json link show wls1 | jq -r '.[] | to_entries[] | "\(.key) \(.value)&...


0

This sounds like a job for the fmt command that's part of coreutils. In particular, you'll want to use -s, --split-only split long lines, but do not refill


2

try: your-command |grep -Eo '(vxlan id|srcport|dstport) [0-9]+|local [0-9.]+'


0

The application sets the class when creating the windows. This means ultimately the application determines if you can set the class, and if yes, with what commandline option(s). There is no universal option. In particular, you cannot do this from another application (unless you start doing tricky things with preloading libraries, and intercepting the ...


0

I use this function: mdp() { pandoc -t plain `find . -maxdepth 1 -iname "${1:-readme.md}"` | less } Usage: mdp <file> Will open parsed .md file specified as argument mdp Will open readme.md if there's any


2

To answer OP's question in comment: "Is there a way to do it without using a for loop?" I usually use a dedicated utility for this: mmv mmv 'report?.txt' 'myreport#1.txt' (there are several other similar tools around, like rename)


1

In the zsh shell, the following would rename the three files shown: autoload -U zmv zmv -v -- 'report<1-3>.txt' 'my$f' The source pattern should be a valid zsh extended globbing pattern (quoted), and the source pattern used here simply matches the three filenames that you mentioned. The $f in the target pattern will be replaced by the full original ...


1

You can use mv: for f in *.txt;do mv $f "my$f"; done Or you can use rename: you may need to install it based on your distro. rename -v -n 's/report/myreport/' *.txt rename (option*) 's/oldname/newname/' file1 file2 or use *.extension If you are on Archlinux use this if that didn't work: rename -v report myreport *.txt For options check man ...


3

You can use just a simple loop in one line: for ftr in report[0-9]*.txt; do mv "$ftr" "my${ftr}"; done If you don't want use a loop, you can try this: find . -maxdepth 1 -type f -name "report[0-9]*.txt" -printf "%f\n" | xargs -I{} mv {} my{} Note that, as in the for loop, you need to put this in the path where the ...


0

If running du on a particular directory takes 20 seconds, then that is what it will take to run du on that directory. You can't really do it quicker. What you can do quicker is to eliminate the manual labor, i.e. remove the need to run du manually on each individual directory and to compare the sizes. You can do this in a few different ways, depending on how ...


0

This happend to me when after i installed Andriod Stuido, and wrote the wrong path to SDK. Got multiple export error: not a valid identifier. And all commands did not work. I had to open bash_profile in Notepad (outside the terminal) and remove the wrong PATH.


1

See the manual page. The chroot command launches a command with a new root directory. In your example, /mnt is the new root, and bash -l is the command whose root will be /mnt. As stated by the comment, -l makes the shell act like a login shell.


1

Man page for chroot: SYNOPSIS chroot [OPTION] NEWROOT [COMMAND [ARG]...] DESCRIPTION Run COMMAND with root directory set to NEWROOT.


0

In 2021 we can also suggest for linux distributions with systemd the use of systemd-run as a way to detach a process and keep it running after closing ssh login. One can launch a command and later inspects status: systemd-run --unit=background_cmd_service --remain-after-exit command # later on journalctl -b -u background_cmd_service systemctl status ...


-1

A simple command is ls | xargs du -sh


0

With zsh: autoload zmv zmv -n '(*) - (*) (\(<->\))(#q/)' '$1 $3 $2' Remove -n (dry-run) when happy.


1

A docker based one liner so you don't have to have any particular language installed: docker run --rm -i -p 8000:8000 -v $(pwd):/app -w /app ruby:alpine ruby -run -ehttpd . -p8000


2

The site may serve pages with a LAST-MODIFIED header: do a HEAD request and extract that header. curl --silent --head https://glennj.github.io | grep -i '^last-modified:' Not all sites return that header though.


2

First, get a fingerprint for the current state as a baseline: curl --silent www.example.com | md5sum > www.example.com.md5 Then, you can subsequently check to see if the fingerprint changes: curl --silent www.example.com | md5sum > www.example.com.md5new if ! cmp www.example.com.md5 www.example.com.md5new > /dev/null; then printf "%s has ...


1

You have provided qualifiers (-W and -n) but no action for the net command to execute. It responds by giving you the list of actions that it can perform, for example, net status shares (Update your question to tell us what you're trying to achieve and maybe someone here can help you with the appropriate command.)


0

You can use: ls -lA | awk '{print $9}' It will work if you happen not to have any files with spaces in their names.... otherwise a slightly more convoluted approach may work: ls -lA | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0;}


1

Running a command in the background allows you working on in that shell, but does NOT prevent the command from being killed once you exit the session (e.g. log out from the desktop session, end an ssh-session, exit the tty). nohup is meant for starting long-running processes that should run on a server even when the user logs out.


0

There are two sets of commands that can do this, xclip and xsel, and they can be used interchangeably. In order to use the clipboard used by graphical applications (rather than the terminal selection buffer), an option must be specified. To copy into the clipboard: uptime | xclip -selection clipboard # or uptime | xclip -sel clip # or uptime | xsel -ib To ...


4

Late to this thread but wanted to post what I found. Needed to print a large PDF file (200+ pages) as a grouping of signatures for bookbinding. I used pdfjam to make the signature sets: pdfjam --landscape --signature 16 filename.pdf I opened the new pdfjam file in a viewer and printed odd pages. I put the stack of printed pages back into the printer ...


Top 50 recent answers are included