This is really fast :)
time find . -name \*.c | xargs wc -l | tail -1 | awk '{print $1}'
204753
real 0m0.191s
user 0m0.068s
sys 0m0.116s
Show Sample Output
if its the current directory, no need find command. just grep will do
The difference between this and the other alternatives here using only grep is that find will, by default, not follow a symlink. In some cases, this is definitely desirable.
Using find also allows you to exclude certain files, eg
find directory/ ! -name "*.tmp" -exec grep -ni phrase {} +
would allow you to exclude any files .tmp files.
Also note that there's no need for calling grep recursively, as find passes each found file to grep.
Recursively replace a string in files with lines matching string. Lines with the string "group name" will have the first > character replaced while other > characters on other lines will be ignored. Show Sample Output
Changed out the for loop for an xargs. It's a tad shorter, and a tad cleaner.
The wherepath function will search all the directories in your PATH and print a unique list of locations in the order they are first found in the PATH. (PATH often has redundant entries.) It will automatically use your 'ls' alias if you have one or you can hardcode your favorite 'ls' options in the function to get a long listing or color output for example. Alternatives: 'whereis' only searches certain fixed locations. 'which -a' searches all the directories in your path but prints duplicates. 'locate' is great but isn't installed everywhere (and it's often too verbose). Show Sample Output
Warning!, if the pattern didn't find anything it shows the total size of dot dir Show Sample Output
This will find all files in the path "." which are older than 10*24hrs (10 days). This will find any type of file.
I created this command to give me a quick overview of how many file types a directory, and all its subdirectories, contains. It works based off file extension, rather than file(1)'s magic output, because it ended up being more accurate and less confusing. Files that don't have an ext (README) are generally not important for me to want to count, but you're free to customize this fit your needs. Show Sample Output
Press > or < to go to the next or previous track. Space to toggle play/pause, etc. It creates a temp file descriptor. To see where the file descriptor gets created type: echo <(echo foo) This works better than running find first, then piping to mplayer with xargs or something, because that won't let you use keyboard shortcuts.
find -exec is evil since it launches a process for each file. You get the total as a bonus. Also, without -n sort will sort by lexical order (that is 9 after 10).
This command shows the size of directories below here, refreshing every 2s. It will also track directories created after running the command (that what the find bit does). Show Sample Output
Please be careful while executing the following command as you don?t want to delete the files by mistake. The best practice is to execute the same command with ls ?l to make sure you know which files will get deleted when you execute the command with rm.
The following command finds all the files not modified in the last 5 days under /protocollo/paflow directory and creates an archive files under /var/dump-protocollo in the format of ddmmyyyy_archive.tar
I use this sometimes when ctags won't help.
Gnu grep allows to restrict the search to files only matching a given pattern. It also allows to exclude files.
You define your variable MYVAR with the desired search pattern: MYVAR= ...which can then be searched with the find command. This is useful if you in a script, where you want the arguments to be fed into the find command. The provided search is case insensitive (-iname) and will find all files and directories with the pattern MYVAR (not exact matches). This may go without saying, but if you want exact matches remove the \* and if you want case sensitive, use the -name argument.
This works fine too.
If you would like to ignore a directory including its subdirectory. For example, a tmp/ directory
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: