how to set folder path for gtags - emacs

I am new to gtags, and have a question. I have a big project, such as android AOSP, I want gtags to parse some folders, how can I achieve it with gtags? I searched and got solution:
use -f option with gtags, it seems doesn't support folders
Is there any good idea that I can set the folders path and gtags only process those folders?

UPDATE: author of the question came up with a better solution in the comments. I'm adding it here so it's easier to find:
.. create tag file in the sub-directories I need, and add the directories
to GTAGSLIBPATH when loading the project,
My answer:
You can limit what gtags indexes by adding list of files/directories to skip keyword in ~/.globalrc or /etc/gtags.conf. Here's a sample gtags.conf file.
The problem is that often global/gtags packages don't install gtags.conf (at least it's not there in global-5.7.1-2 on ubuntu 12.04), so you'll need to either get it from global source distribution, or use someone else's gtags.conf as a reference. For instance here.
Something like this should work. Note that leading / means from the top of the tree. Without it gtags will skip matching entries anywhere in the tree.:
common:\
:skip=/skip-this-dir/,/lib/and-this/,/include/and-this-one-too/:

The -f option is premised on find(1). Please try the followings.
$ find folder1 folder2 folder3 -type f -print | gtags -f -
or
$ find folder1 folder2 folder3 -type f -print >gtags.files
$ gtags

This is my bash function to get rid of files and paths including 'dummy' and 'win':
function gtagsupdate {
find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" | grep -v dummy | grep -v win | gtags -f -
}

Related

Delete multiple files in CENTOS command

How can i delete all the file that are ending with *0x0.jpg in CENTOS ? I need to delete multiple files nested into folders and subfolders
I assume you have a shell - try
find /mydirectory -type f -print | grep '0x0.jpg$' | xargs -n1 rm -f
There is probable a more elegant solution but that should work
However I would put an echo in before rm on the first run to ensure that the right files are going to be removed.
Ed Heal's answer works just fine but neither the grep nor xargs calls are necessary. The following should work just as well and be a good bit more efficient for large amounts of files.
find /mydirectory -name '*0x0.jpg' -type f -exec rm -rf () \+

Need to find list of scripts that uses a certain file

I have a file named "performance". I need to know which scripts use this file.
I don't believe there is a straight forward way of listing files used by scripts. You will have to run grep in combination of find to check if the script contains the name of the file that you want to check for. Knowing the exact name of the file will help. Using words like performance might end up grepping files that uses that word in comments.
find /path/ \( -name "*.sh" -o -name "*.pl" \) -type f -print0 | xargs -0 grep "performance"
If you're on linux, then you may install and configure auditd to watch for accesses to a particular file.
You can use the -r option to recursively grep through all sub-directories and find text. The syntax is as follows:
grep -r "performance" /dir/

Configuration files management

I have a bunch of configuration files used by gradle.
conf1 conf2 conf3 conf4 etc.
Sometimes I need to change some setting in every file or in several files.
Is there any tool(for Linux) that helps me to do that?
For example, if I want set settings1 in conf2, conf3 and in conf5 I would use something like
"set settings1=value in conf2,conf3,conf5"
You could do it with sed. Needing to change some but not all of a set of similarly-named files in a folder complicates it a bit:
find . -name conf2 -o -name conf3 -o -name conf5 | xargs sed -i 's/settings1=/settings1=value/g'
If you were changing all of the conf files you could just do this:
sed -i 's/settings1=/settings1=value/g' conf*

unix - delete files only from directory

Say with a directory structure such as:
toplev/
file2.txt
file5.txt
midlev/
test.txt
anotherdirec/
other.dat
myfile.txt
furtherdown/
morefiles.txt
otherdirec/
myfile4.txt
file7.txt
How would you delete all files (not directories and not recursively) from the 'anotherdirec'? In this example it would delete 2 files (other.dat, myfile.txt)
I have tried the below command from within the 'midlev' directory but it gives this error (find: bad option -maxdepth find: [-H | -L] path-list predicate-list):
find anotherdirec/ -type f -maxdepth 1
I'm running SunOS 5.10.
rm anotherdirec/*
should work for you.
Rob's answer (rm anotherdirec/*) will probably work, but it is a bit verbose and generates a bunch of error messages. The problem is that you are using a version of find that does not support the -maxdepth option. If you want to avoid the error messages that 'rm anotherdirec/*' gives, you can just do:
for i in anotherdirec/*; do test -f $i && rm $i; done
Note that neither of these solutions will work if any of the files contain spaces or other special characters. You can put double quotes around $i if that is an issue.
Find is sensitive to options order. Try this:
find anotherdirec/ -maxdepth 1 -type f -exec rm {} \;
rm toplev/midlev/anotherdirec/* if you want to delete only files.
rm -rf toplev/midlev/anotherdirec/* if you want to delete files and lower directories

how to prevent "find" from dive deeper than current directory

I have many directory with lots of files inside them.
I've just compressed that directory respectively become filename.tar.gz, someothername.tar.gz, etc.
After compressing, I use this bash to delete everything except file name contains .tar.gz:
find . ! -name '*.tar.gz*' | xargs rm -r
But the problem is find will dive too deep inside the directory. Because the directory has been deleted but find will dive deep in each directory, many messages displayed, such as:
rm: cannot remove `./dirname/index.html': No such file or directory
So how to prevent find from dive deeper than this level (current directory)?
You can use ls instead of find for your problem:
ls | grep -v .tar.gz | xargs rm -rf
You can tell find the max depth to recurse:
find -maxdepth 1 ....