Tag Info

Hot answers tagged

138

More precisely, a double dash (--) is used in bash built-in commands and many other commands to signify the end of command options, after which only positional parameters are accepted. Example use: lets say you want to grep a file for the string "-v" - normally "-v" will be considered the option to reverse the matching meaning (only show lines that do not ...


59

The main differences are: wget's major strong side compared to curl is its ability to download recursively. wget is command line only. There's no lib or anything, but curl features and is powered by libcurl. curl supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, POP3, IMAP, SMTP, RTMP and RTSP. wget supports HTTP, HTTPS and ...


54

In the simplest calling of sed, it has one line of text in the pattern space, ie. 1 line of \n delimited text from the input. The single line in the pattern space has no \n... That's why your regex is not finding anything. You can read multiple lines into the pattern-space and manipulate things surprisingly well, but with a more than normal effort.. Sed ...


47

From your comments, you seem to be confused about exactly what a shell is. The kernel is responsible for managing the system. It's the part that actually loads and runs programs, accesses files, allocates memory, etc. But the kernel has no user interface; you can only communicate with it by using another program as an intermediary. A shell is a program ...


46

Set Membership $ grep -xc 'element' set # outputs 1 if element is in set # outputs >1 if set is a multi-set # outputs 0 if element is not in set $ grep -xq 'element' set # returns 0 (true) if element is in set # returns 1 (false) if element is not in set $ awk ...


43

It's usually used as a quick and dirty way to provide answers to an interactive script: yes | rm -r large_directory will not prompt you about any file being removed. Of course in the case of rm, you can always supply -f to make it steamroll the directory removal, but not all tools are so forgiving. Update A more relevant example of this that I recently ...


37

Using - as a filename to mean stdin/stdout is a convention that a lot of programs use. It is not a special property of the filename. The kernel does not recognise - as special so any system calls referring to - as a filename will use - literally as the filename. With bash redirection, - is not recognised as a special filename, so bash will use that as the ...


35

The following is what I ended up using to reliably create a temporary directory that works on both Linux and Darwin (Mac OS X), without hardcoding $TMPDIR or /tmp: mytmpdir=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'` Background: The GNU mktemp command requires no arguments. Plain mktemp will create a temporary file in the system temporary ...


33

I know there is already a selected answer, but you can get the requested behavior with just ls: ls -ld -- */ (Note that the '--' marks the end of parameters, preventing folder names beginning with a hyphen from being interpreted as further command options.) This will list all the directories in the current working directory where it is run. To get all ...


30

mknod was originally used to create the character and block devices that populate /dev/. Nowadays software like udev automatically creates and removes device nodes on the virtual filesystem when the corresponding hardware is detected by the kernel, but originally /dev was just a directory in / that was populated during install. So yes, in case of a near ...


28

Use perl instead of sed: $ perl -0777 -i.original -pe 's/a test\nPlease do not/not a test\nBe/igs' alpha.txt $ diff alpha.txt{,.original} 2,3c2,3 < not a test < Be --- > a test > Please do not -pie is your standard "replace in place" command-line sequence, and -0777 causes perl to slurp files whole. See perldoc perlrun to find out more about ...


28

Sort of. The shell has no idea what the commands you are running will do, it just connects the output of one to the input of the other. If grep finds more than 10 lines that say "hello world" then head will have all 10 lines it wants, and close the pipe. This will cause grep to be killed with a SIGPIPE, so it does not need to continue scanning a very ...


27

There are several different patterns for options that have been used historically in UNIX applications. Several old ones, like tar, use a positional scheme: command options arguments as for example tar uses tar *something*f "file operated on" *"paths of files to manipulate"* In a first attempt to avoid the confusion, tar and a few other programs ...


24

There is already a command for this: seq 100 104 will print these numbers on separate lines: 100 101 102 103 104 So just direct this output into a file: seq 100 104 > my_file.txt and seq 100 2 104 will print in increments of two, namely: 100, 102, 104


23

As of v. 8.21, coreutils includes numfmt: numfmt reads numbers in various representations and reformats them as requested. The most common usage is converting numbers to / from human representation. e.g. printf %s\\n 5607598768908 | numfmt --to=iec-i 5.2Ti Various other examples (including filtering, input/output processing etc) are presented ...


21

In linux there are many tools for that, for example lsblk, fdisk -l or parted -l. Example $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 238.5G 0 disk ├─sda1 8:1 0 200M 0 part /boot/efi ├─sda2 8:2 0 500M 0 part /boot └─sda3 8:3 0 237.8G 0 part ...


20

There are three levels of built-in utilities: Some utilities are really part of the shell as a programming language, even though they are not reserved words. They are control flow utilities (., :, break, continue, return, trap, exit, exec, eval), parameter-related utilities (set, unset, shift, export, readonly, local¹, typeset¹), alias utilities (alias², ...


18

No, there is no such standard tool. Since GNU coreutils 8.21 (Feb 2013, so not yet present in all distributions), on non-embedded Linux and Cygwin, you can use numfmt. It doesn't produce exactly the same output format (as of coreutils 8.23, I don't think you can get 2 digits after the decimal points). $ numfmt --to=iec-i --suffix=B --padding=7 1 177152 ...


17

-9 is the signal number (in this case SIGKILL), so kill -9 sends a SIGKILL to the process in question. This signal causes the process to terminate immediately (unless it's waiting in a kernel function). The signal can neither be ignored nor can the receiving process perform any clean up action after receiving the signal (i.e. a signal handler for SIGKILL ...


16

This marks end of parameter (option) list. http://linux.about.com/library/cmd/blcmdl1_compgen.htm


16

You can use file tool: $ file file.png file.png: PNG image data, 734 x 73, 8-bit/color RGB, non-interlaced $ mv file.png file.txt $ file file.txt file.txt: PNG image data, 734 x 73, 8-bit/color RGB, non-interlaced


14

Try just time instead of timethis. Although be aware that there's often a shell builtin version of time and a binary version, which will give results in different formats: $ time wget -q -O /dev/null http://unix.stackexchange.com/ real 0m0.178s user 0m0.003s sys 0m0.005s vs $ \time wget -q -O /dev/null http://unix.stackexchange.com/ 0.00user ...


13

First, from your experience with the second card, it seems that your reader is damaged and now damages the cards you insert into it. Stop using that reader immediately, and try to recover the card with another reader. If your data is at all valuable, try to get a brand-name reader with better quality than a bottom-price one. If the card is merely partly ...


13

xdotool exposes the pointer location (xdotool getmouselocation), and recent versions (since 2.20110530.1) indicate which window is at that location as well. None of xwininfo, wmctrl or older versions of xdotool appear to have a way to match a window by a screen position where it's visible. The underlying X library call is XQueryPointer (corresponding to a ...


13

In Bash the type shell built-in gives information about the executable things: aliases, functions, executables. See help type for details. # just check for existence type -t 'yourfunction' > /dev/null || echo 'error: yourfunction not found' # explicitly check for given type [[ "$( type -t 'yourfunction' )" != 'function' ]] && \ echo 'error: ...


13

When a program tries to write to a pipe and there is no process reading from that pipe, then the writer program receives a SIGPIPE signal. The default action when a program receives SIGPIPE is to terminate the program. A program can choose to ignore the SIGPIPE signal, in which case the write returns an error (EPIPE). In your example, here's a timeline of ...


12

sed has three commands to manage multi-line operations: N, D and P (compare them to normal n, d and p). In this case, you can match the first line of your pattern, use N to append the second line to pattern space and then use s to do your substitution. Something like: /a test$/{ N s/a test\nPlease do not/not a test\nBe/ }


12

Beside the main point mentioned in the previous answer the yes command can also be used to test high loads of CPU on a system. yes creates a process which acts as a dummy CPU loader and results in 100% processor usage. http://en.wikipedia.org/wiki/Yes_(Unix)


11

This is easier to do if you install something like xdotool. Then you can do: xdotool search --name "window name" windowsize 300 400 replace "window name" with a name or reg ex appearing in the window title (you can also search by window class and a variety of other things), and the two numbers appearing after windowsize are the width and height, ...



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