Hot answers tagged

42

To find out about a key binding. In bash: $ bind -p | grep -a '{' "\e{": complete-into-braces "{": self-insert $ LESS='+/complete-into-braces' man bash complete-into-braces (M-{) Perform filename completion and insert the list of possible com‐ pletions enclosed within braces so the list is available to the shell (see ...


10

You could do: echo -a -b -c | xargs -n 1 command Or: xargs -n1 command <<< '-a -b -c' with some shells. But beware that it affects the stdin of command. With zsh: autoload zargs # best in ~/.zshrc zargs -n 1 -- -a -b -c -- command Or simply: for o (-a -b -c) command $o None of those would abort if any of the command invocations failed ...


10

You can refer to the first word of the previous command line (command in your case) by history expansion !!:0 and then you can just add necessary arguments to it. command -a && !!:0 -b && !!:0 -c For example: % echo foobar && !!:0 spamegg && !!:0 baz echo foobar && echo spamegg && echo baz foobar ...


7

With GNU grep: grep -o '\b\w*\.swf\b' file Output: example.swf example2.swf example3.swf \b: a zero-width word boundary \w: word character \.: match one dot See: The Stack Overflow Regular Expressions FAQ


6

The kernel's terminal driver (termios) interprets the special keys that can be typed to send a signal to a process, send end of file, erase characters, etc. This is basic Unix kernel functionality and very similar on most Unix and Linux implementations. The stty command displays or sets the termios special characters, as well as other parameters for the ...


6

It is impossible to have NUL bytes in command line arguments, so the question is what do you want to happen in case there are NUL bytes in the standard input. As you've noted, your candidate solution #1 runs the command multiple times in this case. That's not ideal. But there is no ideal solution that lets you handle true binary input. As I see it, your ...


6

start cmd:> awk 'lines[$0]++ == 0' input Hi how are you hello today is monday I am fine


6

That is part of the GNU coding standards, so all GNU (and many non-GNU) software follows it. However, it's by no means an absolute standard; there are other ways of implementing this, such as: -Wlong-option: originated from the C compiler, and specified as such in POSIX. -long-option (i.e., single-dash): supported by most applications (usually as an ...


5

This is an easy job for sort, use the unique (-u) option of sort: % sort -u file1.txt hello Hi how are you I am fine today is monday To save it in file2.txt: sort -u file1.txt >file2.txt If you want to preserve the initial order: % nl file1.txt | sort -uk2,2 | sort -k1,1n | cut -f2 Hi how are you hello today is monday I am fine


4

Various ways of accomplishing this are discussed, along with the merits and drawbacks of each, in the article "Running bash commands in the background properly". Based mostly on that article and also my own reading of the POSIX specs for nohup, the most portable way to accomplish what you want is with: nohup inkscape ./Design.svg >/dev/null 2>&1 ...


4

This will print lines (with filename and line number) with repeated words: for f in *.txt; do perl -ne 'print "$ARGV: $.: $_" if /\b(\w+)\W+\1/' "$f" done For multi-line matching there's this, but you lose the line numbers because it's slurping in the file by paragraphs (that's the effect of the -00 option). The \W+ between the two words means any ...


4

You should take a peek at the venerable diction(1) and style(1) commands. They catch a variety of boo-boos. There are newish versions (GPLv3 here on Fedora 23). Install For example on Debian-based distributions, install the package diction, which includes style: $ sudo apt-get install diction At least in Fedora it is: $ dnf install diction Red Hat ...


4

grep is the command that implements the g/<RE>/p command in ed/ex (hence its name), that is, it prints the lines that match a given regular expression (regex or regexp for short). Here, '^[^:]\+::' is the regular expression (quoted so the shell doesn't treat some of those characters specially). More precisely (as there are several implementations of ...


4

You can use the df command: $ df -h Filesystem Size Used Avail Use% Mounted on udev 3.9G 0 3.9G 0% /dev tmpfs 799M 8.7M 790M 2% /run /dev/xvda1 50G 6.3G 41G 14% / tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup ...


4

Yes, it is provided by GRUB. The GRUB command shell is just as powerful as the shell. You can use it to discover boot images, kernels, and root filesystems. When you're at the grub> prompt, you have a lot of functionality similar to any command shell such as history and tab-completion. The grub rescue> mode is more limited, with no history and no ...


3

Since you are flexible about the final file names, and these are photos from a modern smartphone, I recommend exiftool to automatically organize and rename photos for you: first, make a copy/back up your ~/Pictures/iPhone so you always have an something to fall back on if needed run the exiftool on your command prompt with these options: $ exiftool -P -r ...


3

Assuming you're using bash: Try hitting ^Z (i.e., Ctrl-Z) to stop the process, move it to the background, and get another bash prompt. Type fg; not, the former continues the stopped process and returns when it finishes. Alternatively, figure out the proces id of the program you want to wait for, assume it's 2342. In a new shall, type until kill -0 2342; ...


3

Your problem comes from the ping command that never exits. You should make a loop that call ping for one test -c 1: while [ true ] ; do if ping -c 1 www.google.com | grep timeout ; then say fail ; fi ; sleep 1 ; done edit I wrote a bash while loop, may be you should adapt it to your shell program (It's been a long time I play with mac os X), I added ...


3

How about a shell function wrapping a loop? yourcmd() { local arg for arg; do thing "$arg" || return done } Where "thing" is the actual command you want to invoke. Then simply yourcmd -a -b -c You can even generalize this to any command: splitargs() { local cmd arg cmd="$1" shift for arg; do "$cmd" "$arg" ...


3

I know this is rather old, but... If you do not actually want to display the rate, but only want to watch if something is happening on copying of a large file, you can also just use the watch command (also works with mv): cp /path/to/myfile /path/to/target/myfile Then, in another shell, or pushing the copy-command to the background (e.g. with Ctrl + Z ...


3

Here's what I ended up with: tr '[:space:]' '\n' < highlander_typo.txt | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | uniq -D I believe that's GNU tr syntax.


3

A umask value of 001 says that it is preventing the creation of files with other executable permissions. (Actually not preventing the creation, as preventing the executable-permissions). A 666 mode in an open statement only permits user+group+other for read and write permissions. So the umask has no effect on that. However umask does not affect chmod.


3

You can achieve that by using the following notation: echo "${!index}" If you want to process positional arguments, I suggest to use getopt (not getopts), though.


3

You can use env your-command to avoid interference from the shell. Example: $ env kill -L 1 HUP 2 INT 3 QUIT 4 ILL 5 TRAP 6 ABRT 7 BUS 8 FPE 9 KILL 10 USR1 11 SEGV 12 USR2 13 PIPE 14 ALRM 15 TERM 16 STKFLT 17 CHLD 18 CONT 19 STOP 20 TSTP 21 TTIN 22 TTOU 23 URG 24 XCPU 25 XFSZ 26 ...


3

You can use df with the total flag --total produce a grand total df --total or df --total -h for human readable output (i.e K,M,G) This wil produce output such as Filesystem Size Used Avail Use% Mounted on /dev/sda2 23G 13G 8.7G 60% / udev 4.0G 124K 4.0G 1% /dev tmpfs 4.0G 72K 4.0G 1% /dev/shm ...


3

First step Replace spaces with line ends using sed Second step Filter the output using grep Example sed -e s/\ /\\n/g file | grep .swf


3

You can do: grep -o '[^ ]*\.swf' file.txt [^ ]* matches zero or more non-space characters \.swf matches literal .swf Example: % grep -o '[^ ]*\.swf' file.txt example.swf example2.swf example3.swf


2

I made a tool, ProxyMan, to simplify the entire task. You can download it from this link. Also, you can have a look at the code if you are more interested to know the backend functioning. Download the zip file,extract them, go to the location of extracted files in terminal and following commands would help you: bash main.sh: to set and unset proxy. bash ...


2

I ended up using precmd I put alias precmd 'source ~/.tcsh/precmd.tcsh' into my .cshrc file and moved my prompt set into that file. Source of the .tcsh set tmpstr = `(git status --untracked-files=no --porcelain >! ~/out ) >&! ~/out1` #echo $tmpstr #for debugging if !( -s ~/out ) then if !( -s ~/out1 ) then set gitstr = ...


2

Amidst the creative and insightful answers, here's something simple in the name of typing fewer characters: # under the assumption that you have a frequently-used set of flags: -a -b -c alias c='command -a && command -b && command -c' # slightly more generally, name some aliases according to the set of flags alias cabc='command -a ...



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