Tag Info

Hot answers tagged


The old-style backquotes ` ` do treat backslashes and nesting a bit different. The new-style $() interprets everything in between ( ) as a command. echo $(uname | $(echo cat)) Linux echo `uname | `echo cat`` bash: command substitution: line 2: syntax error: unexpected end of file echo cat works if the nested backquotes are escaped: echo `uname | \`echo ...


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


sudo touch /bin/rm && sudo chmod +x /bin/rm apt-get download coreutils sudo dpkg --unpack coreutils* And never again. Why didn't you used sudo with apt-get? Because the download command doesn't require it: download download will download the given binary package into the current directory. So, unless you are ...


There are lots of options!!! Summary $ echo $((20.0/7)) $ zcalc $ bc <<< 20+5/2 $ bc <<< 'scale=4;20+5/2' $ expr 20 + 5 $ calc 2 + 4 $ node -pe 20+5/2 # Uses the power of JavaScript, e.g. : node -pe 20+5/Math.PI $ echo 20 5 2 / + p | dc $ echo 4 k 20 5 2 / + p | dc $ perl -E "say 20+5/2" $ python -c "print 20+5/2" $ python -c "print ...


Don't go straight to du /. Use df to find the partition that's hurting you, and then try du commands. One I like to try is du -h <dir> | grep '[0-9\.]\+G' because it prints sizes in "human readable form". Unless you've got really small partitions, grepping for directories in the gigabytes is a pretty good filter for what you want. This will ...


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


Try out multitail. This is an ├╝bergeneralization of tail -f. You can watch multiple files in separate windows, highlight lines based on their content, and more. multitail -c /path/to/log The colors are configurable. If the default color scheme doesn't work for you, write your own in the config file. For example, call multitail -cS amir_log /path/to/log ...


debian and its derivatives (and probably most other distributions) come with busybox which is used in the initramfs. busybox bundles most core command line utilities in a single executable. You can temporarily symlink /bin/rm to /bin/busybox: ln -s busybox /bin/rm To get a working rm (after which you can do your apt-get install --reinstall coreutils). ...


One of the following 2 should work: $ nohup redshift & or $ redshift & $ disown See the following for a bit more information on how this works: man nohup help disown Difference between nohup, disown and & (be sure to read the comments too)


This expands somewhat on the !! trick mentioned in this answer. There are actually a bunch of history-related commands that tend to get forgotten about (people tend to stab Up 100 times instead looking for a command they know they typed). The history command will show a list of recently run commands with an event designator to the left !N will substitute ...


I'd strongly suggest not to use find -L for the task (see below for explanation). Here are some other ways to do this: If you want to use a "pure find" method, it should rather look like this: find . -type l -xtype l (xtype is a test performed on a dereferenced link) This may not be available in all versions of find, though. But there are other options ...


Alternatively, you can write: gzip < file > file.gz When not given any argument, gzip reads its standard input, compresses it and writes the compressed version to its standard output. As a bonus, when using shell redirections, you don't have to worry about files called "--help" or "-" (that latter one still being a problem for gzip -c --). Another ...


Use "--" to make rm stop parsing command line options, like this: rm -- --help


If you're just switching between two directories, you can use cd - to go back and forth.


You want to be using GNU Screen. It is super awesome! ssh me@myserver.com screen #start a screen session run-a-long-process CTRL+a , d to detatch from your screen session exit #disconnect from the server, while run-a-long-process continues When you come back to your laptop: ssh me@myserver.com screen -r ...


Use nohup to make your process ignore the hangup signal: $ nohup long-running-process & $ exit


Because they didn't exist originally, and the default behavior is backwards compatible. Also, because they don't exist on all unix variants, and the default behavior is compatible with other unix variants. For many tools, because they are intended to be parseable by other tools. This is rarely the case for ls, but parsing the output of du or df is ...


Bash: shopt -s autocd Zsh: setopt autocd tcsh: set implicitcd Also, 'autojump' is a useful tool. Once installed it remembers directories so that you can type j abc and if you've visited abc before, say x/d/f/g/t/abc then it will cd to there! https://github.com/joelthelion/autojump


bash -- insert preceding line's final parameter alt-. the most useful key combination ever, try it and see, for some reason no one knows about this one. press it again and again to select older last parameters. great when you want to do something more to the argument/file you used just a moment ago.


The difference is in what data the target program is accepting. If you just use a pipe, it receives data on STDIN (the standard input stream) as a raw pile of data that it can sort through one line at a time. However some programs don't accept their commands on standard in, they expect it to be spelled out in the arguments to the command. For example touch ...


Your shell is meant to evaluate that shell code output by ssh-agent. Run this instead: eval "$(ssh-agent)" Or if you've started ssh-agent already, copy paste it to your shell prompt (assuming you're running a Bourne-like shell). ssh commands need to know how to talk to the ssh-agent, they know that from the SSH_AUTH_SOCK environment variable.


Just with sed, without any pipes : sed '1d;$d' file.txt NOTE 1 mean first line d mean delete ; is the separator for 2 commands $ mean last line


There's no built-in command, but you can easily write a function that calls mkdir then cd: mkcd () { mkdir "$1" cd "$1" } Put this code in your ~/.bashrc file (or ~/.kshrc for ksh users, or ~/.zshrc for zsh users). It defines a function called mkcd. "$1" will be replaced by the argument of the function when you run it. This simple version has several ...


There are two classes of builtins: Some commands have to be built into the shell program itself because they cannot work if they are external. cd is one such since if it were external, it could only change its own directory; it couldn't affect the current working directory of the shell. (See also: Why is cd not a program?) The other class of commands are ...


Yes. The standard grep tool for searching files for text strings can be used to subtract all the lines in one file from another. grep -F -x -v -f fileB fileA This works by using each line in fileB as a pattern (-f fileB) and treating it as a plain string to match (not a regular regex) (-F). You force the match to happen on the whole line (-x) and print ...


How do you feel about using awk instead of grep? chopper:~> ps aux | awk 'NR == 1 || /syslogd/' USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND root 19 0.0 0.0 2518684 1160 ?? Ss 26Aug12 1:00.22 /usr/sbin/syslogd mrb 574 0.0 0.0 2432852 696 s006 R+ 8:04am 0:00.00 ...


du can be depth-restricted: du -d 5 Will only recurse to depth 5. /EDIT: This counts only for the display; the tool will still determine the total size of the whole directory tree but this is still much faster than running a full du.


The {} syntax is Bash syntax not tied to the for construct. mkdir {A..Z} is sufficient all by itself. http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion

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