Tag Info

Hot answers tagged

17

In Bash, you can use Bash's built in string manipulation. In this case, you can do: > text="some text with spaces" > echo "${text// /}" sometextwithspaces For more on the string manipulation operators, see http://tldp.org/LDP/abs/html/string-manipulation.html However, your original strategy would also work, your syntax is just a bit off: > ...


15

There are several options to do so: You can use a terminal multiplexer like screen or tmux. In screen, for example, the shortcut Ctrl+a - a, has the same functiononality as Alt+Tab in graphical environments: switch to the last screen. Or you use vim's internal function. Type :!command in vim's command mode. For example: :!ls -l. After the command ...


7

You don't need echo command at all, just use Here String instead: text=$(tr -d ' ' <<< "$text") Just for curiosity I checked how much time such a trivial task takes for different tools. Here are the results sorted from slowest to fastest: abc="some text with spaces" $ time (for i in {1..1000}; do def=$(echo $abc | tr -d ' '); done) 0.76s user ...


5

Just modify your text variable as below. text=$(echo $text | tr -d ' ') However, if we have control characters this might break. So, as per Kasperd's suggestion, we could have double quotes around it. So, text="$(echo "$text" | tr -d ' ')" will be a better version.


4

$ sed 's. ..g' <<< $text namewithspace


4

You can press Ctrl-z to stop vim and go to CLI, do whatever you need to (edit another vim file perhaps), then press fg on command line to return back into vim at the same place you left off at. If you didn't see the command fg being typed, then it's very likely that screen was being used.


3

I would delete all non-alpha characters using tr and count the number of resultant characters. Passing both the tr solution and your solution to bash's time built-in suggests the tr solution is about 5 times faster, at least on my system tr -cd '[:alpha:]' <filename | wc -m


3

I don't know about the "suddenly returned ..." part, but the first bit is fairly trivial. The :shell command opens your shell. For me, it opens at wherever I was when I opened vim, so it is inheriting settings from vim, as G-Man notes. That gives you the CLI mode. You can also open another vim from it. Quitting this shell returns you to wherever you where in ...


2

With posix sed: $ echo AbbigailAbieAbbyAbbi | sed 's/.\{4\}/& /g; s/ //' Abbigail Abie Abby Abbi


2

With GNU sed: $ echo AbbigailAbieAbbyAbbi | sed -e 's/.\{4\}/& /2g' Abbigail Abie Abby Abbi


2

Word of warning when using wc -l because wc -l functions by counting \n, if the last line in your file doesn't end in a newline effectively the line count will be off by 1. (hence the old convention leaving newline at the end of your file) Since I can never be sure if any given file follows the convention of ending the last line with a newline or not, ...


1

If the container is running systemd: $ systemd-detect-virt lxc


1

who : Print information about users who are currently logged in. whoami : Print effective username of being ran whoami. For example: mohsen@debian:~$ who ## list logged in usernames mohsen :0 2014-09-19 16:31 (:0) mohsen pts/0 2014-09-19 16:32 (:0) mohsen pts/1 2014-09-19 19:42 (:0) mohsen@debian:~$ whoami mohsen ...


1

I am logging in as root in my shell and typing who and this is the output. who root tty1 2014-08-25 14:01 (:0) root pts/0 2014-09-05 10:22 (:0.0) root pts/3 2014-09-19 10:08 (xxx.xxx.edu) It effectively shows all the users that have established a connection. ssh ramesh@hostname Running who again will result in ...


1

Solution for Ubuntu, works for pulse.. so will most likely work for most OS using pulse pacmd list-sink-inputs Here is one for alsa #!/bin/sh for i in /proc/[0-9]*/fd/* do var="$(readlink $i)" if test x"$var" != x"${var#/dev/snd/pcm}" then echo $i fi done


1

Mounting a HDD To mount a HDD that's physically connected to your system, you first need to identify the device handle that's been assigned to it. I typically use the command line tools blkid or lsblk to find out this information. blkid $ sudo blkid /dev/sda1: UUID="XXXXXX" TYPE="ext4" /dev/sda2: UUID="XXXXXX" TYPE="LVM2_member" ...


1

ls /boot ls / … however you might want to expand upon your question, as Debian / SSD drive / live CD are (more or less) irrelevant to listing directory contents. Maybe you're asking where the boot and root partitions from a live CD are mounted, e.g. /mnt/gentoo and /mnt/gentoo/boot?.



Only top voted, non community-wiki answers of a minimum length are eligible