New answers tagged

0

ruby is a nice concise language for this kind of stuff ruby -e ' words = ARGV.collect {|fname| File.readlines(fname)}.flatten.map(&:chomp) words.combination(2).each {|pair| puts pair.join("")} ' file[123] > file4 onetwo onethree onefour onefive onesix twothree twofour twofive twosix threefour threefive threesix fourfive foursix fivesix


0

I once found a script (I don't remember where all I have is my bash_history). This is not the solution, it's a workaround. I know it's not exactly what you asked for but it may be useful. It uses the microphone to detect silence. This is my script: while :; do rec -t raw /dev/null rate 32k silence 1 0.1 4% 1 1.0 15%; clementine -t; sleep ...


0

ssh <some other pc> /path/to/some/script.sh


1

Assuming the total size of the input files is smaller than getconf ARG_MAX, (i.e. the maximum command line length), then this should work: set -- $( cat file[123] ) for f in $@ ; do shift for g in $@ ; do echo $f$g done done > file4 cat file4 outputs: onetwo onethree onefour onefive onesix twothree twofour twofive twosix threefour ...


0

If you are using an embedded system the busybox that is common on systems like OpenWRT has very limited functionality and only 2-3 flags are supported. If you want a quick and dirty way of printing dmesg output on screen continually as events change, a simple bash loop works fine. It's not ideal but as I mentioned the BusyBox dmesg is missing a lot of ...


2

One way is to use alias shell builtin, for example: alias Python='python' alias PYTHON='python' alias Python='python' alias pyThoN='python' Also see this post for a better approach regex in alias


0

Completion does this. Press Tab to list the files starting with the part of the word containing the cursor up to the cursor. That is, if the cursor is at | in xdg-open fo|.pdf, then pressing Tab lists all the files beginning with fo, whether they have the .pdf extension or not. This makes completion most useful when you've only typed a prefix of the file you ...


0

There's no way to automatically grab the output of the previous command (not under any usual environment). But if you manually select the output with the mouse, then you can run less `xsel` or, if the output contains spaces or wildcard characters and you aren't running zsh, less "`xsel`" If you don't mind running the command again, press Up then add ...


2

First of all, I can’t reproduce the results you claim for the command you showed.  I got the files being renamed to another directory_file1.jpg, another directory_file2.jpg, etc., but still under the some directory directories. Secondly, because of the depth of your directory structure, you should be using -mindepth 4 instead of 2.  Thirdly, I strongly ...


0

I tested these command on Linux Debian in the terminal. If your terminal is wide enough, just stating "ls" will give columns but it won't use all the space (width) of the terminal. I made the terminal as wide as the screen and "ls" just produced 4 columns. Problem is if you pipe this into "more" you loose the columns. Next I used "ls -w200" in the ...


2

less $(find . -name myfile.txt) less `find . -name myfile.txt` The first is, I believe, both POSIX-compliant and nest-able. The second, I believe, is more portable.


2

Similar to @coffeeMug, this is the more up-to-date way to doing this as it is apparently faster: find . -name "*.log" -exec ls -l '{}' + I'll also point you to CommandLineFu, which is always helpful with these things.


2

You can achieve this using find's -exec flag: find . -name "*.log" -exec ls -l '{}' \; In this example find searches for all log files in current directory and then list them using ls -l. In your case you should replace ls with less. See the ACTION part of find man page here find(1) man page.


0

For commands like chown that have their own recursion it is fastest to use that option: chown -R owner:group * .* as Stephen indicates. However it is useful to know that the main problem that slows down your use of find is that you invoke chmown on every single directory and file found. It is much quicker to use: find . -type f -exec chown ...


2

Use chown's recursive option: chown -R owner:group * .* Specifying both * and .* will match all the files and directories that find would. The recommended separator nowadays is : instead of .. If you want to change the current directory's ownership too, this can be simplified to chown -R owner:group .


1

mkdir backupcache cp -rp .cache/. backupcache that way only the content (/.) of .cache gets copied, not the .cache part.


0

I would like to suggest you to put all your aliases and functions in a file, tipically ~/.bash_aliases. If not yet present, you can add in your .bashrc (or wherever you need) those lines: # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See ...


1

I would put environment variables in .bash_login or .bash_profile, since they are (when exported) inherited to subshells and don't need to be reset for every shell invocation. Not that resetting them would cost practically anything, but in case I want to set an envvar to something else for the duration of a subshell. That's hard to do if the .bashrc ...


0

This is also an experience based response rather that one backed up by hard data. I find that when deleting many files in similar trees with a lot of cross links it seems faster to delete isolated subtrees in parallel. Let me try and explain with a diagram: topdir1 |-a1 |-b1 |-c1 topdir2 |-a2 |-b2 |-c2 topdir3 |-a3 |-b3 ...


0

In my experience, the best way to speed up rsync+hardlink based backups was to decrease the number of files you have. A large number of small files slows down rsync a lot. If you can organize your data in such a way so that your mostly small-file, mostly read-only directories get tarred up, you should see a significant speed up in your backup script. (With ...


1

The df is reporting a small number because you're mostly deleting directories, which are relatively small. Also, depending on the filesystem, changes to directories and changes to the number of links to a file are journaled and/or synced to the disk immediately, since they're critical for fault recovery, and thus slower. That's actually a testament to the ...


2

The ? is part of a mechanism called "pathname expansion" in the shell. Colloquially, the shell mechanism is called "globing". The basic glob makes use just of three characters: * ? and [ that build "patterns". An asterisk * means: Any character in any quantity (any string). A question mark (?) means: Any character one time. The square braces ...


3

? is a special character in pattern matching, which match any single character. So the command means find all files and directories in /foo/path and its subdirectories, whose names are exactly one character long. The \? is used to prevent your shell from performing filename generation. You can use other quoting mechanisms: find /foo/path -name '?' or: ...


1

Since the question is essentially asking for opinions, you will get different answers. A good design practice, for example, uses as few places as possible to provide a given feature. Some put information like this in the system area to reduce the amount of work done by users to customize their shell environment. In my environment, I use the terminal ...


1

I put PS1 code in bashrc all the time. My code is as follows: export PS1="\[\e[01;37m\][\[\e[0m\]\[\e[01;32m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[01;34m\]\h\[\e[0m\]\[\e[00;37m\] \[\e[0m\]\[\e[00;37m\]\t\[\e[0m\]\[\e[01;37m\] \W \e[1;37m(\e[1;32m|\e[1;33m|\e[1;31m|\e[1;37m]\\$ \[\e[0m\]" I use a different PS1 for root (/root/.bashrc) - red username, ...


0

I can't see how your use of xargs in this way is anything but slow. My manpage says -P is the number of processes and -n is the number of arguments. There's no special value for -P0, so that's likely ignored (or, if honored, you get zero processes, which would explain 24 hours of nothing!). And -n1 ensures you get one exec(2) for each filename, which is ...


1

If you see a mismatch between what df and dh report, you may have open files which are deleted but are still being written to. This takes up disk space (according to df), but is not reported anywhere (such as du) because the space doesn't belong to any existing file. If you experience this, you may need to restart some services (or the machine for a brute ...


0

If you really reluctant about writing scripts you may find Here document handy. Short said, you add << SOMETEXMARKER to the end of the line and continue entering as many commands for remote host as you like. Then, on the last line you enter (at the very beginning of the line) the same SOMETEXTMARKER and that makes the entered commands get executed ...


3

It might be easier to simplify the command so that you have fewer special characters on which the shell might choke: ssh jboss@myTargetServer 'ps -p $(cat /var/run/jboss-as/jboss-as-standalone8.pid) -o %cpu= 2>/dev/null' The trailing 2>/dev/null throws away the error text in the event that the PID file either cannot be found or contains a stale PID. ...


1

The second command as you have it runs the code part ($()) in local subshell. You need to make it run on the other side by escaping special characters (basically $): ssh jboss@myTargetServer tmpValue=\$(cat /var/run/jboss-as/jboss-as-standalone8.pid) \ && top -b -U jboss -n 1 |grep \$tmpValue |awk '{print $9}' or put it all into the apostrophes ' ...


1

All of the above examples will tell you the size of the data on disk (i.e. the amount of disk space a particular file is using, which is usually larger than the actual file size). There are some situations where these will not give you an accurate report, if the data is not actually stored on this particular disk and only inode references exist. In your ...


2

I would recommend putting those commands into a script that you remotely call with ssh. Otherwise you'd need to put the whole "remote" part of the command line into quotes and properly escape everything inside. This can be tedious and error prone. That's why remote script call.


0

Something like this should work using python which is commonly available: cat slowest-names.log | python -c 'import collections, sys; print collections.Counter(sys.stdin);' This assumes word per line. If there are more, splitting should be easy as well.


0

Clean xrandr output for imagemagick use xrandr |grep \* |awk '{print $1}'


3

Each line you write must have a command, usually the first word. To get something printed, a common command is echo. If the pwd (present working directory) has files a, aa, bb, and ccc. Then, this command will print all files in the directory: $ echo * a aa bb ccc And this command will print all files in the pwd that have one character: $ echo ? a ...


2

Looking in /media is a reasonable way to find hotplug block devices. You can also use lsblk to list the block devices and whether they are hotpluggable: $ lsblk -l -p -o name,rm,hotplug,mountpoint NAME RM HOTPLUG MOUNTPOINT /dev/sda 0 0 /dev/sda1 0 0 / /dev/sda2 0 0 [SWAP] /dev/sda3 0 0 /home /dev/sdc 0 1 ...


0

There is no difference between internal and external devices, so no, there's no better way than to hope mounting has been consistent enough that all external devices (and only those) are mounted under /media. But a user with the right permissions can easily mount e.g. an USB stick anywhere.


1

One way with find and install: find /var/public/voicelogging/quality_monitoring -name \*.WAV -exec sh -c ' bn=${0##*/}; x=${bn%%-*}; dt=${x##*_}; y=${bn%_*}; id=${y##*_} install -D "$0" "/home/username/logging/${id}/${dt}/${bn}"' {} \; this uses parameter expansion to extract the date: ${dt} and the user id: ${id} from the filename and then uses install ...


2

It's a kind of necroposting but I've had the same problem recently (with a different backend) and found that the reason is in a wrong Content-Type. By default it's "text/plain" or "text/html", and in my case curl -H "Content-Type: application/json" -d ... solved the issue.


0

I'm not sure why Perl isn't acceptable here. On the inputs you provided, this line gives the output you asked for: perl -0777p -e 's/.* > (.*) joined the channel\.\n(((?!.* \1 (was kicked from channel\.|was banned from channel\.)\n).*\n)+?.*\1 disconnected)/\2/mg' irc.txt The -e argument is exactly the first argument to your magicregextool except that ...


2

Try: cp /usr/share/backgrounds/*.jpg /week/pictures/final/jpg/ 2> cp.err Note that the cp.err file will be created in the directory where you are when you run the command. If you want the error file in a differente directory, you can do: cp /usr/share/backgrounds/*.jpg /week/pictures/final/jpg/ 2> /desired_directory/cp.err


0

gparted uses resize2fs to change the partition's size. It doesn't take many arguments. Below are the ones I've found useful. -M shrinks to the file system's minimum size. -p shows a percentage indicator. -P prints the file system's minimum size and exits.


3

.epub files are .zip files containing XHTML and CSS and some other files (including images, various metadata files, and maybe an XML file called toc.ncx containing the table of contents). The following script uses unzip -p to extract toc.ncx to stdout, pipe it through the xml2 command, then sed to extract just the text of each chapter heading. It takes one ...


0

Thomas Dickey's answer addresses the issue in general, for any (ELF) binary. Given the way your question's phrased, you might find the __DATE__ and __TIME__ predefined macros useful; they allow the compilation date and time to be referred to within a program (so a program knows its own compilation date and time). Here's a quick example: #include ...


0

stat -c %z displays last creation/updating time of file and it's not changeable or preservable. Hence if you copy the file to other place, it will always get new now creation time. What are you looking for is stat -c %y, to display last modification time, which is usually preserved by most tools dealing with files and directories.


0

You can copy preserving the modification time, e.g., cp --preserve=timestamps source destination or (more generally: mode, ownership and timestamps) cp -p source destination although in some cases, preserving ownership is not wanted. Similarly, you can copy to remote systems using scp's -p option: scp -p source remote:destination but scp does not ...


2

When you use grep with color options it produces extra escape character sequences which tell the terminal to turn color on or off, these sequences introduce a risk of not being interpreted properly and causing unexpected results. You can view these by capturing grep's output With no color send greps output to output.txt % grep -o --color=none '.\+ middle ...


1

You are receiving that error because the program "update_prebinding" is not in your PATH, possibly because it is not installed on your system.



Top 50 recent answers are included