Used for moving stuff around on a fileserver
This command looks for a single file named emails.txt which is located somewhere in my home directory and cd to that directory. This command is especially helpful when the file is burried deep in the directory structure. I tested it against the bash shells in Xubuntu 8.10 and Mac OS X Leopard 10.5.6
This little function will smarten 'cd'. If you try to cd into a file (which I guess we all have done), it cd's into the directory of that file instead. I had to use nesten if's, to get cd to still work with 'cd' (to get to $HOME), 'cd -' (to get to last directory), and 'cd foo\ bar'. Show Sample Output
Another way of doing it that's a bit clearer. I'm a fan of readable code.
Also resolves symlinks, showing the full path of the link target
Ever use 'locate' to find a common phrase in a filename or directory name? Often you'll get a huge list of matches, many of which are redundant, and typically the results are not sorted. This command will 'locate' your search phrase, then show you a sorted list of just the relevant directories, with no duplications. So, for example, maybe you have installed several versions of the java jre and you want to track down every directory where files matching "java" might exist. Well, a 'locate java' is likely to return a huge list with many repeated directories since many files in one directory could contain the phrase "java". This command will whittle down the results to a minimal list of unique directory names where your search phrase finds a match.
fcd : file change directory A bash function that takes a fully qualified file path and cd's into the directory where it lives. Useful on the commadline when you have a file name in a variable and you'd like to cd to the directory to RCS check it in or look at other files associated with it. Will run on any ksh, bash, likely sh, maybe zsh. Show Sample Output
This is a equivalent to the GNU ' readlink' tool, but it supports following all the links, even in different directories.
An interesting alternative is this one, that gets the path of the destination file
myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link" | sed "s|^\([^/].*\)\$|$(dirname $1)/\1|"); }
Show Sample Output
Searches for all .project files in current folder and below and uses "svn info" to get the last changed revision. The last sed joins every two lines. Show Sample Output
I submitted a command like this without $0 if $BASH_SOURCE is unset. Therefor, it did only work when using ./script, not using 'sh script'. This version handles both, and will set $mydir in a script to the current working directory. It also works on linux, osx and probably bsd.
Should run with sudo
Sometimes you need the full path to your script, regardless of how it was executed (which starting directory) in order to maintain other relative paths in the script.
If you attempt to just use something simple like:
STARTING_DIR="${0%/*}"
you will only get the relative path depending on where you first executed the script from.
You can get the relative path to the script (from your starting point) by using dirname, but you actually have to change directories and print the working directory to get the absolute full path.
Show Sample Output
This let me find some a set of modifications that were made to a rather large tree of files, where the file-names themselves were not unique (actually: insanely redundant and useless. "1.dat 2.dat ..."). Pruning down to last-branch brough things back to the "project-name" scope, and it's then easy to see which branches of the tree have recently changed, or any other similar search. Ideally, it should sort the directories by the mtime of the most recent *file* *inside* the directory, but that's probably outside the scope of a (sane...) command line.
Copy files and dir in parallel. It is Faster.
Using the gnu-parallel.
Has 2 commands:
- First - Create dir structure in /BKP
find Files/ -type d | parallel 'mkdir -p /BKP/{}'
- Second - Copy for structure created
find Files/ -type f | parallel 'rsync -a {} /BKP/$(dirname {})'
- Great for backups!
- Can use "rsync" or "cp".
- Compare with a simple "rsync" or "cp"!
Had trouble with the other function, because of missing semicolons. (According to my bash on OS X)
Set variable 'input' to a set of flac files.
Uses "locate" instead of "find", "sort -u" instead of "sort | uniq" and it's case insensitive. Show Sample Output
work for execute file
I think this is the cleanest way of getting the current working directory of a script. It also works on osx, Linux, and probably bsd as well..
this command is used to locate all pom.xml files, access the dir and do a mvn clean, but I do recommend you to disable network interfaces to not download dependencies packages to be faster. Show Sample Output
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: