Tag Info

Hot answers tagged

90

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 ...


46

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

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 ...


41

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

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 ...


32

I know there is already a selected answer, but you can get the requested behavior with just ls: ls -ld -- */ This will list all the directories in the current working directory where it is run. To get all the subdirectories of some other folder, just try: ls -ld /path/to/directory/*/ Note that the -l is optional.


29

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 ...


28

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 ...


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 ...


26

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

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 ...


24

It depends on what you're doing. The install command is normally used in installation scripts that come with packages and source code for installing a binary to your system. It can also be used to install any other file or directory. In addition to the -d and -c options you have -m for specifying the new permissions of the file to be installed, so you don't ...


21

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


19

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

As of Feb 2013 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. ‘4G’ ==> ‘4,000,000,000’). E.g. : echo 5607598768908 | numfmt --to=iec-i outputs: 5.2Ti Various other examples (including filtering, ...


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 ...


15

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 ...


15

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

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 ...


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

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

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 marks end of parameter (option) list. http://linux.about.com/library/cmd/blcmdl1_compgen.htm


11

It rather depends on what you intend by 'command'. From one perspective a command is simply an executable called from the command line, therefore ls and ls -alh /tmp/foo/bar/*tar.bz are both the command ls. Another perspective is that a command is the sum of its parts, meaning that the above example is 2 distinct commands. If your intention is to count ...


11

I recommend reading a book on unix or Linux shell and command line usage, in order to learn basic usage and get a feeling for some advanced features. Then you can turn to reference documentation. The usage of specific commands is described in their manual. man cat will show the manual of the cat command on your system. Manual pages are usually references, ...


10

The xwininfo command gives this kind of output, but you do have to click on the window you want info on: % xwininfo xwininfo: Please select the window about which you would like information by clicking the mouse in that window. xwininfo: Window id: 0xa0000d "flask" ... So doing: xwininfo | grep 'Window id:' might give you something ...


10

xdotool exposes the pointer location (xdotool getmouselocation). None of xdotool, xwininfo or wmctrl 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 QueryPointer message). Here's a simple Python wrapper script around this call (using ctypes). Error checking ...


10

The output of uname is not designed to be cryptic; the reason it doesn't show what you consider useful information is that its purpose is to display machine and kernel identification, but not operating system identification. You can still generally guess the Linux distribution, because people who compile kernels tend to include some information in the kernel ...


10

For bash, the primary resource is man bash. For builtins specifically, there is the help builtin. Here is a quote from help printf. In addition to the standard format specifications described in printf(1) and printf(3), printf interprets: %b expand backslash escape sequences in the corresponding argument %q quote the argument in a way ...



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