Tag Info

Hot answers tagged

193

Try the watch command. Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>] [--no-title] [--version] <command>` So that: watch -n1 command will run the command every second, forever. On Mac OS X, you can get watch from Mac Ports, or you can get it via Homebrew: brew install watch


66

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


43

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


36

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


35

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


35

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


29

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.


27

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

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


21

One problem that all the answers posted so far have is that the time the command is executed can drift. For example, if you do a sleep 10 between commands, and the command takes 2 seconds to run, then it's going to run every 12 seconds; if it takes a variable amount of time to run, then over the long term the time when it runs can be unpredictable. This ...


21

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


21

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


20

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


18

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


16

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


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


12

This is just a shorter version of other while+sleep answers, if you are running this kind of tasks often as your daily routine, using this saves you from unnecessary key presses, and if your command line starts to get longer understanding this one is a bit easier. But this one starts with sleeping first. This is generally useful if you need to follow ...


12

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


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


11

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)


10

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


10

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


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


9

Unfortunately, none of the POSIX command line utilities provide arithmetic on dates. date -d and date +%s are the way to go if you have them, but they're GNU extensions. There's a clumsy hack with touch that sort of works for checking that a date is at least n days in the past: touch -t 201009090000 stamp if [ -n "$(find stamp -mtime +42)" ]; then ... ...


9

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


9

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


9

From a search through the man pages, on a Linux system, I find that the command supporting a --human-readable option are the following: df dir du ls rsync vdir. This search is obviously limited to installed packages on this particular machine. For each of them you can define an alias in ~/.bashrc if you use bash as a login shell (or a function, if you ...


9

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



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