Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

nevada

« Newer Snippets
Older Snippets »
Showing 1-7 of 7 total  RSS 

watch -- execute commands over and over again.

* Fast and easy way of setting a reminder for yourself, while working in the command line: ( sleep 10 && echo -e "Tea is ready\a" ) & 10 is a number of secons to wait until fire up the alarm, "-e" argument to echo forces it to see the "\a" sequence, which is an alarm bell.
* execute commands over and over again - run fortune (program) every 20 seconds, run program 'w' every 2 seconds (default), keep track of filename.
 watch -n 20 fortune
watch w
watch ls -l filename

find

* This command finds all the files and removes them. The slash is to escape the semicolon. We don't want the semicolon to be taken as a command seperator. (it's a command delimitor for the parameter -exec).
find -name "*" -exec rm {} \;

* This command finds and removes all files and executes ls.
find -name "*" -exec rm {} \;; ls

* Find only regular files (not directories, sockets, etc).
find -type f -print

* Find patterns 'foo' in all files starting from the current directory(.).
find . -type f -exec grep foo {} \;

* List full pathnames of files in directory dirname.
find dirname

* Finds the file test.txt.
find . | grep test.txt

bash root

* Use su - instead of su, The "-" gives you the target user's environment instead of your own. This is most evident when you forget the dash and the shell can't find commands in /sbin and /usr/sbin.
* Run command as root. su - -c <command>

bash commandline

* set -o vi (bash will respond to vi input).
* Placing a command in `` (left slanted apostrophes) it will simply put the output of that command on the command line. For example, renice -18 `pidof xmms` will give all xmms processes a priority of -18. (and set -o for more options).
* To unalias a alias, alias aliasname=.

diff

diff two directories
diff <dir1> <dir2>

processing columns

print the first column, delimited by space
nawk -Fc '{print $1}' test.txt


print the second column, delimited by :
nawk -F: '{print $2}' test.txt

patching source

Making Patch -- to represent the addition of a new file, diff it against /dev/null.
diff -Naur test.old test.cpp > test.patch

Apply Patch
patch test.cpp test.patch

Undo Patch
patch -R test.cpp test.patch
« Newer Snippets
Older Snippets »
Showing 1-7 of 7 total  RSS