Tag Info

Hot answers tagged

34

This question is addressed in BashFAQ/032. In your example, you would: { time sleep 1; } 2> /dev/null The reason why time sleep 1 2>/dev/null doesn't behave how you're expecting is because with that syntax, you'll want to time the command sleep 1 2>/dev/null (yes, the command sleep 1 with stderr redirected to /dev/null). The builtin time works ...


18

Use head: ls -l | head -n 15 10 lines is the default. Read the head man page for more options. (older versions of head also support usage without the explicit -n as in head -15)


17

because basename wants just one parameter... not LOTS of. and xargs creates lots parameters. to solve your real problem (only list the filenames): find . -name '*.deb' -printf "%f\n" which prints just the 'basename' (man find): %f File's name with any leading directories removed (only the last element).


15

I'm a big fan of GnuWin32. You can download just the packages you need; each stands alone so you don't need to install any core Unix emulation layer like with Cygwin.


14

Try find /srv/www/*/htdocs/system/application/ -name "*.php" -exec grep "debug (" {} \; -print This should recursively search the folders under application for files with .php extension and pass them to grep. An optimization on this would be to execute: find /srv/www/*/htdocs/system/application/ -name "*.php" -print0 | xargs -0 grep -H "debug (" This ...


13

If you create new session, you can use screen -S <mysession> In already running session, hit Ctrl-a and type :sessionname <mysession>


11

To remove a file named -x, use rm -- -x (-- means end of options) or rm ./-x.


11

In the first example, your shell will first expand the *.c to match all files in the current directory which end in .c. So, if you have one.c, zwei.c, and tres.c in your directory, your shell will expand this to find . -name one.c zwei.c tres.c and find will probably get confused because you're passing a couple extra arguments after -name one.c -- ...


10

Yes, there is. There are quite a few projects that use idle computers for scientific research, the most famous (at least the ones I know) are: SETI@home: SETI@home is a scientific experiment that uses Internet-connected computers in the Search for Extraterrestrial Intelligence (SETI). You can participate by running a free program that downloads and ...


9

Your particular question about time builtin has been answered, but there are some commands that don't write either to stdout or to stderr. A classic example is the Unix command crypt. crypt with no arguments encrypts standard input stdin and writes it to standard output stdout. It prompts the user for a password using getpass(), which by defaults outputs ...


9

It is fairly common to ask this type of question in interview settings. A common way to handle files with dashes is either: $ rm -- -f $ rm ./-f


9

The nproc limit you are talking about applies to runable entities, it is thus limiting threads (and therefore, processes containing them). Every process has at least one thread (the primary thread), so that only threads can be run. Strictly speaking, processes are not "runable". I tested the code in daya's answer (also added sleep(1); in thread code) and ...


9

There is no way to save a screen session in the fashion that you desire. What I did was the next best thing: scripted autossh to connect to my servers and set up my rig the way I like it. Love it. Local connection down, I wait, it comes back up and there's my work ( I use nested screens ). Server down or rebooted, I wait, and am back in my default ...


9

Use the --spider option. --spider When invoked with this option, Wget will behave as a Web spider, which means that it will not download the pages, just check that they are there. You can use it to check your bookmarks, e.g. with: wget --spider --force-html -i bookmarks.html


9

Try this: find . -name '*.deb' | xargs -n1 basename


8

To print the fingerprint of an on-disk armored key without importing it, just use --with-fingerprint: > gpg --with-fingerprint jm3.asc pub 1024R/9112BC51 1996-02-05 john manoogian <jm3@*> Key fingerprint = C9 DC 27 29 0E 1A DB 50 21 C8 64 08 15 29 41 86 uid john manoogian <jm3@foo... uid ...


7

unxutils has old versions of a bunch of some of the most useful utilities. including grep for example. gnuwin32 has later(more up to date) versions, of a much larger number of utilities. That's obviously a major advantage. Bear in mind that gnuwin32 has that major advantage. With unxutils, you can run into issues as it uses old versions, and when looking ...


7

Wikipedia has a list of distributed computing projects that you could contribute to. You could also "mine" bitcoin, although I'm not sure how much money you'd net after paying for electricity.


6

Because they're Linux apps, that depend on the Linux kernel API. Windows natively doesn't provide that API, so the Cygwin DLL was created to do that. Linux apps can then be built against the Cygwin DLL, which provides (most of) the Linux services the application expects.


6

A common question in Unix. The main way is to give the full path name to the file, so it doesn't have a dash in front of it: $ rm -file.txt unknown option -l $ rm ./-file.txt #No problem! $ rm $PWD/-file.txt #Same thing Some commands, you can use a dash by itself (or a double dash) to end the options. However, this is not necessarily true with all ...


6

find is not even needed for this example, one can use grep directly (at least GNU grep): grep -RH --include='*.php' "debug (" /srv/www/*/htdocs/system/application/ and we are down to a single process fork.


6

Use bc -l, which preloads the math library and the default scale is set to 20. $ bc -l bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 4/3 1.33333333333333333333


6

Some solutions: UnxUtils - Last updated 4/24/2013 GNUWin32 - Last updated 12/27/2010 Finally, if you want comprehensive, you're after Cygwin, which is the "standard" method of getting GNU tools on Windows, but is ... rather bulky. And the moment you have some third-party software installed, where the Windows binary was built using Cygwin and which ...


6

Try this: awk '{print $0" "length($4)}' infile | sort -k5,5rn | sed -e 's/ [0-9]*$//' > outfile


5

You can set the scale with scale=2 Then division works as expected: scale=2 15/12 1.25 To quote from Wikipedia: All numbers and variable contents are arbitrary precision numbers whose precision (in decimal places) is determined by the global scale variable.


5

I understand, that I am not allowed to do some modifications to Linux, then compile it, put it in CD and start selling or distributting without source code, right? Correct and... because it's a copy-left license, if you create something based on the original source covered by this license, that must also be covered by the same license. Ex. If you download ...


5

Emacs is an extensible system for editing text built on top of a powerful programming language. With a typical text editor you can only do what the author thought to include commands for. Emacs can be made to do pretty much anything you can think of. As an example: Long ago I wrote a program to read mail inside of Emacs. It supported MIME, IMAP, POP, ...


4

you have to use rm -- <filename> Ex: rm -- -f


4

Read the documentation more thoroughly. It seems once I'm in a session I can name it using screen -S <name>


4

Don't bother doing that. Just install MinGW, specifically MSYS.



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