Hot answers tagged

330

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


302

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


239

du -sh is a good place to start. The options are (from man du): -s, --summarize display only a total for each argument -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) To check more than one directory and see the total, use du -sch: -c, --total produce a grand total


209

There are lots of options!!! Summary $ echo "$((20.0/7))" $ awk "BEGIN {print (20+5)/2}" $ 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 "...


206

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


199

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


180

sudo touch /bin/rm && sudo chmod +x /bin/rm apt-get download coreutils sudo dpkg --unpack coreutils* And never again. Why didn't you use 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 ...


178

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


170

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 . -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 as well;...


147

You can just use *; there is no need for *.*. File extensions are not special on Unix. * matches zero or more characters—including a dot. So it matches foo.png, because that's zero or more characters (seven, to be exact). Note that * by default doesn't match files beginning with a dot (neither does *.*). This is often what you want. If not, in bash, if you ...


146

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)


143

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


141

For GNU gzip 1.6 or above, FreeBSD and derivatives or recent versions of NetBSD, see don_cristi's answer. With any version, you can use shell redirections as in: 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 ...


134

Typically one uses tar to create an uncompressed archive and either gzip or bzip2 to compress that archive. The corresponding gunzip and bunzip2 commands can be used to uncompress said archive, or you can just use flags on the tar command to perform the uncompression. If you are referring specifically to the Zip file format, you can simply use the zip and ...


115

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


106

If you have GNU coreutils (common in most Linux distributions), you can use du -sh * | sort -h. The -h option tells sort that the input is the human-readable format (number with unit). This feature was added to GNU Core Utilities 7.5 in Aug 2009. Note: If you are using Mac OSX, you need install coreutils with brew install coreutils, then use ...


106

You can use tee and process substitution for this: cat file.txt | tee >(pbcopy) | grep errors This will send all the output of cat file.txt to pbcopy, and you'll only get the result of grep on your console. You can put multiple processes in the tee part: cat file.txt | tee >(pbcopy) >(do_stuff) >(do_more_stuff) | grep errors


103

On *BSD: date -r 1234567890 On Linux (specifically, with GNU coreutils ≥5.3): date -d @1234567890 With older versions of GNU date, you can calculate the relative difference to the UTC epoch: date -d '1970-01-01 UTC + 1234567890 seconds' If you need portability, you're out of luck. The only time you can format with a POSIX shell command (without ...


103

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.


101

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


99

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


98

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


93

more more is an old utility. When the text passed to it is too large to fit on one screen, it pages it. You can scroll down but not up. Some systems hardlink more to less, providing users with a strange hybrid of the two programs that looks like more and quits at the end of the file like more but has some less features such as backwards scrolling. This is ...


92

Using cat Since your file is short, you can use cat. cat filename Using less If you have to view the contents of a longer file, you can use a pager such as less. less filename You can make less behave like cat when invoked on small files and behave normally otherwise by passing it the -F and -X flags. less -FX filename I have an alias for less -FX....


89

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


85

There are many ways to go about this. Method #1 - ps You can use the ps command to find the process ID for this process and then use the PID to kill the process. Example $ ps -eaf | grep [w]get saml 1713 1709 0 Dec10 pts/0 00:00:00 wget ... $ kill 1713 Method #2 - pgrep You can also find the process ID using pgrep. Example $ pgrep wget ...


84

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



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