date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,404,865,705,000 |
I am trying to symlink a set of specific files from a project I'm working on.
There is a known string in each of the filenames I wish to symlink.
Here is what I have so far:
ln -s find ~/path/to/src/ -name "*stringtomatch*" find ~/path/to/dest
I have the directory structure setup in the destination to match the sour... |
I created a short script to do this, with a nice output which should be easy check the results. It doesn't need to have the destination directory structure created. Use as follows:
$ ./recursive-symlink.sh --help
Usage:
./recursive-symlink.sh <source_path> <dest_path> <find_args...>
To show its usage, let's say I h... | Recursively "find" file names containing string and symlink files in another directory |
1,404,865,705,000 |
ln -sf source_file target_file succeeds even when source_file does not exist.
ln -f source_file target_file on the other hand fail, as expected.
How can it be tuned to give error on the first case without first testing for the file existence explicitly (i.e. not [[ -e source_file ]] && ln -sf source_file target_file)
|
From the ln man page:
When creating hard links, each TARGET must exist.
No mention of symlinks there; in fact, this statement seems to imply that this is not the case for symlinks.
As I said in my comment on your question, when creating a symlink to a non-existent source, a broken link is created:
$ ln -sfv blah bla... | Why does ln -sf silently fail? |
1,404,865,705,000 |
I use Vim 8.2 to edit my files in my Ubuntu 18.04. When I open a file, do some changes and quit with Vim, the inode number of this file will be changed.
As my understanding, it's because the backup mechanism of my Vim is enabled, so each edition will create a new file (.swp file) to replace the old one. A new file has... |
It seems the setting backupcopy is auto (run :set backupcopy? in Vim to confirm).
The main values are:
yes make a copy of the file and overwrite the original one
no rename the file and write a new one
auto one of the previous, what works best
[…]
The auto value is the middle way: When Vim sees that renaming file ... | Why didn't inode change anymore with a hard link |
1,404,865,705,000 |
I have an "install.sh" that installs my personal scripts:
find /home/Steven -name '*.sh' -exec ln -s -t /usr/local/bin {} +
I would like to make an "uninstall.sh" that removes the symbolic links created
by "install.sh". I wrote this:
for z in /usr/local/bin/*
do
if [ -h "$z" ]
then rm "$z"
fi
done
but it remov... |
If you have GNU or BSD find, this should do it:
find -lname '/home/Steven/*' -delete
| Remove symlinks originating from specific directory |
1,641,895,127,000 |
I want to create a relative symlink pointing to a relative symlink, not to the relative symlink's target. It seems that when creating a relative symlink ln resolves TARGET instead of pointing to the actual TARGET. Can this process be skipped? In the example below, I would want rsym-to-existing-rsym.txt to point to rsy... |
A plain ln -s treats its target as a string. It doesn't care whether that string happens to be a path to an existing file.
The GNU extension ln -sr treats its target as a filesystem location. It needs to dereference directories in the target, because otherwise the resulting actual target would be wrong:
mkdir /tmp/dem... | ln: create relative symlink to a relative symlink |
1,641,895,127,000 |
So there was a file dummy1. I created a symlink:
ln -snf dummy dummy1
and confused source and target file, as I actually wanted dummy to point to dummy1 not vice versa.
So now dummy1 is a symlink.
Is the original dummy1 file removed by doing this? Any way to get it back?
I would expect to get it back somehow, because... |
I hope you have a backup of dummy1! From the man page for ln:
-f, --force
remove existing destination files
So dummy1 has been removed and replaced by the symlink.
If you want to prevent this in the future, do not use the -f flag to ln.
| Is existing file removed when a symlink is created with the same name? |
1,641,895,127,000 |
How does the relative paths work in ln (-s or not)? For example if I type ln -s foo bar/banana.txt what does this mean? What is foo relative to? Because it doesn't seem to be relative to the current path. Also is it different if I remove -s or not? I've tested it out and the result doesn't make sense to me, and the ma... |
It's different with and without -s.
With -s in:
ln -s path/to/file some/dir/link
path/to/file is set as the symlink target of some/dir/link (or some/dir/link/file if link was a directory).
A symlink is a special type of file which /contains/ a path (can be any array of non-0 bytes, some systems even allow an empty st... | Paths in ln with hard links and soft links |
1,641,895,127,000 |
I am trying to use fortran code called SAMMY-8 which has its binary ready for use.
I was using without any issue while I had f25 installed. When upgrading to f27 I got the following error when trying to run the software
sammy: error while loading shared libraries: libgfortran.so.3: cannot open shared object file: No ... |
libgfortran.so.3 from Fedora 9 : provides.log →
libgfortran.so.3(GFORTRAN_1.0)(64bit)
libgfortran = 4.3.0-8
The original package libgfortran-4.3.0-8.x86_64.rpm will conflict, if any fortran dependent applications are installed (e.g. 'openblas-thread'), so a rebuild to a new name is required.
compat-libgfortran-4.... | Use libgfrotran.so.3 and GFORTRAN_1.0 on fedora 27 |
1,641,895,127,000 |
I moved my filesystem and symlinks from Ubuntu 14.04 to 16.04 by using FAT32 memory card, which apparently broke those links; stopped using BitTorrentSync. Differential condition is that those links are remnants of my OSX installation because of XSym. I do ls -la $HOME | grep Math for a symlink
-rw-r--r-- 1 masi mas... |
Two possible solutions that spring to mind.
1. Iterate across all the directories in LOREM and symlink them to $HOME
cd "$HOME/LOREM"
for item in *
do
test -d "$item" || continue
mv -f "$HOME/$item" "$HOME/$item.DELETE_ME_LATER" 2>/dev/null
ln -s "$HOME/LOREM/$item" "$HOME/$item"
done
# Once you are happy... | How to Relink these symlinks after moving the system? |
1,641,895,127,000 |
I've checked the manpages, the mount, the permissions ...
(edit: combined history into one sequence as requested. Starting to seem a not-simple problem. Nothing new since last edit, just bundled up all pretty)
~/sandbox/6$ editfunc doit
~/sandbox/6$ -x doit
+ doit
+ find
.
+ cp /bin/ln /bin/id .
+ sudo chown jthill:j... |
Found it:
If sysctl fs/protected_hardlinks is set,
hard links by someone not the owner (and without CAP_FOWNER), must be:
not special
not setuid
not executable setgid
both readable and writable
according to fs/namei.c. Some guy on SO wanted to have a dropbox folder people could add to but not see into (I think t... | setgid binary doesn't have permission, mount's right, I'm missing something, but what, please? |
1,641,895,127,000 |
I was making a Bash script with the setuid permission on, but it didn't work. So I found my solution here:
Why does setuid not work? and
Allow setuid on shell scripts
Now my script works fine and all (I rewrote it in cpp).
To satisfy my curiosity as to why pure Bash shell didn't work, I read this link: http://www.fa... |
The code ln /etc/setuid_script -i is intended to create a hardlink to a file called -i in the current directory. You might need to say ln -- /etc/setuid_script -i to make this work if you are using GNU tools.
The shell can get commands to run in 3 different ways.
From a string. Use sh -c "mkdir /tmp/me" with the -c f... | What does `ln /path/to/file -i` do in a setuid'ed script? |
1,641,895,127,000 |
What does ln -T do? I know the flag does not exist in the BSD version of ln, and it only exists in the GNU version, and I have read the documentation that it will make ln "treat LINK_NAME as a normal file always", but what does that mean and why does the BSD version not have it?
|
The -T (--no-target-directory) option to GNU ln provides a safety feature that may be useful in scripts.
Suppose that you want to create a new name, $newname, for a file $filename, where the new name is maybe provided from external sources.
The command
ln -T "$filename" "$newname"
would then fail if $newname was an a... | What does "ln -t" do [duplicate] |
1,641,895,127,000 |
I have found that when creating a symbolic link to a folder it is produced with or without the trailing slash based on your input. for example:
$ ln -sfv /ln-test/FOLDER/ test-tail
test-tail -> /ln-test/FOLDER/
$ ln -sfv /ln-test/FOLDER test-notail
test-notail -> /ln-test/FOLDER
$ ll /ln-test
total 16
drwxr-xr-x 2 ... |
Accessing a file through a symbolic link is equivalent to replacing the file's base name by the symlink text if the symlink text doesn't start with / (relative link), and to replacing the file's full path by the symlink text if the symlink starts with / (absolute link). If there's a trailing slash in the symlink text,... | Why can a softlink to a directory be created with or without the trailing slash? |
1,641,895,127,000 |
I am trying to write a shell script to create link for file from my dotfiles repo to my home folder.
I want to use hard link if possible because it cannot be broken when moving it to somewhere in the same filesystem with HOME.
But if I clone the dotfiles to another filesystem, I have to use symlink instead.
So, how ... |
ln source target 2>/dev/null || ln -s source target 2>/dev/null || exit 1
or, slightly more "interactively" (chattier),
if ! ln source target 2>/dev/null; then
echo 'failed to create hard link, trying symbolic link instead' >&2
if ! ln -s source target 2>/dev/null; then
echo 'that failed too, bailing ... | Create hard link if possible, else use symlink |
1,641,895,127,000 |
Target situation:
data/file.txt owned by myUser:myUser and "-rw-rw-rw-" (chmod 666)
symbolic link /tmp/file.txt owned by postgres:postgres and "-rw-rw-rw-"
So, I can edit the file with my user, and the other user (postgres) can read and write it also, but the link and the file are owned by different users.
Real wor... |
The directories /home and /tmp aren't really appropriate for this, and neither is using a symbolic link. Make a directory to store the file and set up permissions for it using an ACL. Let's say that your username is peter. Some of the commands below might be superfluous, and these are given merely to be explicit.
# Ma... | Best workaround for file's symbolic link with different group than file |
1,641,895,127,000 |
I have a script that creates a temp directory using mktemp -d.
A folder generated in the temp directory is the output of the script that will be copied to another part of the machine.
I was considering using ln to use the same folder instead copying the contents somewhere else. I was wondering if it would still... |
It depends on where your temporary directory is. That is, have you created your own temporary directory, or are you using the system's (/tmp)?
In your scenario, you are expecting the files/folder to remain after the temporary directory has been cleaned up.
If it's in the system's /tmp directory then it may well be cle... | Do Links to /tmp files get deleted? |
1,641,895,127,000 |
I'm trying to get the following working:
alias banana='emacs /usr/local/nagios/etc/objects/'
So i want to just type "banana firewall.cfg" to edit this file(/usr/local/nagios/etc/objects/firewall.cfg).
If i type that, emacs opens two buffers, one for "/usr/local/nagios/etc/objects" in directory edit mode, and the othe... |
Aliases are good for giving another name to a command, or for passing default arguments. They are not good beyond that, for example to modify an argument. Use a function instead.
To support multiple file names easily, change to the target directory first. Use parentheses instead of braces to create a subshell so that ... | alias for 'emacs /usr/local/nagios/etc/objects' |
1,641,895,127,000 |
I have a number of files in /etc/rc3.d/ directory which all are symbolic links and point to files in /etc/init.d/ directory using ../init.d/ designation. For example file S18rsyslog in /etc/rc3.d/ directory is a symbolic link to file /etc/init.d/rsyslog, but according to ls -l, /etc/rc3.d/S18rsyslog does not point to ... |
What is the advantage to keep symbolic links relative to directory? Because this allows one to move the direcoty itself without breaking the symbolic links?
Exactly.
In addition, is it possible to create a symbolic link with .. (parent directory) in the path without being in the directory? ln -sv '/etc/init.d/rsysl... | understand the designation of symbolic links |
1,641,895,127,000 |
On openSUSE Tumbleweed 20210606 with kernel GNU/Linux 5.12.9-1-default
I tried making a hard link of file from /cust to ~/backup:
df /cust && df ~/backup && ln -P /cust/customization.tar ~/backup/
and get a result with error message:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 70652313... |
ln without options creates a hard link as documented in the manual page for link, especially the section explaining error EXDEV, which contains the remark
link() does not work across different mount points, even if the same
filesystem is mounted on both
Although I realize that the paragraph below does not address th... | about ln command : condition of cross-device |
1,641,895,127,000 |
I have an issue with creating symbolic links with ln, with the relative and the force flag set.
The scenario is as follows:
$ tree
.
├── folder1
│ └── file
└── folder2
I create the link:
$ ln -sfr folder1/file folder2
$ tree
.
├── folder1
│ └── file
└── folder2
└── file -> ../folder1/file
This is as I want i... |
This is a bug and appears in the coreutils from version 8.16 to 8.21. It was fixed in 8.22. From the release notes of version 8.22:
ln --relative now updates existing symlinks correctly. Previously it based
the relative link on the dereferenced path of an existing link.
[This bug was introduced when --relative... | Inconsistent behaviour creating symbolic links with relative and force flag |
1,641,895,127,000 |
I'm using Puppet and I need to create symlinks between two folders.
I have around 10 folders with the same structure and I always want to execute my link command in xx/yy/zz.
Something like this:
ln -s aa/bb/folder_to_link folders_1_to_x/yy/link_name
I tried following these directions but had no success.
Is there a... |
The proper solution to something like this in puppet is to create a defined type:
define folder_link (
$link_map = $name,
) {
$link_map_split = split($link_map, ':')
$origin = $link_map_split[0]
$link_name = $link_map_split[1]
$link_path = "/folders_1_to_x/yy/$link_name"
file { $link_path:
ensure => link,
t... | How do I execute a command in each subdirectory? [duplicate] |
1,641,895,127,000 |
From the manual of coreutils, for ln
When creating a relative symlink in a different location than the
current directory, the resolution of the symlink will be different
than the resolution of the same string from the current directory.
Therefore, many users prefer to first change directories to the
location ... |
There are two things to remember:
ln -s (without -r) stores the target name literally as you pass it to it
if you pass a relative target, it resolves relatively to the link name, not your current working directory
Example:
I'm in /home/user/d0 and I want a link to /home/user/file so I do:
ln -s ../file .
../file is... | Why change the current directory to the parent directory of a relative symlink before creating it |
1,641,895,127,000 |
As we all know, the ln command creates a link, with the default being a hard link and the -s option creating a symlink. The general syntax is ln [-s] OLD NEW, where OLD is the file you are linking to and NEW is the new file you are creating. Hard links can not be created for directories, as a hard link could be create... |
Read your man page: Question 1 = 1st Form, this is because in linux all items are considered files, even directories. As an example, use your text editor to "open" /etc/, ie: nano -w /etc/ nano will politely tell you /etc/ is a directory Since it's technically legal to create never ending symlinks. In the old days... | Seemingly Inconsistent Behavior for "ln" & "ln -s" |
1,641,895,127,000 |
So, as mentioned here, 'ln -s /directory 'D:' maps the windows D: location to a Linux style directory.
However, as far as I know, this goes against the Linux naming system. Why does Linux allow the use of Windows style directory starters in the ln command?
|
This works because D: is a valid directory name in Linux (and POSIX in general). It has no significance as far as Linux is concerned.
(Some programs will treat certain directories named like this in a special way, in the appropriate directory; for example, Wine expects directories like this in the dosdevices directory... | Why Does `'ln -s /directory 'D:'` Work Like It Does? |
1,641,895,127,000 |
I'm new to bash scripting and wanted to make a script that will get user input and hard link all the files of a directory to another one. So far I have this:
read -p "What directory do you want to link? " dir
items=$(ls -m $dir -Q | tr -d '\n'' ')
read -p "Where do you want to link the files? " outdir
echo "Linkin... |
For a short utility script like this, I would suggest not making it interactive. The user likely already knows exactly what directory they want to make a copy of in the manner that you describe, and allowing the user to make use of tab-completion and/or filename globbing on the command line makes it more likely that ... | Need help with a script to link files in a directory |
1,641,895,127,000 |
I would like to replace a directory with a symlink. For the directory itself I have full permissions (rwx), but for the parent directory I don't have write permissions (r-x).
Is this possible? The man page for ln states that -f removes existing destination files, which sounds like it would first would delete the direc... |
If you don't have write permission in the parent directory, you can't make any changes in the parent directory; this includes deleting the target directory, and creating a symlink.
In any case, ln won't overwrite a directory, even with -f.
| Can I replace a directory with a symlink without write permissions in parent? |
1,641,895,127,000 |
I'm trying to create a script to swap the location of a symbolic link in the current directory and the target file in another (relative) directory. Unfortunately, I can't figure out how to make the link in the non-local directory and searches for info on 'ln -s' only retrieve simple case uses. I realize I could 'cd'... |
Assuming you're using GNU tools, you could determine the absolute paths to link and target and use ln -r or use realpath's --relative-to option to create relative link targets.
Here's a minimal example without sanity checks or cleanup of the link backup:
#!/bin/bash
link=$(realpath -s "$1") # absolute path to link
t... | Help with script swapping target and symbolic links |
1,641,895,127,000 |
I'm working in a team, which develops a c++ (ROS) project.
For some reason, we haven't a good git management.
We have several git branches. To compile the project, I have to git clone the codes from each branch and rearrange the structure of directories.
First, I mkdir -p /home/me/repo, then I git clone the codes from... |
Accessing .. doesn't really work as you expect when symlinks are involved...
And when you try that in bash, bash tries to be "helpful" and fixes it for you, so the problem does not become aparent.
But, in short, when you go to /home/me/project2/src/hdmap/../third_party, the kernel will first resolve the symlink of "hd... | Why can't a project compile with symbol link |
1,641,895,127,000 |
I am in the parent directory and there are a number of files with .fastq, .fq, .fastq.gz and .fq.gz extensions in different subdirectories. I created a subdirectory named FASTQC and want to create symlinks to all of them in that subdirectory.
When I try:
find "$PWD" \( ! -path "$PWD/FASTQC" -type f -name *.f*q -o -nam... |
( ! -path "..." -type f -name ... -o -name ...gz ) -exec ...
is parsed as
( ( ! -path "..." -type f -name ... ) -o ( -name ...gz ) ) -exec ...
because (the implied) and binds stronger than or. You probably want
! -path "..." -type f ( -name ... -o -name ...gz ) -exec
to have the ! -path (and -type) filter apply t... | ln -s reports that a procedure failed, but creates symlinks nonetheless |
1,641,895,127,000 |
Background
The PNG image files I want to use is stored in directories according to date, for example:
/NAS-mein/data/201812/
PNG stored within it like /NAS-mein/data/201812/foo/bar/20181231_1500.png
So I created a symbolic link PNG_path in my home directory
ln -s /NAS-mein/data/201812/ PNG_path
and I'm able to upda... |
The percent sign is special in crontab and needs to be escaped if you put your date command there (see man 5 crontab).
Your symbolic link points to a directory. When you run ln again, it will put the link inside that directory.
Example:
$ mkdir real
$ ln -sf real link
$ tree
.
|-- link -> real
`-- real
1 directory, ... | How to regularly update symbolic link (ln -sf) via crontab |
1,641,895,127,000 |
I want to target all files called fooxxxbarxxx. The common thing among all those files is that it contains foo and bar.
I've tried to use *foo*bar* and *foo**bar* but it doesn't work.
Specifically, I'm trying to create soft links to those files, and the rest of the code already works for more straightforward executi... |
In bash shell you need to use extglob option for this OR type shell expansions.
shopt -s extglob nullglob
and then do the globbing as
ln -s /path/**/@(*foo*bar*|*bar*foo*)
| How can I stack wildcards to target specific files? |
1,357,233,237,000 |
In Linux and Unix systems there are two common search commands: locate and find.
What are the pros and cons of each? When one have benefits over the other?
|
locate(1) has only one big advantage over find(1): speed.
find(1), though, has many advantages over locate(1):
find(1) is primordial, going back to the very first version of AT&T Unix. You will even find it in cut-down embedded Linuxes via Busybox. It is all but universal.
locate(1) is much younger than find(1). Th... | locate vs find: usage, pros and cons of each other |
1,357,233,237,000 |
How can I update the cache / index of locate? I installed new packages and the files are clearly not yet indexed.
So which command do I have to commit, in order for the indexer to trigger?
I'm currently working on debian jessie (testing):
with Linux mbpc 3.13-1-amd64 #1 SMP Debian 3.13.7-1 (2014-03-25) x86_64 GNU/Linu... |
The command is:
sudo updatedb
See man updatedb for more details.
| How to update Linux "locate" cache |
1,357,233,237,000 |
I wanted to install the command locate, which is available via sudo apt-get installmlocate.
However, I first ran sudo apt-get installlocate which seems to have installed something else.
Typing the command locate <package> however seems to call upon mlocate.
What is the package locate, and can (should) it be safely re... |
The locate package is the implementation of locate from GNU findutils. The mlocate package is another implementation of the same concept called mlocate. They implement the same basic functionality: quick lookup of file names based on an index that's (typically) rebuilt every night. They differ in some of their functio... | Difference between locate and mlocate |
1,357,233,237,000 |
On a new Ubuntu 10.4 instance, I tried to use the locate command only to receive the error
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
from using this command on other systems I'm guessing that this means the database has not yet been built (it is a fresh install). I believe it is... |
The cron job is defined in /etc/cron.daily/mlocate.
To run it immediately:
sudo updatedb
or better
sudo ionice -c3 updatedb
This is better because updatedb is set in the Idle I/O scheduling class, so that it do not disturb (from the I/O point of view) other applications. From ionice man page:
-c class
T... | How do I enable locate and queue the database to be built? |
1,357,233,237,000 |
The locate program of findutils scans one or more databases of filenames and displays any matches. This can be used as a very fast find command if the file was present during the last file name database update.
There are many kinds of databases nowadays,
relational databases (with query language e.g. SQL),
NoSQL d... |
Implementations of locate/updatedb typically use specific databases tailored to their requirements, rather than a generic database engine. You’ll find those specific databases documented by each implementation; for example:
GNU findutils’ is documented in locatedb(5), and is pretty much just a list of files (with a s... | What kind of database do `updatedb` and `locate` use? |
1,357,233,237,000 |
I go to use the updatedb command to update the index and I get
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'
fyi The locate command is working, e.g.
$ locate Index.xml
/usr/share/mysql/charsets/Index.xml
durrantm.../durrantm$
How can I overcome this issue when trying to run updatedb?
|
You have to run the updatedb command as the super user. For example,
sudo updatedb
| updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db' |
1,357,233,237,000 |
I often use "locate" command on CentOs to find files.
What's the alternative for this command on Debian ?
|
I recommend locate.
sudo apt-get install locate
| Alternative for "locate" on debian |
1,357,233,237,000 |
This finds a large number of files that are under various subdirectories of "Dropnot"
$ locate Dropnot
Can I find just the directory location with locate? (which directory "Dropnot" is in)
So if Dropnot is in /home/me/, that's the only entry that gets returned.
If so, what's the simplest / shortest way ?
Preferably... |
There is no option to use locate to find selected type of file (like directory), but you can use syntax from your question - Dropnot$ to find lines that ends with Dropnot. For that you must use -e option to locate to turn on POSIX regular expression.
In this case you should use:
locate -e Dropnot$
It is important wh... | How can I use locate only for a directory |
1,357,233,237,000 |
I'd like to find where a file (with a partially-known filename) is in the file system. I'd like to know how to do this from the command line, rather than using a GUI utility.
In Windows, I'd run the following:
cd /d C:\
dir *filename* /s
What's the Linux equivalent?
|
locate filename
find -name '*filename*'
echo **/*filename*
ls -ld **/*filename*
(Read on for the main terms and conditions. Read the manual for the fine print.)
Listing the contents of a directory is kind of a secondary feature of ls. The main job of ls, the one that takes up most of its complexity, is fine-tuning it... | How to find a file in the filesystem from the command line? |
1,357,233,237,000 |
How is updatedb so much faster than find?
Here's a timed comparison between updatedb and a find command that does a seemingly similar task.
compare.sh
#!/usr/bin/env bash
cmd="sudo updatedb"
echo $cmd
time eval $cmd
cmd="sudo find / \
-fstype ext4 \
-not \( \
-path '/afs/*' -o \
-path '/net/*... |
See the man page for updatedb, "If the database already exists, its data is reused to avoid rereading directories that have not changed".
Whereas the find command traverses all directories regardless of whether they have changed.
| How is updatedb so much faster than find? |
1,357,233,237,000 |
I keep my digital music and digital photos in directories in a Windows partition, mounted at /media/win_c on my dual-boot box.
I'd like to include those directories—but only those directories—in the locate database.
However, as far as I can make out, updatedb.conf only offers options to exclude directories, not add t... |
There's no option for that in updatedb.conf. You'll have to arrange to pass options to updatedb manually.
With updatedb from GNU findutils, pass --localpaths.
updatedb --localpaths '/ /media/win_c/somewhere/Music /media/win_c/somewhere/Photos'
With updatedb from mlocate, there doesn't appear a way to specify multiple... | How to add specific directories to "updatedb" (locate) search path? |
1,357,233,237,000 |
I am trying to perform this:
locate pg_type.h | cat
But this command simply does nothing different than locate pg_type.h
What should I change ? I want to perform cat pg_type.h wherever pg_type.h may be.
|
locate -e0 '*/pg_type.h' | xargs -r0 cat
locate pg_type.h would find all the files with pg_type.h in their path (so for instance if there was a rpg_type.horn directory, you'd end up displaying all the files in there).
Without -0 the output of locate can't be post-processed because the files are separated by newline c... | Why does pipe not work with cat and locate? |
1,357,233,237,000 |
Suppose that I have a file named filename123.txt and it is the single file that is named so, and I can locate it with the command locate filename123. And it returns only this file.
Now I want to open it with vi/vim. But I don't want to go to that location and type the vi command followed by filename. Here I want the r... |
You can use xargs:
locate filename123 | xargs vi
By default xargs will execute as few instances of the specified command as possible, passing as many parameters as possible according to the system's ARG_MAX. To limit the number of parameters passed to an instance of vi, use xargs' -n option.
To handle file names cont... | How to `locate` multiple files and open them in vim? |
1,357,233,237,000 |
locate gtags would find all the files named gtags.
What if I only need executables, is there any way to do this?
|
Not easily. You can use
locate bash | while IFS= read -r line; do [[ -x "$line" ]] && echo $line; done
to find all executables where the name contains bash. This is faster than using find across the whole filesystem because only a few files need to be checked.
locate bash does what it always does (lists all matche... | How find only executable files using 'locate'? |
1,357,233,237,000 |
Is it possible to get a reliable progress bar (or just a reliable information how long it will take) when doing updatedb?
|
No, there's no such option, as well it shouldn't have any.
If you need to measure that, you must first know how many files are present on your system, that means loop through everything twice, it can be slow
One evicent example is that if you extract kernel source code with file-roller, it's slower than doing the same... | Progress bar in updatedb |
1,357,233,237,000 |
I wonder how to use the command locate to search for words that are not case sensitive? Such as modify locate normal to search for results that have "Normal" and "normal".
|
That depends on the locate you use. There are a couple of implementations, with identical executable names, but various package names: locate, slocate, mlocate, rlocate.
Usually they all have -i and/or --ignore-case switch. Consult your locate's man page for the exact syntax.
Also usually they have no configuration fi... | 'locate' for case-insensitive words? |
1,357,233,237,000 |
I would like to exclude some Windows folders on an NTFS mount from being indexed by locate. I'm familiar with the PRUNEPATHS syntax in /etc/updatedb.conf. It is a white-space separated list of directory names.
My problem is that I want to exclude directories that contain white space themselves (e.g. Program Files (x8... |
In updatedb.sh line 175 gives a hint:
PRUNEREGEX=`echo $PRUNEPATHS|sed -e 's,^,\\\(^,' -e 's, ,$\\\)\\\|\\\(^,g' -e 's,$,$\\\),'`
There the $PRUNEPATHS is handled like plain text, the ' ' characters are replaced and no escaping is possible.
To ensure the space survives that line 175, you must denote it without expl... | How to exclude directories with blanks via locate's PRUNEPATHS? |
1,357,233,237,000 |
If I understand correctly, the database locate relies on is just for files on partitions of internal HDDs. I wonder if it is possible to use locate on external HDDs?
|
The locate database is generally configured to omit files on removable disks, since they can't be assumed to be there later. It can be configured through a file such as /etc/updatedb.conf (the location depends on which of the several locate programs you use and how it is configured by your distribution).
For a removab... | Make `locate` able to search files on external HDD |
1,357,233,237,000 |
Is it possible to locate a path in the file system like what can be done for file names? For example I want to find all paths in system that include 'foo/bar', which may have the following result:
/home/myname/test/foo/bar/hello
/var/www/site/foo/bar
|
If you are unable to find the file with the below command then try updatedb for updating db used by locate command.
locate -r foot/bar/
or
# locate "/*/bar/avi"
/foot/bar/avi
find command can also do this
find / -path */foot/bar*
find / will search the whole system starting from /
| How to locate a path? |
1,357,233,237,000 |
I am trying to rename files that include the character "à".
I do the following :
rename -v 's/à/a/g' *
But it shows all the files as unchanged. Verbose mode shows the same thing.
I tried to escape with \ but with no luck.
How can I make the regex match this type of character ?
EDIT
The output of perl -V :
Summary of ... |
On macOS and with the HFS+ file system at least, accented characters are encoded in their decomposed form so à is encoded as a\u300 (a followed by the combining grave accent combining character) even if you created the file with touch $'\ue0' (the pre-composed form (stand-alone a with grave accent), causing all sorts ... | How to rename filenames with accents on macOS? |
1,357,233,237,000 |
I usually find the answers to all my Unix related problems already posted as questions and answers. However, this particular issue has had me stumped for the past hour so I thought I’d ask my first question on this site.
Problem
I have a development / staging server server running CentOS 5.11.
Running locate as a regu... |
The problem was the permissions for / (the root directory) and the clue for finding that was this line from your strace output:
access("/", R_OK|X_OK) = -1 EACCES (Permission denied)
You were missing group read permission settings for /. But because you still had x (execute) permission, which allows ... | No output from locate command |
1,357,233,237,000 |
When searching for files, I often prefer using locate (because of the speed).
However, I end up opening a terminal just for that purpose and then closing it again. Not a big problem for me, but my girlfriend often forgets command names.
Is there a way to have Nautilus to use mlocate for searching?
Ideally, I'd love to... |
I've not seen a way to incorporate these results into Nautilus, but there are GUIs for search in mlocate's database. The one that I'm most familiar with is called catfish. It's generally in most of the standard distros' repos. The main website is here, titled: Catfish is a versatile file searching tool.. The project's... | Is there a way to have Nautilus include mlocate in the results? |
1,357,233,237,000 |
I'm trying to find where check_dns is defined in nagios' commands.cfg file, although there are quite a few files.
I know I could run something like find / -name "command.cfg" -exec grep check_dns {} \; to search for matches, but if possible I would like to use locate since it is an indexed copy and much faster.
When I... |
Yes, you can use xargs for this.
For example a simple:
$ locate commands.cfg | xargs grep check_dns
(When grep sees multiple files it searches in each one and enables filename printing along matches.)
Or you can explicitly enable filename printing via:
$ locate commands.cfg | xargs grep -H check_dns
(Just in case on... | How can I act on the results of the "locate" command? |
1,357,233,237,000 |
To use locate command with regex , do we need to enclose the pattern in quotes along with passing --regex option ? If yes, then what do the following mean -
a) locate --regex file* ? Here regex will happen or shell globbing ?
b) locate 'file*' ? Will locate do regex search even though we did not passed --regex ?
c) lo... |
You type the command at the shell prompt. The shell processes what you typed, which includes globbing, substituting variables, substituting $() and so on. After processing what you typed, the shell executes the command.
Quotes are needed if a string contains characters that are special to the shell, such as spaces or ... | Understanding locate command regex |
1,357,233,237,000 |
I am a heavy user of the locate tool, which is part of the findutils package. It's fine to use it on command line, but sometimes I would also like to search for a file (as fast as with locate) within my Xfce 4.10 desktop.
Is there any nice GTK frontend (or a panel applet) for the locate command?
|
The one that I'm most familiar with is called catfish. It's generally in most of the standard distros' repos. The main website is here, titled: Catfish is a versatile file searching tool.. The project's Launchpad site is another additional resource if needed.
excerpt from website
Catfish is a search GUI powered by lo... | GTK Frontend for locate |
1,357,233,237,000 |
I have to search for a specific file type on a storage unit and also want to know their owners.
With locate '*.txt' >> result.txt I find all files I'm looking for but I'm missing the owner this way.
Any suggestions on how I could do it properly?
|
locate -0 '*.txt' | xargs -r0 stat -c "%n %U" >>result.txt
should do the trick
| Locating files and displaying their owner |
1,357,233,237,000 |
I'm working with XML files, each of which could be dozens of lines long. There are literally hundreds of these files, all over a directory structure. Yes, it is Magento.
I need to find the file that has the <foo><bar><boom><bang> element. A <boom><bang> tag could be defined under other tags, so I need to search for th... |
You could try xmlstarlet to select if the path exists then output the filename:
find . -name '*.xml' -exec xmlstarlet sel -t -i '/foo/bar/boom/bang' -f -n {} +
| Find XML file with specific path |
1,357,233,237,000 |
In FreeBSD 12, on a freshly-created virtual machine (DigitalOcean), I tried to use the locate command.
$ locate java
I received an error.
locate: database too small: /var/db/locate.database
Run /usr/libexec/locate.updatedb
So I ran locate.updatedb.
$ /usr/libexec/locate.updatedb
Got a message, complaining about p... |
locate is an easy way to search for a file quickly since it has it's own database. However, I always just use find(1). The results are returned to the user who ran it, and the user who ran it can only find files they have the appropriate file system permissions to.
find searches recursively, so you can specify / as th... | Safe secure way to locate a file in FreeBSD? |
1,357,233,237,000 |
I'm on Ubuntu 11.04, where I have:
$ locate --version
mlocate 0.23.1 [...]
The man locate page says:
If --regex is not specified, PATTERNs can contain globbing characters. If any PATTERN
contains no globbing characters, locate behaves as if the pattern were *PATTERN*.
OK, so to do a little test: first, just ... |
Your glob will only match if the name starts with lua. Try this glob:
locate '*lua*so*'
| Getting globbing to work with `locate`? |
1,357,233,237,000 |
I need to compile a package but the ./configure command does not work?
I'm getting the following error:
-bash ./configure : No such file or directory
Where is that script?
I used the locate command but it did not return anything.
|
locate will not work unless you have an up-to-date database.
Try find . -type f -name configure instead, or issue an updatedb command first, then do the locate (make sure the current path isn't excluded)
But first, you should always check the documentation - maybe the way to compile it does not use the configure mecha... | "./configure" command does not work |
1,357,233,237,000 |
I want to search for arbitrary file/directory names, but only want to list file paths containing the search string at the same position once.
Especially not every file within a directory matching the search string.
Here is an example, locate -i flatpak lists:
/etc/flatpak
/etc/dbus-1/system.d/org.freedesktop.Flatpak.S... |
Sounds like you want to search for flatpak in the file name only (and not in other path components), so you can use the -b/--basename option:
So:
locate -ib flatpak
Another approach could be to use the -r/--regex option and write:
locate -ir 'flapak[^/]*$'
That is flatpak followed by any number of characters other t... | Search for arbitrary files but only list matches in results once |
1,357,233,237,000 |
I am trying to locate all the files named hosts on a linux PC remotely. The problem is there are almost several thousand files with ghostscript as one of the upper directory names or as part of a directory name, so it's returning ALL of those directories. Is there a way to locate hosts, but exclude ghosts?
|
You could pipe the output into a grep -v command to exclude ghostscript
| grep -v "ghostscript"
| Locate but exclude names - Linux |
1,357,233,237,000 |
I want to locate all folders on my server that end with 'wordpress-seo'.
I tried find command but it takes too long.
sudo find /home/w/s -type d -name 'wordpress-seo'
Now I am trying locate command but it returns all paths that have wordpress-seo.
a/wp-content/plugins/wordpress-seo
a/wp-content/plugins/wordpress-seo... |
Try this:
locate -r "wordpress-seo$"
Although i should mention that find offers huge variations of options over locate. You have found locate faster because it just reads from a database /var/lib/mlocate/mlocate.db while find search through files every time, whenever you give it something to search.
locate's databas... | Locate specific folders |
1,357,233,237,000 |
I had a look at man locate but couldn't find an answer to this.
The updatedb command appears to index everything under /, but according to my experiment it didn't index a file at /media/mike/W10 D drive/nonsense_file.
Am I to suppose that it excludes mounted media volumes/locations? Is this documented somewhere? Is t... |
The configuration is in the file /etc/updatedb.conf. It may look like this:
# /etc/updatedb.conf: config file for mlocate
# This file sets variables that are used by updatedb.
# For more info, see the updatedb.conf(5) manpage.
# Filesystems that are pruned from updatedb database
PRUNEFS="9p afs anon_inodefs auto au... | Which parts of a Linux system does locate index or not index? [duplicate] |
1,357,233,237,000 |
Is there anyway to display the size of each file next to it after executing the "locate" command?
|
If your locate implementation understands the option -0:
locate -0 PATTERN | xargs -0 ls -sd
Otherwise:
locate PATTERN | xargs -I {} ls -sd
Of course you may want to vary the flags passed to ls, e.g. add -h to get “human-readable” sizes, add --color=auto to have special files in color, etc.
If some of the files in t... | How to display size of each file next to it after executing the "locate" command? |
1,357,233,237,000 |
I need to locate a library on my system and it's name is expected to be found a couple of times. I want to keep only the first occurrence.
So far I've tried some methods for splitting strings by newlines but neither seem to work with locate's output.
I'm not using find because I don't know where the lib may be in adv... |
There are several ways to filter the output from locate.
Method #1 - be explicit
If you know you're looking for a particular version of the library, then just ask locate for it directly.
$ locate libstdc++-3-libc6.2-2-2.10.0.so
/usr/lib/libstdc++-3-libc6.2-2-2.10.0.so
Method #2 - grep
If you're looking for glibc .so ... | Keep only first match from locate output |
1,357,233,237,000 |
I run Linux Mint 21.
Currently the locate command always returns no results, and updatedb always returns immediately. The database is sized no more than a few kilobytes.
I have verified that the package mlocate is installed. The updatedb command is a cascading symbolic link that ultimately resolves to /usr/sbin/u... |
After investigation, I discovered the following option:
sudo updatedb --debug-pruning
The output is lengthy, but ends with the following line:
Skipping `/': bind mount
In fact, the root file system is a subvolume on a Btrfs partition.
Apparently, plocate, as well as mlocate, not playing well with Btrfs subvolumes is... | locate and updatedb do nothing in Linux Mint |
1,357,233,237,000 |
How can I locate a file using locate in CentOS under a specific directory from terminal?
Locate search the whole database!
|
There is no option for that functionality in the output from man locate on CentOS 6.5, at least. But, you could get pseudo-functionality by changing a search term. For example, locate cron might produce too much output, but locate '/var/log/cron' would limit the results to those items in the locate database that match... | How to locate a file in a directory |
1,357,233,237,000 |
Just moved to Ubuntu 12.04 from Windows 7.
Under Win 7 I use "Everything" to search files and directories, it can build the index database and update it once any file or directory changes. I'm very used to it so I want know if there is something similar under Ubuntu 12.04.
Now my workaround is updatedb and locate, but... |
There are 3 choices that I'm familiar with.
tracker
recoll
Beagle
This tutorial titled, The best Linux desktop search tools discusses these and a couple of others.
Tracker
Installation is a snap.
$ apt-get install tracker tracker-utils
After installation it should start indexing your drive automatically. You can pe... | How to monitor directory/file changes to rebuild index? |
1,357,233,237,000 |
After having established the locate command's database indexing file & directory names across my FreeBSD 12 system (as described in this related Question), I now regret doing so because of its emitted security warning:
Executing updatedb as root. This WILL reveal all filenames on your machine to all login users, whic... |
The only thing that locate.updatedb does is update the locate database.
If you don't want to divulge the locations of sensitive files via that database, then you can wait for locate.updatedb to complete, and then run the rm command to remove the database:
sudo rm /var/db/locate.database
| Delete the "locate" database in FreeBSD |
1,493,068,643,000 |
When working with the output of commands such as locate which produce lists of paths in "human readable form" (i.e. without \ in front of spaces), how do you redirect their output to another command?
The output of $ locate [something] produces paths with spaces in them, which inhibits other programs to use the paths i... |
What is the specific reason you're using locate? This appears to do what you have asked for:
find . -type f -name '*doc' -exec du -h "{}" \;
That said, if you really do want do use a tool like locate or find and pass its input as parameters to another program, you can avail yourself of the NUL delimited output and i... | How to redirect a list of human readable paths to another command? |
1,493,068,643,000 |
I used locate binary many time to search something on my 1TB HDD.
Most of the time, I got many result and I have to read each line to get what exactly I'm looking for.
It would be great if the locate can output the matched pattern with color ( just like grep --color)
Is there any way to do so for locate command ?
|
The easiest way is to write a simple shell script which combines locate and grep:
Create a file somewhere in your $PATH (e.g. /usr/local/bin/clocate) with
#!/bin/sh
locate --regex "$1" | grep --color=auto "$1"
then make it executable, e.g.
chmod +x /usr/local/bin/clocate
and use it like locate. The script does only... | locate with color |
1,493,068,643,000 |
In the Linux-Ubuntu terminal:
ifconfig throws bash: ifconfig: command not found
locate command does the same.
sudo yum install net-tools throws: bash: yum: command not found as well, but I might also have made a spelling mistake there when I tested it.
What does it mean, do I have to install ifconfig? Or are there a... |
Different distributions of linux have different tools to install packages, known as package managers - you need to use the right one for your distribution. Yum is the package manager for Red Hat systems. Instead, you need to use apt, Ubuntu's package manager. Try:
sudo apt install net-tools locate
That pattern should ... | ifconfig and locate command not found, `bash: ifconfig: command not found` |
1,493,068,643,000 |
when updatedb is run it generates a mlocate.db file.
How to list all the files in the mlocate.db file?
locate *
is this correct?
|
The correct command will be locate '*' or locate "*" or locate \*.
The * has to be quoted to avoid having the shell expand it to names present in the current working directory.
| How to list all files in mlocate database file? |
1,493,068,643,000 |
Looks like it's not configurable through /etc/updatedb.conf, and not mentioned in its manual as well.
So can I change that?
|
You should probably know that mlocate only does queries on the databases created by updatedb. If you want to change the default location of the databases created by updatedb you should pass the --output FILE option to updatedb and then do the query with locate --database FILE afterwards.
You could do:
$ sudo updatedb ... | Change where mlocate stores the database? |
1,493,068,643,000 |
I ran rm -rf on /var/cache/lxc, not realizing it was full of symlinks. I've lost a bunch of files, including most of /dev. I have a mlocate.db from 16 hours ago. How do I compare the list of files from mlocate.db to what still exists to get a complete list of what is missing? locate -e says it will give me files t... |
Make a backup copy of /var/lib/mlocate/mlocate.db now, before the mlocate updatedb cron job runs again.
Dump mlocate.db to a text file:
mlocate / | sort > /var/lib/mlocate/mlocate-old.txt
Update your your mlocate.db. How to do this varies slightly according to what kind of unix clone or linux distribution you're usi... | How do I compare mlocate.db to what exists now? |
1,493,068,643,000 |
I have the following version of locate:
$ locate --version
mlocate 0.26
Copyright (C) 2007 Red Hat, Inc. All rights reserved.
This software is distributed under the GPL v.2.
This program is provided with NO WARRANTY, to the extent permitted by law.
I am trying to find all files (not directories) that have some spec... |
Your commands also outputs files the current user doesn't have the permission to access.
Slightly shorter solution would be
locate -0b '\python' | perl -0nE 'say if -f'
but it doesn't print the non-accessible files.
You can use bash to loop over the files, too, but it's a bit more verbose:
locate -0b '\python' | whil... | mlocate: how to print files only [duplicate] |
1,493,068,643,000 |
I want to pass multiple DB files to the locate command, like this:
locate -d ~/.a_locate.db:~/.b_locate.db: -Ai file_to_find
But this gives me this error:
locate: can not stat () `~/.b_locate.db': No such file or directory
The man page for locate says:
-d, --database DBPATH
Replace the default database wi... |
The second ~ isn’t being expanded; try
locate -d "${HOME}/.a_locate.db:${HOME}/.b_locate.db:" -Ai file_to_find
instead, or, since this is zsh, just
locate -d $HOME/.a_locate.db:$HOME/.b_locate.db: -Ai file_to_find
The reason is that ~/ is only expanded at the beginning of a shell word. A shell word only ends at whit... | How to pass multiple DB files to locate? |
1,493,068,643,000 |
Based on the man page of the command "updatedb", we can change and override the configuration of /etc/updatedb.conf using the below commands:
--prune-bind-mounts FLAG
Set PRUNE_BIND_MOUNTS to FLAG, overriding the configuration file.
--prunefs FS
Set PRUNEFS to FS, overriding the configuratio... |
These flags don’t change the configuration file; they affect the invocation of updatedb they are attached to, ignoring the configuration file.
Thus
sudo updatedb --prune-bind-mounts no
runs updatedb with PRUNE_BIND_MOUNTS set to no, regardless of the value set in the configuration file.
If you want to change /etc/upd... | How can I change the configuration of /etc/updatedb.conf file? |
1,493,068,643,000 |
I am having trouble understanding why find and locate would work differently for C and Python source files. My goal is to count the number source files and the sum of their source code lines for a given language. I used both find and locate to compare outputs (updatedb was just run prior to this with sudo to make sure... |
There are many problems with your commands.
First, locate *.c only looks for files matching *.c if you run it in a directory that doesn't contain any file whose name matches *.c. Otherwise the shell expands *.c to the list of matching files. That's probably not happening, otherwise you'd get a lot fewer matches, but l... | When counting source files and LOC with locate and find - why do Python files come up different? |
1,493,068,643,000 |
I would very much like to allow users in a small office environment harness the power of slocate indexed database on the file server.
Currently when users are looking for a file in our fileserver, they need to run find from their Windows workstations on the network shares that are available from the server. This loads... |
I looked and did not find any offering that provided just a web app interface to an existing slocate database file.
So you have the following options:
Roll your own. Shouldn't be too difficult use a CGI based approach which would allow users to search for entries in your pre-built slocate database file.
Skip using t... | is there a web app for returning results to a search on an indexed database? |
1,493,068,643,000 |
I run updatedb like this: updatedb --localpaths="/a /b"
/a is a removable drive. /b is the local hard drive. Although /a's not always accessible to me, I frequently want to run locate to find if I have a certain file on it (based on the last time I ran updatedb).
The problem is, if I run updatedb when it's not plugged... |
I don't know Linux on Windows, nor the GNU version of locate, but you should be able to do what you want. There is a longer version of the manual here.
Replace your single updatedb --localpaths="/a /b" by 2 commands,
updatedb --localpaths="/b"
if [ -d "/a" ]; then updatedb --localpaths="/a" --output=/dir/mydb; fi
whe... | Can updatedb keep localpaths for removable drives that aren't plugged in? |
1,493,068,643,000 |
Is there a CLI tool similar to gnome-search-tool?
I'm using locate, but I'd prefer that it grouped results where directory name is matched. I get a lot of results where the path is matched which is not what I want:
/tmp/dir_match/xyz
/tmp/dir_match/xyz2/xyz3
It needs to be fast and thus use a search index.
|
locate is very versatile can take -r and a regexp pattern, so you can do lots of sophisticated matching. For example, to match directories a a0 a1 and so on use '/a[0-9]*/'. This will only show directories with files in them since you need the second / in the path. To match the directory alone use $ to anchor the pa... | Simple CLI tool for searching |
1,493,068,643,000 |
So basically, I'm trying to delete the files:
/var/lib/mysql/db/nomNomina2.*
and when I look for them with locate, I get the following output:
/var/lib/mysql/db/nomNomina2.MYD
/var/lib/mysql/db/nomNomina2.MYI
/var/lib/mysql/db/nomNomina2.frm
but then I try to
$ rm -fv /var/lib/mysql/db/nomNomina2.frm
I get no ou... |
locate is not dependable for live, current information about what files are present on your system. Information is cached in a database.
Also consider the famous line, with link:
It's not working! Should I blame caching?
For actual current information on what files/directories exist on your box right now, use ls or... | Cannot delete file, but can delete parent directory |
1,493,068,643,000 |
What gives? Normal find and locate commands don't turn up the verify program that lives at /bin/verify. In fact, it seems they don't turn up anything that lives in /bin
[jake@jace]/bin% "find" /bin/ -iname "verify" 2>/dev/null
/bin/verify
[jake@jace]/bin% "find" /bin -iname "verify" 2>/dev/null
[jake@jace]/bin% "find... |
Gah.
[jake@jace]/bin% ls -lhd /bin
lrwxrwxrwx. 1 root root 7 May 22 2012 /bin -> usr/bin/
I'm running Fedora 17. Apparently /bin is symlinked to /usr/bin. And of course (and quite rightly) find and locate ignore symlinked directories to avoid result pollution.
| Why don't find and locate search /bin? |
1,493,068,643,000 |
Currently I'm trying to migrate from mlocate to plocate.
I'm using mlocate in my script (note: locate is aliased to either mlocate or plocate depending which one I've installed).
Successfully searched home directory with mlocate
Below is the first 10 outputs after running locate home (locate is aliased to mlocate):
/h... |
TL:DR: if you're using btrfs, do the following:
edit /etc/updatedb.conf
replace PRUNE_BIND_MOUNTS = "yes" with PRUNE_BIND_MOUNTS = "no"
save the file
update the db with sudo updatedb
test again with locate home to see any outputs from home directory.
Explanation
I contacted plocate author and he kindly sent me to th... | `plocate` couldn't find results in my home dir but `mlocate` could. How to search results in home dir? |
1,493,068,643,000 |
For context, I'm using zsh. Every time I use locate, I want to pass the -i and -A flags.
Usually, if I can get away with it, I create an alias with the same name as the existing command to do this. But according to this question, aliases can't accept arguments, so I have to use a function instead. Usually I stop there... |
I am really surprised by that other post you mentioned, as it can be very misleading. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. Of course you can put options in an alias, but it is just restricted, meaning, the alias is replaced in one place.
$ alias ls='ls -l'
$ l... | How can I/Should I default flags when running a command? |
1,493,068,643,000 |
I often use locate as a command to find stuff system-wide.
However, I find it very annoying that the osx version of locate doesn't seem to have the -b option to match the basename only; and so prints all the content of every folder that matches the query.
It also doesn't have the -e option for checking whether the fil... |
Kasa's answer pointed me to the right direction: these are two different programmes. The Linux locate is actually mlocate, and can be installed on Mac with some struggles, as some people have done, while the Mac locate is a different and older version. More about the difference in this answer.
However, the easier way ... | `locate` in linux vs osx |
1,493,068,643,000 |
System: Linux Mint 19.1 Tessa, edition: Cinnamon
Got a problem with a locate command. I created test.txt file on a desktop. After that I did:
sudo updatedb
However
locate test.txt -i
still doesn't show anything.
Permissions to mlocate.db: -rw-r----
Working on normal user, not root (that's why I was using sudo comm... |
The updatedb command will scan the filesystems on your system and create an index of the names of the available files and directories. This indexing is performed as a non-privileged user. This means that the index will only ever contain the names of files that are accessible by all the system's users.
Since your hom... | Locate doesn't work |
1,493,068,643,000 |
Does the locate database not save certain files? Like are there files that excluded from the database by default?
|
Depends on the locate implementation and configuration. On my Ubuntu 16.04, the default configuration skips a few things:
$ cat /etc/updatedb.conf
PRUNE_BIND_MOUNTS="yes"
# PRUNENAMES=".git .bzr .hg .svn"
PRUNEPATHS="/tmp /var/spool /media /home/.ecryptfs /var/lib/schroot"
PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_m... | Do some file get excluded from being saved in the locate database? |
1,493,068,643,000 |
There are multiple installation of Java on my system, some silently installed by IDEs, and I wanted to find out where they are. So I thought to use locate to find them. My first try of
locate java
had several thousand hits finding .*java.*.
Is there a way to restrict the locate to just find files with and exact name?... |
From man locate:
To search for a file named exactly NAME (not *NAME*), use
locate -b '\NAME'
locate -b '\java'
-b - Match only the base name against the specified patterns.
| how to find occurrences of a file using locate |
1,493,068,643,000 |
Is there any alternative out there for find similar to ag and ack?
I'm really tired of having to type:
find some/app -iname "some_file*"
I much rather just type:
find "some_file*"
And have it search for the current folder and recursively in all subfolders.
|
That's what functions or scripts are for. e.g.
myfind() {
search="$1"
shift
find . -iname "$search" "$@"
}
The "$@" on the end allows you to still specify other find options if you want to. Note, however, that find is quite fussy about the order of some options, some options only work if they come befor... | Shorthand alternative to find |
1,493,068,643,000 |
This output is rather self-explanatory:
XXXXX@debianvirtualbox:~$ locate -r "^/var/lib/tomcat[0-9]/.*" -l 10
/var/lib/tomcat8/conf
/var/lib/tomcat8/lib
/var/lib/tomcat8/logs
/var/lib/tomcat8/webapps
/var/lib/tomcat8/work
/var/lib/tomcat8/webapps/ROOT
/var/lib/tomcat8/webapps/websight
/var/lib/tomcat8/webapps/ROOT/META... |
Try --regex (without a 'p') rather than -r (aka --regexp). This tells locate to use extended regexps rather than basic.
locate --regex "^/var/lib/tomcat[0-9]{1,2}/" -l 10
alternatively, escape { and } with \ to make them special in basic regex.
| Regex quantifiers are not working well with locate |
1,493,068,643,000 |
locate (or rather, updatedb) is somewhat simple: it takes the output of find for the required paths (usually '/'), sorts it, and then compresses it with a front-compression tool (frcode), in which the consecutive common prefixes are replaced by number of repeated characters.
So I'm wondering, what's stopping anyone fr... |
Often, GNU grep and BSD competition is just pretty slow.
People like ag (aka the_silver_searcher), rg (aka ripgrep) or ack; they don't try to build an index of the text, they just search it anew for every query, but in a more efficient manner than grep. I'm using (mostly) rg these days, and it really makes searching t... | Just as there is "locate" to "find". Is there a database for a faster "grep"? |
1,493,068,643,000 |
This may come across as a silly question because each file and directory on a system can and will have permissions to block an ordinary user from seeing various files- but for added security sake and a context too long to get into: Can mlocate have multiple databases for different groups of users? Or every user for th... |
mlocate, by default, only shows files that the user has access permission to. At least on my CentOS 7 build:
For example:
% rpm -qf /usr/bin/locate
mlocate-0.26-8.el7.x86_64
% locate /root/.ssh
% sudo locate /root/.ssh
/root/.ssh
/root/.ssh/authorized_keys
/root/.ssh/known_hosts
This works because locate is setgid... | Different mlocate database for each user? |
1,493,068,643,000 |
I often use the following pipeline of locate (from findutils) and grep to find files whose pathnames contain two words word1 and word2, without any specific order between each other:
locate -i word1 | grep -i word2
I was wondering how to do that with a single non-pipeline command alone? Is it a better way than my pi... |
That very much depends on your implementation of locate. That's not a standard command and there are a few different implementations with quite significant differences.
There's one implementation in GNU findutils.
With that one:
locate -i word1 word2
locates files whose path contains either word1 or word2 case
insen... | Improve search for files by pathnames with locate and grep pipeline |
1,493,068,643,000 |
I love Synapse in Xfce and want to know more about improving its use.
I use it to restart, logout or shutdown, launch applications, access files and folders.
I have been trying to fix a few problems that affected file access on my second drive, as it involved opening files with executable permission and searching on ... |
Trying to learn about this, I have found about the basics of Synapse's operation, which can be presented here as an answer.
Not only Synapse launcher has a lot of plugins that enhance its operation, but it is entirely based on plugins. Disabling all of them makes it useless: even Application Search is a plugin.
When... | Synapse launcher: what is the difference between the `locate` command and the simple search? |
1,493,068,643,000 |
Problem
I tried to implement a negative lookahead when searching a file with locate like this:
locate --regex "apple(?!t)"
However I'm getting the following error, because there seems to be some substitution going on:
locate: invalid regexp `apple(?touch latex_preamble.tex)': Invalid preceding regular expression
Ho... |
There are several implementations of locate, and the ones I'm aware of want either POSIX extended regexps, or POSIX basic regexps. Neither support lookaheads.
| Locate --regex with negative lookahead |
1,302,684,686,000 |
I tried to rm -rf a folder, and got "device or resource busy".
In Windows, I would have used LockHunter to resolve this. What's the linux equivalent? (Please give as answer a simple "unlock this" method, and not complete articles like this one. Although they're useful, I'm currently interested in just ASimpleMethodTha... |
The tool you want is lsof, which stands for list open files.
It has a lot of options, so check the man page, but if you want to see all open files under a directory:
lsof +D /path
That will recurse through the filesystem under /path, so beware doing it on large directory trees.
Once you know which processes have file... | How to get over "device or resource busy"? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.