output
stringlengths 9
26.3k
| input
stringlengths 26
29.8k
| instruction
stringlengths 14
159
|
---|---|---|
TL;DR
Don't do this unless you have peculiar auditing requirements. It's generally more trouble than it's worth.
Explanation
The only account that should have write access to /boot is root. If you have root, you can unset immutable bits and pretty much do what you want anyway.
The major downside of mounting /boot read-only, setting immutable bits, or anything similar is that you will need to undo those settings every time you update your kernel or boot loader. This is much more likely to trip you up than it is to offer meaningful security.
Alternatives
Depending on what you're really trying to do, you may have some alternatives. For example:Ensuring that /boot is on a separate partition that is rarely written to is a good idea if you're worried about filesystem corruption.
Periodically validating the contents of /boot with Tripwire or debsums, especially when comparing against hashes stored on separate read-only media, is a good security measure if you're worried about tampering.
Mounting /boot read-only, and then having your package manager mount it read-write during updates, may be useful.Remounting Read-Only Partitions During Apt Updates
As an example the last alternative, you might configure /boot read-only in your /etc/fstab, then add something similar to the following to your /etc/apt/apt.conf on Debian-based systems:
DPkg {
Pre-Invoke { "mount -o remount,rw /boot"; };
Post-Invoke {
"test ${NO_APT_REMOUNT:-no} = yes ||
mount -o remount,ro /boot ||
true";
};
};This will keep /boot read-only except during updates. Obviously, you will need to do something different if you aren't using the apt package manager, or if the above doesn't work for some other reason.
| What is the effect of setting immutable bit on /boot partition with perspective of security.
is it advisable to set the immutable bit (-i) to everything under /boot? Will it enhance or degrade the system security?
I would like to go further and do the same for other "precious" files like /etc/bind/named.conf, etc.
| What is the effect of setting immutable bit on /boot partition [closed] |
The letters `acdeijstuADST' select the new attributes for the files:
append only (a), compressed (c), no dump (d), extent format (e),
immutable (i), data journalling (j), secure deletion (s), no tail-merg‐
ing (t), undeletable (u), no atime updates (A), synchronous directory
updates (D), synchronous updates (S), and top of directory hierarchy
(T).from the manpage for chattrFiles with this flag will fail to be opened for writing. This also blocks certain potentially destructive system calls such as truncate() or unlink().
$ touch foo
$ chattr +a foo
$ python
> file("foo", "w") #attempt to open for writing
[Errno 1] Operation not permitted: 'foo'
> quit()
$ truncate foo --size 0
truncate: cannot open `foo' for writing: Operation not permitted
$ echo "Appending works fine." >> foo
$ cat foo
Appending works fine.
$ rm foo
rm: cannot remove `foo': Operation not permitted
$ chattr -a foo
$ rm fooThis option is designed for log files.
|
what does the a in chattr +ia <filename> do? and why would you add the a in combination with the i? note: I know the i is for immutable
| what does the "a" in chattr +ia do? |
You don’t mention it in your text,
but your code block shows that you are doing your test in /tmp.
Even if your root filesystem (HDD or SSD) is ext4,
you might have /tmp mounted as a separate filesystem,
probably of type tmpfs, and that does not support extended attributes.
You can check whether this is the case
by executing any of the following commands:mount | grep tmp
df /tmp
grep /tmp /etc/fstabThe fact that the getfattr succeeds is a little surprising, but not very.
I guess some developer thought it would be harmless
to report that a file has no extended attributes
when the filesystem doesn’t support extended attributes.
After all, it’s true — the file has no extended attributes.
|
I am trying to get extended attributes working on Fedora 22. I can't seem to be able to set the attributes even on my files, but I can read them. Here's how it looks:[jarek@localhost ~]$ cd /tmp/
[jarek@localhost tmp]$ touch a
[jarek@localhost tmp]$ setfattr -n "user.abc" -v "blah" a
setfattr: a: Operation not supported
[jarek@localhost tmp]$ sudo setfattr -n "user.abc" -v "blah" a
setfattr: a: Operation not supported
[jarek@localhost tmp]$ strace setfattr -n "user.abc" -v "blah" a
...
setxattr("a", "user.abc", "blah", 4, 0) = -1 EOPNOTSUPP (Operation not supported)
...
+++ exited with 1 +++
[jarek@localhost tmp]$ getfattr a
[jarek@localhost tmp]$ echo $?
0Some information about my system:[jarek@localhost ~]$ uname -a
Linux localhost.localdomain 4.1.5-200.fc22.x86_64 #1 SMP Mon Aug 10 23:38:23 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[jarek@localhost test]$ mount |grep /dev/sda5
/dev/sda5 on / type ext4 (rw,noatime,seclabel,discard,data=ordered)Does anyone have an idea what am I doing wrong? This works on Ubuntu 14.04.
Edit
That is indeed on /tmp which is a tmpfs, not ext4 file system on my system.
| Can't set extended attributes on ext4 on fedora 22 - operation not supported |
The location of the X cookie file can be configured with the XAUTHORITY environment variable. The default is ~/.Xauthority.
Of course, the location that you pass to applications has to match the location where the cookie is stored. SLiM doesn't offer a way to add the cookie to a different file: it has ~/.Xauthority hard-coded. If you want to use a different file, patch SLiM or use a display manager that happens to have this configuration option. For example, Gdm stores X cookies under /var/run/gdm.
I think you can make .Xauthority a symbolic link, if you don't want the modifiable file to be in your home directory.
Making your home directory immutable is an exercise in futility. You're likely to encounter many other similar issues. The standard place for configuration files and state files is your home directory — that's where dot files get their name, because they start with a . so that ls won't list them by default.
|
Is it possible to change the location for .Xauthority, to something other than $HOME/.Xauthority ? AFAIU, this file is being created every time I log into LXDE, by my login manager slim.
The problem I am having is following:
I want to set my home to "immutable" using extended attributes:
chattr +i /home/martin/This way, no applications can save their files directly in /home/martin/, but they can still save files in directories located lower levels of my home, i.e. /home/martin/.config/.
At the moment, when I set my home to immutable, I cannot login to LXDE because the login manager (slim) cannot create /home/martin/.Xauthority. This happens even if the old .Xauthority exists. The login manager could just overwrite the old file with new data, but apparently this is not what it does. It creates a new file and deletes the old one. This is not allowed when /home/martin is immutable (overwriting existing file would be allowed).
Therefore, I would like to store .Xauthority somewhere else, such as .config/.Xauthority. Is this possible?
I know that xauth takes the parameter -f where file path can be specified.
UPDATE:
looking at the source code of slim, I think I might have found the place where .Xauthority is being deleted and created again:
string xauthority = pw->pw_dir;
xauthority.append("/.Xauthority");.../* reinitialize auth file */
authfile = cfg->getOption("authfile");
remove(authfile.c_str());
putenv(StrConcat("XAUTHORITY=", authfile.c_str()));
Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
authfile);How could I change the source code, so that file gets overwritten, rather than deleted/created ?
| change location of $HOME/.Xauthority |
Use attr instead of getfattr to retrieve the attribute. This utility will, by default, handle attributes in the user namespace. It is easier to pull out only the attribute's value too, so there's no need for parsing:
find /files/to/audit -type f -exec sh -c '
for pathname do
attrval=$( attr -q -g test "$pathname" 2>/dev/null )
if [ -z "$attrval" ]; then
printf "%s\n" "$pathname"
fi
done' sh {} +Or, shorter,
find /files/to/audit -type f -exec sh -c '
for pathname do
[ -z "$( attr -q -g test "$pathname" 2>/dev/null )" ] && printf "%s\n" "$pathname"
done' sh {} +These code snippets would call a short in-line script with batches of found regular files from in or under /files/to/audit. The sh -c script loops over the current set of found pathnames to try to get the user.test attribute from each. Any pathname that generates a missing or empty attribute value is printed.
On Debian-based Linux distributions, the getfattr and attr utilities are distributed in the same package (called attr).Slightly fancier, with a parametrised attribute name and output that will indicate either missing or zero-length attribute values:
attr=testfind /files/to/audit -type f -exec sh -c '
attr=$1; shift
for pathname do
if attrval=$( attr -q -g "$attr" "$pathname" 2>/dev/null )
then
if [ -z "$attrval" ]; then
printf "Empty: %s\n" "$pathname"
fi
else
printf "Missing: %s\n" "$pathname"
fi
done' sh "$attr" {} +Or, following the DRY principle:
attr=testfind /files/to/audit -type f -exec sh -c '
attr=$1; shift
for pathname do
unset -v issue if attrval=$( attr -q -g "$attr" "$pathname" 2>/dev/null )
then
[ -z "$attrval" ] && issue=Empty
else
issue=Missing
fi if [ -n "$issue" ]; then
printf "%s: %s\n" "$issue" "$pathname"
fi
done' sh "$attr" {} + |
I think I'm close here but I'm missing something stupid. I'm trying to make awk print out the filenames for files that are missing extended attributes or are missing an attribute value.
So a file will have something like:
getfattr -d /path/to/file/testfile.1 # file: /path/to/file/testfile.1
user.test="1"awk should return the filename if two conditions are met; if user.test is missing, or if user.test is null i.e "". It seems like the obvious way to do this is to simply check the NF. If the NF is 2 or less it means that we're missing one or the other and thus we can print the filename. This is what I have so far:
readarray -t PATHS_ARRAY < <(find /files/to/audit type -f)attr="user.test"printf -- '%s\0' "${PATHS_ARRAY[@]} |\
xargs -0 getfattr -P --absolute-names --name="$attr" |\
awk -v attr_="${attr}=" '
BEGIN { FS="[ ,\"]+" }
$0 ~ ( attr_ ) {
if ( NF <= 2 ) {
print fname
next
}
} { fname = $0 }
'We're separating on ", so for a "correctly" set extended attribute we should get
NF=
1 2 3
user.test=" 2 "and a broken one will be
NF=
1 2 (or 0 because user.test does not exist)
user.test=" " | AWK return path for files with NF <= 2 |
When you run > /tmp/foo.txt, you are overwriting the contents of /tmp/foo.txt with the output of sed 's/old text/new text/' file1.txt. Since /tmp/foo.txt doesn't exist when you run this command, bash will create that file for you and then write it.
Then, when you use the -p flag to cp, you are copying the permissions and attributes of /tmp/foo.txt to file1.txt and overwriting it in the process.
Instead, what you want to do is overwrite the contents of file1.txt with the contents of /tmp/foo.txt, which should sound familiar. Run
sed 's/old text/new text/' file1.txt > /tmp/foo.txt
cat /tmp/foo.txt > file1.txtNote that this doesn't copy any permissions or attributes from file1.txt to /tmp/foo.txt or vice versa - you are maintaining the existing metadata for file1.txt, but modifying the content.
In this specific instance, you could also just use sed -i as pbm suggested.
|
On OSX you can have tags which allows you to identify different categories of files. Here are two text files with different tags when viewed in Finder:I have a large number of these files and have written a bash script to make several edits on these files. So, for instance I do:
$ sed 's/old text/new text/' file1.txt > /tmp/foo.txt
$ cp -p /tmp/foo.txt file1.txtin which case I get the desired file content but loose the tags:Question:
How do I copy the tags from the original file to the edited file?
| Edit a file via a script yet maintain the osx tags |
It turns out that Rich ACL's are not supported by the mainline Linux kernel.
Source: https://wiki.samba.org/index.php/NFS4_ACL_overview#Linux
Further, as of 2 May 2019:
Re: PATCH overlayfs: ignore empty NFSv4 ACLs in ext4 upperdir - Andreas GruenbacherThe patches for implementing that have been rejected over and over again, and nobody is working on them anymore.Thanks reddit user progandy for this info.
|
I am just learning about Rich Access Control Lists on Linux. My immediate objective is to give members of the group the same rights as the owner for a subdirectory tree (all files and directories within).
I have reviewed the man pages for setfattr and getfattr. Neither of those man pages provide a list of the available RichACL's. (I'm really only interested in the RichACL's that are compatible with BTRFS.)
This is another good resource richacl: Rich Access Control Lists - Linux Man Pages (7) that provided some background.
I have done simple examples such as:
setfattr -n user.comment -v "this is a comment" test.txtFollowed by:
getfattr test.txtI know that these operations are different from setfacl and getfacl.
I also understand there are four namespaces of extended file attributes:user
trusted
security
systemAnd I know that RichACL's are richer than POSIX ACL's. And ACLs are different from extended attributes (but they may be stored in xattr name spaces). I know the specifics of what I'm trying to do are filesystem dependent, and that's OK. I only care about BTRFS.
However, I don't have enough information to be able to do anything useful yet. As mentioned, the first thing I want to do is to give the group all the same rights as the owner of a file or directory. Then I want to have those inherited to subdirectories and files in those directories.
Some specific examples include: I want the group members to be able to do operations like chmod, chatttr or even chown, if I deem that to be appropriate.
EDIT: as part of your answer, please also address the utilities (programs) used to read and set rich acl's. I have seen setfattr used in connection with rich acl's. However, I have also seen reference to a utility named setrichacl but I do not find such a utility in Arch Linux.
Stock kernel config info for ACL's:
$ zcat /proc/config.gz | grep -i acl
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_REISERFS_FS_POSIX_ACL=y
CONFIG_JFS_POSIX_ACL=y
CONFIG_XFS_POSIX_ACL=y
CONFIG_BTRFS_FS_POSIX_ACL=y
CONFIG_F2FS_FS_POSIX_ACL=y
CONFIG_FS_POSIX_ACL=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_JFFS2_FS_POSIX_ACL=y
CONFIG_EROFS_FS_POSIX_ACL=y
CONFIG_NFS_V3_ACL=y
CONFIG_NFSD_V2_ACL=y
CONFIG_NFSD_V3_ACL=y
CONFIG_NFS_ACL_SUPPORT=m
CONFIG_CEPH_FS_POSIX_ACL=y
CONFIG_9P_FS_POSIX_ACL=y | How to apply and use Rich Access Control Lists with BTRFS |
You can run inoticoming to watch for files placed in the directory and automatically run any command, in this case chattr. (note linux specific)
|
Let's say I want to set one or more attributes (in the chattr sense) on every file created in a given directory.
Is there a way to achieve this automatically, like umask does for file permissions ?
In other words, is there a way to omit the chattr step in :
$ copy file /path/to/backup/
$ chattr +i /path/to/backup/filefor every file created in /path/to/backup/ ?
Note : My system is Debian and my filesystem is ext3.
| Automatically set file attributes in a given directory |
User extended attributes are supported by default on Ext4, you don’t need to do anything to enable them. To verify this, run
cd
touch xattr-test
setfattr -n user.test -v "hello" xattr-test
getfattr xattr-testThis should show that the extended attribute was successfully stored.
|
I have added user_xattr in ext4 but when I remount it doesn't show xattr & I installed attr & attr_dev
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/Anonymous--vg-root / ext4\040remount,user_xattr errors=remount-ro 0 1` | how to enable xattr support in Debian 9 (Stretch) |
From man xattr both kernel and filesystem can limit the maximum number/size xattr
grep XATTR /usr/include/linux/limits.h#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */
#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */
#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */For btrfsIn the Btrfs, XFS, and Reiserfs filesystem implementations, there is
no practical limit on the number of extended attributes associated
with a file, and the algorithms used to store extended attribute
information on disk are scalableAndIn the Btrfs filesystem implementation, the total bytes used for the
name, value, and implementation overhead bytes is limited to the
filesystem nodesize value (16 kB by default). |
What is actual max allowed size of btrfs xattr? I tried to test this on few systems and got entirely different results (between 11kB and 15kB) so I'm not sure what actually determines this size and whether I'm able to verify it before assignment? (other than brute force binary search)
| Btrfs - max xattr size? |
You can't just use any name. You need to select a namespace. For arbitrary attribute name, you'd need to use the user namespace:
setfattr -n user.naomi -v washere delete.me(see man 5 attr for details).
For ext4, the ext_attr feature must be enabled (on by default). Check with:
sudo debugfs -R stats /dev/block/device | grep -w ext_attrAnd to be able to use attributes in the user namespace, the filesystem should be mounted with the user_xattr option enabled (also on by default). Check with:
grep user_xattr /proc/self/mountinfoIf it returns nothing, also check the default mount options in the debugfs output above.
|
I'm trying to use setfattr, but always get Operation not supported
In my home directory, I'm doing the following:
touch delete.me
setfattr -n naomi -v washere delete.meThis returns setfattr: delete.me: Operation not supported.
My home directory is ext4 and delete.me definitely exists. I'm on Fedora 25. Any idea why this is not working?
| Cannot set file attribute |
The specific attribute in this issue is i, the immutable attribute.
The file was marked immutable.
This means it is unchangeable at all by any user including root. Root can still change the attributes and remove the immutable attribute, but must to so first before making changes to the file, unlike standard no-write permissions to a file which root can simply ignore.
These attributes are only applicable to ext[234] file systems so far as I know.
You can see the man page for chattr,
$man chattrto see a full list and description of the available attributes.
The only one I've ever actually used is i. But some of the others include:
A: atime remains unmodified when accessed
a: can only be opened for writing in append-only mode
c: compressed automatically
j: all data is written to the journal before being written to the file
s: blocks are zeros when file is deleted
u: contents of file are saved when file is deleted for later undeleteThere are other attributes but they are somewhat esoteric and much more info can be found on them in the chattr man page.
|
I am logged into my remote VM (running out of ESXi) as user xyz. I wanted to change my /etc/hosts to add some network names that were not visible by default.
I first tried to run
sudo vi /etc/hostsbut when I got into vi, it was still telling me the file was read-only. Here are the privileges:
>ls -l /etc/hosts
-rw-r--r-- 1 root root 416 2013-06-19 08:08 /etc/hostsI also noticed that almost every other file in /etc has a lsattr of -----------------e-, only hosts has ----i------------e-. E.g.:
>lsattr /etc
...
-----------------e- ./python
----i------------e- ./hosts
...Then I tried to chmod and here is what I got:
>sudo chmod +w /etc/hosts
chmod: changing permissions of `/etc/hosts': Operation not permittedI thought that was weird because root (to which I am switched when I sudo) should be able to do anything. My sudoers file looks quite ordinary:
1 # /etc/sudoers
2 #
3 # This file MUST be edited with the 'visudo' command as root.
4 #
5 # See the man page for details on how to write a sudoers file.
6 #
7
8 Defaults env_reset
9
10 # Host alias specification
11
12 # User alias specification
13
14 # Cmnd alias specification
15
16 # User privilege specification
17 root ALL=(ALL) ALL
18
19 # Allow members of group sudo to execute any command after they have
20 # provided their password
21 # (Note that later entries override this, so you might need to move
22 # it further down)
23 %sudo ALL=(ALL) ALL
24 #
25 #includedir /etc/sudoers.d
26
27 # Members of the admin group may gain root privileges
28 %admin ALL=(ALL) ALLI am looking for an explanation why this is happening and how to work around it.
| Unable to run 'sudo chmod +w /etc/hosts' |
This is a feature. See man chattr:A file with the 'i' attribute cannot be modified: it
cannot be deleted or renamed, no link can be created to
this file, most of the file's metadata can not be
modified, and the file can not be opened in write mode.
Only the superuser or a process possessing the
CAP_LINUX_IMMUTABLE capability can set or clear this
attribute.It is possible to have multiple immutable hard links to a given file: create the links first, then make one of them immutable; they will all become immutable.
|
I had set the immutable attribute for a file that shouldn't be changed until it is deleted
(The file was a backup image of a virtual machine).
As it seems the file also cannot be hard-linked, i.e. it cannot be renamed.
Is that the way it should be?
Compared to a file lacking write permission, this behaves quite differently.
I couldn't find a manual page giving details.
In case it matters:
The filesystem where the problem was seen was OCFS2.
| Bug or feature: Cannot link immutable file |
Nautilus uses ~/.thumbnails normally. Lots of image viewers do generate thumbs there as well. In the normal sub-dir of my system most of the preview files are about 20 KiB in size. It's kinda disturbing that there're no either sqlite database in single file or cache hierarchy (like f/ff/ffdcd558a…1e5200.png) so some FSes could have poor performance looking up a file inside overgrown directory, though, but on the other hand, plain file storage is way simpler to handle inside bunch of different user programms, no mandatory demanding sqlite to be installed and most up-to-date FSes shouldn't have troubles with such plain files layout.
Problems with xattr resemble sqlite's ones — extra complexity, limitations of FS support (according to wikipedia only ReiserFS and XFS handle arbitrary sizes, and EXT3,4 are limited to one block only which would mean 4 KiB mostly).
|
Is there any file browsers for Linux that cache image previews, just like Windows Explorer cache them to a file named Thumbs.db?
As in the latest ext3/4 filesystems, an inode can hold extended attributes, is it utilizied by any file browser? Well, the default 256B inode size may be too small to hold the preview, I can reformat it to get a bigger inode.
I'll be very glad to hear good news, because to refresh the previews for large images and video files are very slow in Nautilus, and noises from the harddisks ..
| How to utilize extended attributes for image preview? |
There’s no reason to have libraries in /usr/share/doc, and as you point out, the “libraries” (which probably aren’t libraries, given the command shown in your htop screenshot) aren’t referenced anywhere. This is extremely likely to be an attack.
See this answer and the links therein for details of what you should do now.
|
Ubuntu Server can't be upgraded because it says that openssh-sftp-server package have unmet dependencies
The following packages have unmet dependencies:
openssh-sftp-server : Depends: openssh-client (= 1:8.2p1-4ubuntu0.2) but 1:8.2p1-4ubuntu0.1 is installedWhen I try to use apt --fix-broken install to install what is missing I receive the following output:
...
dpkg: error processing archive /var/cache/apt/archives/openssh-server_1%3a8.2p1-4ubuntu0.2_amd64.deb (--unpack):
unable to make backup link of './usr/sbin/sshd' before installing new version: Operation not permitted
...
dpkg: error processing archive /var/cache/apt/archives/openssh-client_1%3a8.2p1-4ubuntu0.2_amd64.deb (--unpack):
unable to make backup link of './usr/bin/ssh' before installing new version: Operation not permitted
...Investigating I found that both files have the immutable attribute.
$:~# lsattr /usr/bin/ssh
----i---------e----- /usr/bin/ssh
$:~# lsattr /usr/sbin/sshd
----i---------e----- /usr/sbin/sshdEverytime I try to change attribute of '/usr/bin/ssh' or '/usr/sbin/sshd' with the command chattr -i /usr/bin/ssh or chattr -i /usr/sbin/sshd several processes spawns throwing
... chattr +i /usr/bin/chattr ... /usr/bin/ssh /usr/sbin/sshd (as can be seen in the image below).The process is also changing attributes of the following files.
----i---------e----- /usr/share/doc/libbasechattr.0.so.2
----i---------e----- /usr/share/doc/libchattr-1.0.so
----i---------e----- /usr/bin/chattrI can't find information on the Web for the terms libbasechattr and libchattr.
I found the same behavior in two unrelated machines that are on different sites and don't communicate directly.
System details:Ubuntu Server 20.04.02 LTS
Kernel Linux 5.4.0-66-generic #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021 x86_64
OpenSSH_8.2p1, OpenSSL 1.1.1f 31 Mar 2020
Filesystem is ext4 in one machine and btrfs in the other.Has anyone experienced this before, is this a bug or an attack?
| /usr/bin/ssh and /usr/sbin/sshd can't be moved to update openssh-server and openssh-client because of immutable attribute |
With the filesystem unmounted, you should be able to use debugfs -w -R "rm path_to_file" /dev/sda1 to delete the file.
|
I was experimenting with encryption on an ext4 filesystem and I encrypted a file (using fscrypt) which was set to be immutable (via chattr +i). I have now lost the encryption key and uninstalled fscrypt.
I would like to delete the file, but when I try to delete it, I get the following error:
# rm foo
rm: cannot remove 'foo': Operation not permittedand when I try to make it mutable:
# chattr -i foo
chattr: Required key not available while reading flags on fooTherefore, I believe I cannot delete the file as it is immutable and I cannot change its attributes due to encryption. Any suggestions?Edit:
I have tried the following and they do not work:Deleting/modifying the files from a Live USB. The same errors occur.
Trying after removing the encrypt feature, as Ángel suggested. fsck also doesn't throw any errors for some reason.Output of findmnt (testdir contains foo) and filesystem properties:
$ findmnt --target testdir
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda4 ext4 rw,relatime# tune2fs -l /dev/sda4 | grep "Filesystem features"
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum | How do I delete an immutable encrypted file? |
There is no such flag with Linux chattr. You can either make the file immutable or append-only (in either case, the file's permissions and ownership will be locked), or allow the owner of the file and root to change the permissions. (The immutable attribute on a directory prevents creating or removing files from it but not changing entries' metadata.)
If changing the ownership of the file is acceptable, do it, and use access control lists (or group ownership) to give whoever needs it read and write access to the file. If this is a social issue where your fellow roots can't be relied on, I don't think you'll find a satisfactory technical issue.
Disallowing the owner of a file to change permissions falls into the category of mandatory access control, which is not something unix traditionally supports. There are several MAC frameworks on Linux, and the two major ones are SELinux and AppArmor; I don't know whether they do allow what you're trying to do.
If this is a general problem, you could look into using a database for storage. You can typically give someone the permission to read and write to a table without letting them control the permissions.
A less drastic step than moving to a database would be moving the files to a different filesystem (this may or may not be feasible in your setting). You could then use symbolic links in the place where the files must exist, and hope the permission changers aren't sophisticated enough to look in the place where the real files are (perhaps that could be made read-only?).
A FUSE filesystem that mirrors file contents but changes metadata is another possibility. An existing one is bindfs, which can rewrite permissions (-o perms=…) and can ignore chmods (-o chmod-ignore).
|
Is there any chattr flag that would allow me to lock a file's unix permissons, and not change them without resetting the flag? The file itself should still be modifiable, I just want to prevent ... ignorant people ... from changing the permissions to something wrong accidentally.
| immutable-like flag for perms |
This works
sudo chattr +a +u /path/to/dir |
I want to create a directory which is undeletable, and that you can only add files, not delete any file therein.
I was reading the man chattr page and I came across attribute aA file with the 'a' attribute set can only be opened in append mode for writing. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.But it just mentions files. Can I apply it to a directory? Something like
sudo chattr +a +u /path/to/dir | Append only attribute for directories |
Ext2 and family (including ext4) reserve an attribute for compression but don't implement it. This feature was originally put off because there were more urgent things to do, and then it became obsolescent as the size of storage media increased a lot faster than the size of data that isn't already compressed. Most large files today (videos, music, even word processor documents) are already compressed.
Compression can still make sense for medium-sized files. Performance-wise, it's a trade-off: it costs more CPU time but less I/O time.
Zfs includes everything but the kitchen sink, and in particular it does support compression. So does Linux's btrfs.
|
I would like to be able to compress certain files (that I need to keep, but use rarely) on disk. I noticed that chattr +c flags a file for compression, but it doesn't seem to actually compress files.
What is the simplest way to implement file compression on a per-file or per-directory basis?
| File compression - how to implement in Linux |
After chattr +i, you can't edit the directory. You'll find that adding, renaming, and removing files does not work—that's all that is actually in a directory. In order to prevent editing the files, you need to chattr +i them, too. (Remember: Unix has hardlinks; a single file can exist in multiple directories.)
Depending on what you're trying to accomplish, a read-only bind mount may do what you want. You can make one like this:
# mount --bind /source/path /dest/path -o roNow any access via /dest/path will not be able to change the files and directories at all (but access via /source/path still can). You can prevent access to the source the normal ways (e.g., have it inside some directory with permissions go-x set).
Or maybe what you're doing will work if you just remove write permission, recursively, with a simple chmod -R o-w the-directory.Also, i want to know how to prevent a directory from anything! So no one can delete, edit, or even read it?wipe, shred, or even plain rm would be the normal ways. Ok—that's somewhat sarcastic. If you mean no one other than yourself, then chmod go-rwx the-directory. If you mean not even root, then the best bet is to put it on some removable media and remove it. If you must keep it online, SELinux can do this—but that adds a lot of complexity.
|
How to prevent a directory (including all of its contents), from being edited?
Using command chattr, you can prevent a directory from being deleted:
chattr +i folderBut, you can edit this directory(folder).
So how can i prevent it from being edited (I.e: deleted, writing, creating a file and...) ?
Also, i want to know how to prevent a directory from anything! So no one can delete, edit, or even read it?
| How to prevent a directory from being edited |
I found out how to do it. If anyone experiences the same, you can run
find /path/to/dir/ -type d,f -exec setfattr -x security.selinux {} \; |
I have run exa --long --extended on a folder containing some wallpapers and I noticed that it returns a strange security.selinux (len 37) tag on several of my files. I'd like to know what it is and how to get rid of it. I assume it's something that got passed when I backed up my files from my old Fedora install, but I've since moved from Fedora to Arch and I have switched to apparmor due to the better support for it on latter.
Here is what I'm talking about:
drwxrwxr-x@ - MYUSER 29 juni 19:09 wallhaven_wallhaven_cc_search_q_yosemite_categories_100_purity_110_atleast_2560x1440_sorting_relevance_order_desc
└── security.selinux (len 37) | What is this strange SELinux attribute on several of my files? |
GNU tar can read xattrs and do filtering on them, see https://www.gnu.org/software/tar/manual/html_node/Extended-File-Attributes.html.
A Squashfs filesystem can now be created from a tar archive using sqfstar (in version 4.5 and later).
So something like
tar --xattrs --xattrs-exclude='user.*' -c your-directory | sqfstar img.sqfsShould work.
|
I have a directory containing a root filesystem that I SquashFS and then mount as r/o on other boxes.
However, before SquashFS'ing, i want to clear all the user-namespace xattrs from the filesystem. This is trivial to do with a small getfattr and setfattr loop script, but I want to avoid introducing those as a dependency.
The sticky part is that I only want to clear the user xattrs. I need to preserve the security xattrs as they contain my SELinux labels. So simply telling Squash to not collect the xattrs is not an option.
One idea i had was to get the size of the filesystem, allocate a blank file of that size, format it as ext4, and mount it with -o nouser_xattrr, copy the files there, and then Squash them. This would work, but it's cumbersome, and i have to hope that I have enough space for the file. A tmpfs won't work because no xattr support, plus i may run out of memory.
Any other ideas?
| Ideas to clear user xattrs from files without get/setfattr |
If macos stat is like FreeBSD's, the flags can be expressed in the format specification with %f for the numeric form or %Sf for the decoded text form like in ls -lo.
See man stat, man chflags and man ls on your system for details.
|
I'm using stat like this:
stat -f "%Sp %p %l %Su %u %Sg %g %z %a %N %Y" /*I need also to tell if the file is hidden or not (MacOS).
The . notation is not enough. MacOS hides more files.
For example, this is what I need:
ls -lO
total 9
drwxrwxr-x 32 root admin sunlnk 1024 Jun 4 22:00 Applications
drwxr-xr-x 66 root wheel sunlnk 2112 Feb 18 23:23 Library
drwxr-xr-x@ 9 root wheel restricted 288 Jan 1 2020 System
drwxr-xr-x 7 root admin sunlnk 224 May 18 08:12 Users
drwxr-xr-x 4 root wheel hidden 128 Jun 7 12:49 Volumes
drwxr-xr-x@ 38 root wheel restricted,hidden 1216 Jan 1 2020 bin
drwxr-xr-x 2 root wheel hidden 64 Jun 6 2020 cores
dr-xr-xr-x 3 root wheel hidden 4602 Jun 1 14:24 dev
lrwxr-xr-x@ 1 root wheel restricted,hidden 11 Jan 1 2020 etc -> private/etcI need to run it as one command for sake of processing speed.
My goal is all from my above stat plus the 5th column of the ls command.
Any hints?
I've noticed that %T prints @ for hidden items. It could however show it also for other reasons. Can this be used or not?
It no stat solution is found, is there a way to merge stat results with the extra ls -lO column on a command line?
| Can stat show if file is hidden? |
Added to /etc/pve/openvz/VMID.conf
MOUNT_OPTS="rw,realtime,acl,user_xattr" Did the thing. Now (for example)
setfacl -m u:sshd:rwx ~/tmp
setfacl -m g:ssh:rwx ~/tmpand then
getfacl ~/tmpshows
# file: root/tmp
# owner: root
# group: root
user::rwx
user:sshd:rwx
group::r-x
group:ssh:rwx
mask::rwx
other::r-xSo, ACL is OK
|
Setting up Samba-4.3.5 as AD domain fileserver in OpenVZ container, running in ProxMox (pve-manager/3.4-6/102d4547 running kernel: 2.6.32-39-pve). Hardware node has enabled acl support for /var/lib/vz. Nevertheless, container has no acl support. So, any setfacl command does nothing.
How enable acl and xattr support in container?
| OpenVZ acl support for Samba |
Perhaps
echo 'chattr +i filename' | at beginning_timestamp
echo 'chattr -i filename' | at ending_timestampWould this work for you?
|
It's possible to set immutable bit for a specified range of days?
I was trying to understand how Veeam11 can change the attribute after a few days for immutable backup
| Set immutable bit for specified time |
The -A and -X options are ambiguous and iit is not clear whether they are included or excluded.It should be relatively simple to test how the options behave.
Create a test file with an ACL, copy it with the various options and combinations of them, and see if the copied file has the ACL. (Remove the target file after each copy.)
I'll spare you the full output, but via testing, I see that neither rsync, or rsync -a copies the ACL; but all of rsync -A, rsync -a -A and rsync -A -a do copy it.
So indeed -A is not included in -a, but -a also doesn't exclude -A in the sense of making it not work if explicitly given. -X works similar.
FWIW, this matches how I would have read the man page, that -a is simply the same as -rlptgoD (with a note on how -AX are not included).I wonder whether they are excluded because they are features added on top the Unix file systemAs for the why -a doesn't include -AX, I suppose we'd need to ask the developers. It's possible that they thought the features in question aren't common enough to warrant that, or that most users would not be aware of how they work, or that trying to read and store ACLs and/or xattrs would lead to errors or other issues in some systems.Is there something about extended attributes and access control lists that make it unwise to include them in an archive backup?That's harder to say, and probably depends on your use-case and what exactly you have there in the xattrs (and ACLs).
|
Rsync describes the -a or --archive mode as being equivalent to the options.-rlptgoD (no -H,-A,-X).
The -A and -X options are ambiguous and iit is not clear whether they are included or excluded.
-A stands for --acls and -X stands for --xattrs and I wonder whether they are excluded because they are features added on top the Unix file system, although you would expect an archive backup to include them.
Is there something about extended attributes and access control lists that make it unwise to include them in an archive backup?
Are they stored separately from the files that use them, in a way that makes them inapplicable to an archived backup?
| Does the rsync "-a" option exclude the "-A" and "-X" option? |
I can think of at least two ways to prevent an owner from deleting a directory.A directory can't be deleted if it isn't empty. So put something in it the owner can't delete.A directory they don't own
a file (owner doesn't matter) that is immutableMount something on the directoryIn the first case, they'd still be able to rename the directory.
But if something is mounted on it (which is what you want anyway), they can't do anything to it. Now if they can unmount what is on it...
|
Is it possible to create a directory that its owner can't delete? Let's say I have directory bar owned by user foo, and I'd like to create a subdirectory bar/baz, also owned by foo, such that:foo can create and remove files and directories in bar/baz as normal
foo can create and remove files in bar as normal
foo can remove most directories in bar as normal
foo (or any other non-superuser) CANNOT remove the directory bar/bazThe reason I'd like to do this is because I'd like to set up bar/baz as a BTRFS subvolume (to exclude it from snapshots), and if foo can remove it and recreate it using mkdir, then it would not be a subvolume anymore.
| A directory that is owned by some non-superuser, but can't be deleted by them |
Use -d, which lists directories like other files instead of listing their contents:
lsattr -d pub |
I have a directory called pub on a Ubuntu 20.04 server, that I wish to protect from deletion, and I found https://askubuntu.com/questions/504151/how-to-prevent-directory-from-being-deleted-by-user so I tried:
$ sudo chattr +i pubGood enough, now I want to check if that attribute has been set:
$ lsattr pub
--------------e----- pub/__pycache__
--------------e----- pub/file1.py
--------------e----- pub/file2.py
--------------e----- pub/file3.py
--------------e----- pub/file4.pySo, I got the contents of the directory listed, but I did not get the directory listed, which is what I wanted.
I mean, if it at least gave me an entry for pub, I would have been fine - but here I get all the children and NOT what I requested for... it is so amazingly stupid.
Turns out, there is lsattr -R switch for "recursive", which I've expected to provide output like above - but when I run it, it simply also descends into __pycache__ directory.
So, how do you lsattr a directory only, so you can see if you achieved the right thing with chattr?
| How to lsattr directory only? |
To answer you question: a move and a delete are pretty similar, I think you need a different strategy.
I would put the directory under version control, not only because it appears to be code.
The advantage of a version control system is that you have file history. you could simply run a scheduled task, say every hour that checks if changes were made, using, say git, and apply the changes to version control.
That way, you can allow the people to move stuff, delete stuff, does not matter what ... it is still in version control and retrieval is only a command away.
The other thing with version control systems, like git, is that you have a backup mechanism integrated. You can pull any changes over to one or more other systems AND when I say changes, it is in fact complete file history ... including any change ever made.
With text files, the overhead in storage in minimal, it only ever stores the changes that were made.
The only thing the others are not allowed to touch is the version control system. If you use git, it will create a .git directory, this will contain all the important information ... you could also use other systems like mercurial.
If you really want to capture all changes as they are made, you could try git watch which can watch a git repository, including all subfolders and files therein, and insert any change into git. Better, even, gitwatch can send the changes as they happen to a git on another server (full backup, full history).
|
I am managing some folders on our server. The server runs:
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="7.6"
I have created a directory in "/srv/" and named it "test". I have added another directory called "archived" inside "test".
I have created project_managers user group and added some users to this group. project_managers have read/write/execute permission for "/srv/test/" recursively.
I want the project_managers to be able to move files from one directory to another but not to be able to delete the files entirely from the server.
For example I want project_managers have permission to move "/srv/test/my_code.py" to "/srv/test/archived/" but do not have permission to delete "/srv/test/my_code.py"
I have done: sudo chattr -R +i /srv/test/
It prevents both deleting and moving files.
Is it possible to make files undeletable but moveable?
| How to make files undeletable but moveable in linux server? |
If for some reason you just want to prevent it from being used, you can just render it inoperable:
chmod a-x /usr/bin/chattrI agree it's not a smart thing to remove the file.
|
I would like to delete chattr, as in /usr/bin/chattr, I am using Linux Mint, do you think other parts of the system would be affected?
| if I delete usr/bin/chattr would other components of the system be affected? |
A tilde suffix marks a backup file for a few text editors, such as Emacs ('~') and Vim ('.ext~').
Some programs hide these files, as most people don't care about them.
The only universal convention for a 'hidden' file is a file with a leading '.', due to a feature-like bug which was widely adopted.
|
I want to be able to check whether a file is hidden or not in Cent OS 6.3. These are often referred to as (dot) files but I can clearly see Cent OS 6.3 handling these by appending a ~(tilde) to the end
EG:
myfile (not hidden)
myfile~ (hidden)
Now, I can tell that a file is "hidden" if it's a dot file, but what is going on with this tilde (~) terminating character - is this particular to Cent OS 6.3? Is this something I can simply check for in the file name (EG: starting with a dot or ending with a tilde) I would appreciate help on this as, I would assume "hidden" is a file attribute rather than a "naming convention" as I wrong?
| Cent OS 6.3 Hidden files in shell |
Hm, maybe you could run xattr -d attribute1 -d attribute2 filename, if xattr supports that? That would mean the documentation is a bit wrong, but getopt-based programs often have that problem.
Let's test that:
I don't have MacOS to test, but I got the original source code of the xattr tool, and removed all functionality from it so that my version compiles on linux and instead prints what it deletes.
Sadly,
./xatrr -d foo -d bar foo
xatrr: [Errno 2] No such file or directory: 'bar'Thus, that's not an option.
Well, then:
for attr in attribute1 attribute2 do; xattr -d ${attr} filename; doneis the best I could offer (without relying on more tools).
|
For example, I have a file with three extended attributes:
com.apple.FinderInfo
com.apple.metadata:_kMDItemUserTags
com.apple.metadata:kMDItemFinderCommentI can delete the first two using
xattr -d com.apple.FinderInfo file.txt
xattr -d com.apple.metadata:_kMDItemUserTags file.txtBut I would prefer to not invoke xattr multiple times, and to use something like this instead:
xattr -d \( com.apple.FinderInfo, com.apple.metadata:_kMDItemUserTags \) file.txtxattr -d com.apple.FinderInfo -d com.apple.metadata:_kMDItemUserTags file.txtIs it possible somehow?
| Delete multiple extended attributes (but not all of them) in one step |
Something like that:
find . -flags -hidden \! -name ".DS_Store" |
I have concealed some folders on my laptop using chflags:
chflags hidden hide-meAnd I don't remember where exaclty these folders are located.
How is it possible to find all of them? (Probably by using find and/or grep.)
| Find all the folders that are concealed using 'chflags' |
getxattr or lgetxattr get the binary capability value in fact.
[root@localhost ~]# strace -e getxattr getfattr -d -m - /bin/tcpm
getxattr("/bin/tcpm", "security.capability", NULL, 0) = 20
getxattr("/bin/tcpm", "security.capability", "\0\0\0\2\0 \0\0\0\0\0\0\0\0\0\0\0\0\0", 256) = 20 |
Background : in ima-evm-utils I found lgetxattr() can't return expected value.I wrote a simple c program to verify it.
#include <sys/types.h>
#include <sys/xattr.h>
#include <stdio.h>
int main(){
char xattr_value[1024];
int size;
size=lgetxattr("/bin/tcpm", "security.capability", xattr_value, sizeof(xattr_value));
printf("caps: %s\n", &xattr_value);
printf("%d\n",size);
size=lgetxattr("/bin/tcpm", "security.selinux", xattr_value, sizeof(xattr_value));
printf("selinux: %s\n", &xattr_value);
printf("%d\n",size);
return 0;
}[root@localhost ~]# ./a.out
caps:
20
selinux: system_u:object_r:bin_t:s0
27[root@localhost ~]# getcap /bin/tcpm
/bin/tcpm cap_net_bind_service,cap_net_admin=ep[root@localhost ~]# getfattr -m - -d /bin/tcpm
getfattr: Removing leading '/' from absolute path names
# file: bin/tcpm
security.capability=0sAQAAAgAUAAAAAAAAAAAAAAAAAAA=
security.selinux="system_u:object_r:bin_t:s0"size is not -1 means lgetxattr() suceess,but xattr_value is not expected value
try to gdb ima-evm-utils: #err = return of lgetxattr()
(gdb) p err
$6 = 20
(gdb) p xattr_value
$7 = "\000\000\000\002\000 ", '\000' <repeats 14 times>, "P\261\037&@&^\a\022\274fOT\031", '\000' <repeats 294 times>...
(gdb) p err
$8 = 27
(gdb) p xattr_value
$9 = "system_u:object_r:bin_t:s0", '\000' <repeats 302 times>...source code of this probelm:
for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++) {
err = lgetxattr(file, *xattrname, xattr_value, sizeof(xattr_value));
if (err < 0) {
log_info("no xattr: %s\n", *xattrname);
continue;
}
if (!find_xattr(list, list_size, *xattrname)) {
log_info("skipping xattr: %s\n", *xattrname);
continue;
}
log_info("name: %s, size: %d\n", *xattrname, err);
log_debug_dump(xattr_value, err);
err = !HMAC_Update(pctx, xattr_value, err);
if (err) {
log_err("HMAC_Update() failed\n");
goto out_ctx_cleanup;
}
} | lgetxattr can't get security.capability |
According to a mailing list question from 2003, Reiserfs doesn't support chattr. Granted that was a long time ago, but given your error above, it seems likely that it still doesn't.
|
I am unable to set or view file attributes using lsattr and chattr commands on Reiser File System. Following result is observed:
chattr +i Temp.txt
chattr: Inappropriate ioctl for device while reading flags on Temp.txtlsattr Temp.txt
lsattr: Inappropriate ioctl for device While reading flags on Temp.txtIs there a way to get file attributes with ReiserFS or how should I access file attributes on ReiserFS?
| Inappropriate ioctl for device while reading flags on <file> |
xdg-open is a desktop-independent tool for configuring the default
applications of a user. Many applications invoke the xdg-open command
internally. Inside a desktop environment (like GNOME, KDE, or Xfce),
xdg-open simply passes the arguments to those desktop environment's
file-opener application (eg. gvfs-open, kde-open, or exo-open). which
means that the associations are left up to the desktop environment.
When no desktop environment is detected (for example when one runs a
standalone window manager like eg. Openbox), xdg-open will use its own
configuration files.
from archwikispecific to your question, you could try this to set the default application associated with the png file:
xdg-mime default <ristretto.desktop> image/pngyou need find out what exactly the desktop file name of Ristretto.
afterwards, you could check it with this:
xdg-mime query default image/png |
I would expect xdg-open command to use the same application that opens when I double-click the file in the default file manager, but this is not always true.
For example my DE is XFCE, my file manager is Thunar and my default picture viewer is Ristretto. However, xdg-open example.png opens the example PNG file in Pinta. Why?
| How does the xdg-open command know which application to use to open a file? |
To register a new URL scheme handler with XDG, first create a Desktop Entry which specifies the x-scheme-handler/... MIME type:
[Desktop Entry]
Type=Application
Name=DDG Scheme Handler
Exec=open-ddg.sh %u
StartupNotify=false
MimeType=x-scheme-handler/ddg;Note that %u passes the URL (e.g. ddg://query%20terms) as a single parameter, according to the Desktop Entry Specification.
Once you have created this Desktop Entry and installed it (i.e. put it in the local or system applications directory for XDG, like ~/.local/share/applications/ or /usr/share/applications/), then you must register the application with the MIME type (assuming you had named your Desktop Entry ddg-opener.desktop):
xdg-mime default ddg-opener.desktop x-scheme-handler/ddgA reference implementation of the ddg-open.sh handler:
#!/usr/bin/env bash# bash and not just sh because we are using some bash-specific syntaxif [[ "$1" == "ddg:"* ]]; then
ref=${1#ddg://}
#ref=$(python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" "$ref") # If you want decoding
xdg-open "https://duckduckgo.com/?q=$ref"
else
xdg-open "$1" # Just open with the default handler
fi |
I would like to register a URL scheme (or protocol) handler for my own custom URL protocol, so that clicking on a link with this custom protocol will execute a command on that URL. Which steps do I need to take to add this handler?
Example: I want to open URLs like ddg://query%20terms in a new DuckDuckGo browser search. If this protocol already exists, I assume that the steps to override a handler don't differ much from the steps to create a new one. Yes, technically, this is just a URL scheme, not a protocol.
| Create a custom URL Protocol Handler |
Look at the content of the xdg-open file, and you will notice that it is a simple shell script. Its main task is identifying the desktop environment in use, which will then be used to delegate the task to a specific tool:KDE delegates to kde-open or kfmclient
Gnome delegates to gvfs-open or gnome-open
Mate delegates to gvfs-open or mate-open
XFCE delegates to exo-open
LXDE delegates to pcmanfm, with fallback to “generic” for most URLs
Enlightenment delegates to enlightenment_open
Everything else is termed “generic”, and the script tries its own luckSo the core message is this: in most situations, one of these delegates will do the actual work, so you should check about how these are configured.
For example, I'm running XFCE, so xdg-open calls exo-open which uses the XFCE settings available through the XFCE settings user interface and stored in ~/.local/share/applications/mimeapps.list.
For details about the config files in use, strace -e file can be useful. And if you are in the “generic” situation and want to see what xdg-open itself does, you can try sh -x `which xdg-open` file.name.
|
According to the man page, xdg-open will open a file using the application the user has configured. But how is that application actually determined? I can see no config files associated with xdg-utils, so where are my settings stored and how can I modify them? Seeing how a simple PNG file opens Internet Explorer using Wine, I need to change these settings.
| How does xdg-open do its work |
AFAIK the choice of action is based on the file's mimetype rather than its extension.
At least on Ubuntu, you should be able to use the query action of xdg-mime to show the default application for a specific mimetype
$ xdg-mime query default image/jpeg
eog.desktopYou can check the mimetype for a particular file using xdg-mime query filetype e.g.
$ xdg-mime query filetype kqDRdnW.jpg
image/jpegor using the file command e.g. file --mime-type <file>
See man xdg-mime for further usage information.
|
Given xdg-open and an extension, is there a way to get the application which xdg-open is set to for that particular extension?
For example given xdg-open and .jpg the result is eog.
| Find the default application for a certain extension |
Check the BROWSER variable in /etc/profile and /etc/environment and eventually in your ~/.bashrc. It is probably set to /usr/bin/xdg-open so you should consider to change it to avoid the recursive call.
|
My problem is that many programs call xdg-open to open websites but on my Manjaro system (based on Arch Linux) this is somehow bound to cups :)
When such a call to xdg-open happens, the CPU usage goes up a lot, without anything happens. I restart because the laptop gets hot very quickly.
~ $ xdg-settings get default-web-browser
cups.desktopWhen I want to change that, I get the following response:
~ $ xdg-settings set default-web-browser firefox.desktop
xdg-settings: $BROWSER is set and can't be changed with xdg-settingsI can go ahead and change the environment variable for the browser and I'm fixed, BUT only for this one terminal. How could I make this change permanent or add it to autostart?
I'm using: i3 4.12, fish shell
| Can't change the xdg-open url-handler to Firefox |
Use mimeopen -d to set the default application:
mimeopen -d image.pngsample output:
Please choose a default application for files of type image/png
1) ImageMagick (color depth=q16) (display-im6.q16)
2) GNU Image Manipulation Program (gimp)
3) Feh (feh)Select your default application , next time you will be able to use:
mimeopen image.pngor:
xdg-open image.png |
I just can't find the command to display a *.png image! I tried xdg-open command but it failed:
[student@seqpapl1 Images]$ xdg-open adapter_content.png
xdg-open: no method available for opening 'adapter_content.png'I am currently running ubuntu linux on the server.
| How to open an .png type image in Linux terminal? |
This sounds like your package database is screwed up. First I'd identify all the versions of xdg-open that you have on your system. The type should always be used for doing this task, never rely on which or whereis.
Example
Identify all xdg-open's.
$ type -a xdg-open
xdg-open is /usr/bin/xdg-openFind out which packages they're a part of.
$ dpkg -S /usr/bin/xdg-open
xdg-utils: /usr/bin/xdg-openYou'll want to either repeat the above dpkg -S .. for each match returned by type -a or use this dpkg -S .. search instead.
$ dpkg -S xdg-open
xdg-utils: /usr/bin/xdg-open
xdg-utils: /usr/share/man/man1/xdg-open.1.gzI would do each, one at a time.
Reinstalling xdg-utils
If you'd like to refresh this package's installation do this:
$ sudo apt-get --reinstall xdg-utils |
$ xdg-open
The program 'xdg-open' is currently not installed. You can install it by typing:
sudo apt-get install xdg-utils$ sudo apt-get install xdg-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
xdg-utils is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 89 not upgraded.$ whereis xdg-open
xdg-open: /usr/bin/xdg-open /usr/bin/X11/xdg-open /usr/share/man/man1/xdg-open.1.gz$ which xdg-open$ xdg-open
The program 'xdg-open' is currently not installed. You can install it by typing:
sudo apt-get install xdg-utilsNo, I didn't mean "recursion".
I'm on Linux Mint 15 MATE, but instead of MATE I'm using the i3 window manager.
Edit taking @slm's advice
$ type -a xdg-open
type: xdg-open not foundBut it's in /usr/bin/xdg-open. I checked.
$ dpkg -S /usr/bin/xdg-open
xdg-utils: /usr/bin/xdg-openThe next one was even more interesting.
$ dpkg -S xdg-open
git-annex: /usr/share/doc/git-annex/html/bugs/Fix_for_opening_a_browser_on_a_mac___40__or_xdg-open_on_linux__47__bsd__63____41__.html
xdg-utils: /usr/bin/xdg-open
xdg-utils: /usr/share/man/man1/xdg-open.1.gzThe bug-fix is just a mail archive of a patch for an OSX problem. Anyway, I guess I could try using the full path:
$ /usr/bin/xdg-open
/usr/bin/xdg-open: No such file or directory | xdg-open is installed yet also is not installed |
This answer over on askubuntu.com covers many different ways to solve the problem. The one that was the closes to doing what I wanted was the gtk-launch command:
gtk-launch org.kde.kwrite.desktopOne thing I like about gtk-launch is that it can find the appropriate desktop file even if you only give it the name.
|
I'm trying to write a script that launches the default application for a given mime type. For example, I would like to say my-script text/plain and have it open KWrite for me.
What I know is that you can use xdg-mime to query what is the default application for a given mime type
$ xdg-mime query default text/plain
org.kde.kwrite.desktopHowever, I don't know what is the command I can use to launch KWrite given org.kde.kwrite.desktop. How can I do that? Is having the name of the desktop file enough or do I also need to find out where it is stored (/usr/share/applications, .local/share/applications, etc)?By the way, I don't think I can solve my original problem using xdg-open because XDG open expects to receive a filename or URL as a parameter and I want to be able to launch my applications without needing to pass a filename. For example, I want to be able to open the text editor on a blank file buffer or open my web browser on its home page.
| How can I run a .desktop file? |
You could attempt to manually set it via the command line using mimeopen.
Example
$ mimeopen -d ~/test.pdfPlease choose a default application for files of type application/pdf 1) E-book Viewer (calibre-ebook-viewer)
2) Document Viewer (evince)
3) Xournal (xournal)
4) GNU Image Manipulation Program (gimp)
5) Xpdf PDF Viewer (xpdf)
6) Print Preview (evince-previewer)
7) Inkscape (inkscape)
8) calibre (calibre-gui)
9) Other...use application #2
Opening "/home/saml/Downloads/test.pdf" with Document Viewer (application/pdf)Which results in my PDF file, test.pdf opening up in Evince. From this point on Evince is the default when I use xdg-open.
ReferencesHow to get a list of applications associated with a file using command line
Is there an "open with" command for the command line? |
I run Debian Jessie without a desktop environment (I use the tiling window manager i3) and like to use xdg-open to quickly open files using a preferred application. I have an ongoing problem setting the preferred app for PDF files though. This is my problem in a nutshell:
$ xdg-mime query filetype ~/Downloads/document.pdf
application/pdf$ xdg-mime query default application/pdf
/usr/share/applications/qpdfview.desktop$ xdg-open ~/Downloads/document.pdf
[opens gimp!]Any ideas would be hugely appreciated - this has been plaguing me for about a year. The only way I've ever managed to (temporarily) fix it is by directly editing the mimeinfo.cache and removing the reference to gimp from the application/pdf record.
And yes, /usr/share/applications/qpdfview.desktop exists and contains the correct location of the qpdfview binary. (Indeed, this .desktop file is used when I hand-edit mimeinfo.cache.)
| xdg-open opens a different application to the one specified by xdg-mime query |
Install perl-file-mimeinfo and configure it that way. See the Arch Wiki article on xdg-utils:If no desktop environment is detected, MIME type detection falls back
to using file which—ironically—does not implement the XDG standard. If
you want xdg-open to use XDG MIME Applications without a desktop
environment, you will need to install perl-file-mimeinfo or switch to
one of the resource openers that support XDG MIME Applications. |
I have tried to set my default browser for opening URLs to Chromium using:
xdg-settings set default-web-browser chromium.desktop(yes I checked out whether /usr/share/applications/chromium.desktop existed first before running this command and it does exist) and it returns:
xdg-settings: unknown desktop environmenti3 isn't a desktop environment so I can definitely understand this error, but is there a way around it? The reason I want xdg-open to open URLs using Chromium is that running notebook() from the SageMath command-line attempts to open the notebook in one's default web browser (using xdg-open). Presently this obviously fails (no browser, or application for that matter, is opened to the URL), so I'd like to get this to work which I believe will require me to get xdg-open to open URLs in Chromium.
| How to set the default web browser used to open URLs under i3? |
@user310685 got it close - but DEFINITELY WRONG. That fix "works" only when xdg-open is NOT given "naked" file paths (i.e. with no leading "file://" URI scheme and double-slash) or file-schemed URI's (i.e. with the leading "file://"). Those two types of argument should have xdg-open defer to pcmanfm, but they won't.
The actual error is not a mistake in the STDERR redirection. Rather, it's that the script writer confused the test "and" operator and the shell's process list "and" connector. The one (erroneously) used is "-a"; the correct one is "&&".
As reference, I've reproduced the original script line, my fix for that line, and the "horror of horrors" suggestion by @user310685:
#ORIG# if pcmanfm --help >/dev/null 2>&1 -a is_file_url_or_path "$1"; then
#FIXED# if pcmanfm --help >/dev/null 2>&1 && is_file_url_or_path "$1"; then
#HORROR# if pcmanfm --help >/dev/null 2>$1 -a is_file_url_or_path "$1"; thenThe intention of the if ..; then is given in the script line just above it:
# pcmanfm only knows how to handle file:// urls and filepaths, it seems.With this comment in mind, the way to understand the problematic if .. then line is:Test if pcmanfm is runnable (by having it report it's own help, and discarding any STDOUT or STDERR)
AND, run the script-function is_file_url_or_path() to then see if the "$1" argument is acceptable to pcmanfm (as per the code comment noted above)If both these conditions hold, then the script flows into a short block that:Calls the script-function file_url_to_path() to strip off any leading "file://" part (as local var file)
If the result is NOT an absolute path (i.e. doesn't start with "/"), then prepend the CWD to the value of file
Execute pcmanfm "$file"Why the Original Script Fails:
As noted above, the script is (erroneously) using "-a" as a "process list and operator." What actually happens is that the shell runs the command (after STDOUT and STDERR redirections are "pulled out" of the command, which are allowed to be anywhere in the command word sequence after the first word):
pcmanfm --help -a is_file_url_or_path "$1"This always succeeds (unless pcmanfm isn't executable on the PATH). All the extra stuff on the command line (-a ..) is ignored by pcmanfm running it's --help mode. Thus, the "process as a file or file-URL" code block is always executed. When given an URL (with a scheme part), the file_url_to_path() script-function only removes a leading "file://", truncates any trailing "#..." fragment, and also URI-decodes the argument (i.e. "%XX" are converted to ASCII). NOTE: Unless the argument starts with "file:///", nothing is done.
For example, the OP's URL "https://www.google.com" is unchanged by file_url_to_path() since it does not begin with "file:///". BUT later code then considers this argument to be a "relative path" since it clearly doesn't start with "/". Thus, it prepends the CWD as described and then pcmanfm is almost certainly NOT going to find that munged value as an extant path to display. Instead, it shows an error pop-up, as in the OP's question.
The Fix:
Simple enough: use the correct syntax for a process chain AND-operator: "&&" as shown in the #FIXED# line, above.
The HORROR of @user310685's Suggestion:
What @user310685 proposes does fix one problem, sort of. What happens is that the shell dutifully does variable expansion and then attempts to execute something like:
pcmanfm --help >/dev/null 2>https://www.google.com -a is_file_url_or_path https://www.google.comThis, is almost certainly going to produce a shell redirection error (unless the CWD has a folder (in the right place) named "https:" - which it could). That redirection error spits a message to STDERR, and then the shell moves on. Since this error occured within an if .. else .. fi block, the shell takes the else .. fi part, which is what @user310685 wants. Thus, the problem is solved...
BUT AT WHAT COST???
There are two problems with this not-quite-right fix:When actually given a path or a file-schemed URL, the wrong code path is executed (the else .. fi part). This is because the intended process chain is really only a single process that (almost) always generates a shell redirection error which is taken as the if .. ; condition as being "false." This not soooo bad, since that else .. fi block merely defers work to another script-function called open_generic() which is designed to handle paths and file-URL's (but not using pcmanfm to do the work, rather some other complex code-path that I didn't analyze but I presume does a fair job). But WAIT! The HORROR...
Look back up at the pcmanfm --help ... expanded script line that the shell attempts. Note the redirection of STDERR. Consider what happens if this is done with a legitimate path, like "/home/user/precious". OMG The attept to probe if pcmanfm is available and then to test if the argument is a file just OVERWROTE THE FILE!!! Bye-bye precious... |
I decided to try lxdm (was using fluxbox and xfce), and discovered that for many programs the url handler was failing, producing this error message;Quite strange as you can see, it's prepending the user directory to the url.
The example here is from telegram, but it happens in discord, as well as when executing from the command line; xdg-open https://www.google.com produces a similar error.
xdg-settings get default-web-browser output's firefox.desktop which works as a link in both xfce and lxdm.
More information; I ran bash -x on it and...
$ bash -x /usr/bin/xdg-open http://www.google.com
+ check_common_commands http://www.google.com
+ '[' 1 -gt 0 ']'
+ parm=http://www.google.com
+ shift
+ case "$parm" in
+ '[' 0 -gt 0 ']'
+ '[' -z '' ']'
+ unset XDG_UTILS_DEBUG_LEVEL
+ '[' 0 -lt 1 ']'
+ xdg_redirect_output=' > /dev/null 2> /dev/null'
+ '[' xhttp://www.google.com '!=' x ']'
+ url=
+ '[' 1 -gt 0 ']'
+ parm=http://www.google.com
+ shift
+ case "$parm" in
+ '[' -n '' ']'
+ url=http://www.google.com
+ '[' 0 -gt 0 ']'
+ '[' -z http://www.google.com ']'
+ detectDE
+ unset GREP_OPTIONS
+ '[' -n LXDE ']'
+ case "${XDG_CURRENT_DESKTOP}" in
+ DE=lxde
+ '[' xlxde = x ']'
+ '[' xlxde = x ']'
+ '[' xlxde = x ']'
+ '[' xlxde = xgnome ']'
+ '[' -f /run/user/1000/flatpak-info ']'
+ '[' xlxde = x ']'
+ DEBUG 2 'Selected DE lxde'
+ '[' -z '' ']'
+ return 0
+ case "${BROWSER}" in
+ case "$DE" in
+ open_lxde http://www.google.com
+ pcmanfm --help -a is_file_url_or_path http://www.google.com
++ file_url_to_path http://www.google.com
++ local file=http://www.google.com
++ echo http://www.google.com
++ grep -q '^file:///'
++ echo http://www.google.com
+ local file=http://www.google.com
+ echo http://www.google.com
+ grep -q '^/'
++ pwd
+ file=/home/nesmerrill/.local/share/applications/http://www.google.com
+ pcmanfm /home/nesmerrill/.local/share/applications/http://www.google.com
+ '[' 0 -eq 0 ']'
+ exit_success
+ '[' 0 -gt 0 ']'
+ exit 0The important part seems to be pcmanfm --help -a is_file_url_or_path http://www.google.com but, that command if that's how it was used, doesn't seem to do much of anything?
$ pcmanfm --help -a is_file_url_or_path http://www.google.com
Usage:
pcmanfm [OPTION…] [FILE1, FILE2,...] Help Options:
-h, --help Show help options
--help-all Show all help options
--help-gtk Show GTK+ OptionsApplication Options:
-p, --profile=PROFILE Name of configuration profile
-d, --daemon-mode Run PCManFM as a daemon
--no-desktop No function. Just to be compatible with nautilus
--desktop Launch desktop manager
--desktop-off Turn off desktop manager if it's running
--desktop-pref Open desktop preference dialog
--one-screen Use --desktop option only for one screen
-w, --set-wallpaper=FILE Set desktop wallpaper from image FILE
--wallpaper-mode=MODE Set mode of desktop wallpaper. MODE=(color|stretch|fit|crop|center|tile|screen)
--show-pref=N Open Preferences dialog on the page N
-n, --new-win Open new window
-f, --find-files Open a Find Files window
--role=ROLE Window role for usage by window manager
--display=DISPLAY X display to use | xdg-open on debian 9 fails to open browser |
mimeopen treats unknown files as text/plain or application/octet-stream.
To set default application, run mimeopen with -d option. Since I could not find option to specify mimetype, you need to create dummy files at first.
touch text.txt # for text/plain
mimeopen -d text.txt # and choose your favorite appecho -e \\0 > data.dat # for application/octet-stream
mimeopen -d -M data.dator edit "~/.config/mimeapps.list".
[Default Applications]
text/plain=featherpad.desktop;
application/octet-stream=firefox.desktop;mimeopen, which is shiped with File-MimeInfo, tries to find applications with parent mimytypes. For example, if the filetype starts with "text/", it has "text/plain" as parent. And all filetype inherits "application/octet-stream".
On mimeopen in my environment, the most "suitable" app for octet-stream is VLC Player and for text/plain, it is Calibre's E-book Viewer. That's why some files are opened with these apps.
|
On my Lubuntu (18.10), xdg-open launches VLC Player when the file is not associated to any applications.
$ xdg-mime query filetype jquery.js
application/javascript
$ xdg-mime query default application/javascript # no output
$ xdg-open jquery.js
Error: no "view" mailcap rules found for type "application/javascript"
Opening "/tmp/jquery.js" with VLC media player (application/javascript)On some files, it launches Calibre's E-book viewer (.rb for example).EDIT I digged into xdg-open and found it executes following commands:Check filetype with xdg-mime query filename "$file" and xdg-mime query default $filetype
run-mailcap --action=view "$file"
mimeopen -L -n "$file"The problem lies in mimeopen.
Then how can I change mimeopen to open any unknown files with featherpad, or specific app? In other words, I'd like to set default fallback application if mimeopen can not find any suitable apps.
| How can I set default application for unknown file on xdg-open / mimeopen? |
xdg-open is the safest bet. Not everyone will necessarily have gnome or gvfs installed. xdg-open, on the other hand, is not tied to any desktop environment or toolkit.
|
I have a Java program that runs on Linux, and from within the program, I want to open files (e.g. PDF files) with the system's native viewer. There are various programs available for this purpose: gnome-open, gvfs-open, xdg-open, ...
Which one(s) should I use to cover as many Linux distributions as possible?
| What program to use to open files? (gnome-open, gvfs-open, xdg-open, etc.) |
I cannot say anything about the specification but as far as just the result matters I (not being familiar with the quoting in such files, though) would expect this to work:
Exec=bash -c 'echo seamonkey openURL"($1)"' seamonkey-wrapper %u% |
Older versions of Netscape and Mozilla (for X11) supported the so-called remote protocol: it was possible to open a URL or start composing an e-mail whenever a Netscape/Mozilla window (not necessarily from a local process) was open on the current DISPLAY.
The "remote" feature worked either way: either from a remote client to a local browser, or vice versa, or even from a remote host1 to a remote host2, provided both could connect to the local DISPLAY.
Here's the documentation for:Netscape 4.x
Mozilla SuiteRudimentary support for remote requests has been preserved in SeaMonkey, too, so even nowadays it supports arguments like openURL(%url%,new-tab) and openURL(%url%,new-window)
Now, I want to create a custom *desktop file which would launch SeaMonkey with exactly those arguments.
The problem is, in this form:
[Desktop Entry]
Exec=seamonkey %u%u expansion works, while in this one:
[Desktop Entry]
Exec=seamonkey -remote openURL(%u)it doesn't: %u gets expanded only if it's surrounded with spaces.
The desktop entry specification doesn't mention this, so this is both an undocumented and unexpected behaviour.
Can you suggest any workaround?
| Opening a URL with xdg-open using Mozilla Remote Protocol |
This is a known bug: https://bugs.kde.org/show_bug.cgi?id=343468
You can use a workaround as described in the #3
sudo sed -i 's:macroEnabled:macroenabled:g' /usr/share/mime/subclasses
|
Whenever I open something with xdg-open in my new OpenSUSE 13.2 install, I am spammed by a sequence of warnings like
$ xdg-open ./flask.wsgi
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-excel.sheet.binary.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-excel.addin.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-excel.sheet.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-powerpoint.presentation.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-word.template.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-excel.template.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-powerpoint.template.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-word.document.macroEnabled.12"
kioclient(10634) KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-powerpoint.slide.macroEnabled.12" This occurs regardless of what file/type I'm opening with xdg-open. This is a big nuisance because in some of my programs these warnings get rendered to the screen. The error never occured on my Fedora KDE setup. How can I fix these warnings? What is missing?
| kioclient KMimeTypeRepository::parents: "/usr/share/mime/subclasses" refers to unknown mimetype "application/vnd.ms-excel..." |
grep -ri notepad ~/.local/share/applicationsAre you sure that this gives 0 results? Here on my ArchLinux I have few files with names starting with wine-extension that register Notepad. I suggest You removing them.
Also, for future, to disable registering wine apps You can run winecfg and perform this:Go to the Libraries tab and type winemenubuilder.exe into the "New overrides" box (it is not in the dropdown list). Click add, then select it from the "Existing overrides" box. Click "Edit" and select "Disable" from the list, then click "Apply". |
I am using Arch Linux. Each time I download a TeX file, Firefox suggest me to open it with notepad (which is installed through wine). Why?
$ xdg-mime query filetype Random-file.tex
text/x-tex
$ xdg-mime query default text/x-tex(nothing appears with the second command)
$ xdg-open Random-file.tex
Opening "Random-file.tex" with notepad (text/x-tex)
wine: invalid directory "/home/janus/.wine" in WINEPREFIX: not an absolute pathAnd it opens Firefox (why?), which ask me to either download the file or to open it with notepad.
I do not want to have any app associated to x-tex. I use to download them and open in a console with VIM. I just do not understand why notepad is an option.
Nor ~/.local/share/applications/mimeapps.list nor /etc/mime.types have the word notepad on it.
I am using Mozilla Firefox 40.0.3
| Firefox tries to open TeX files with wined notepad |
The question remains: where did xdg-open get the idea that Mendeley should
be the default PDF viewer from?This is an eminently reasonable question.
Here's a somewhat long answer in three parts.
Option 1: read the documentation
For example, the FreeDesktop standard
on mimetype associations has this to say:Association between MIME types and applications
Users, system administrators, application vendors and distributions can
change associations between applications and mimetypes by writing into a
file called mimeapps.list.
The lookup order for this file is as follows:
$XDG_CONFIG_HOME/$desktop-mimeapps.list user overrides, desktop-specific (for advanced users)
$XDG_CONFIG_HOME/mimeapps.list user overrides (recommended location for user configuration GUIs)
$XDG_CONFIG_DIRS/$desktop-mimeapps.list sysadmin and ISV overrides, desktop-specific
$XDG_CONFIG_DIRS/mimeapps.list sysadmin and ISV overrides
$XDG_DATA_HOME/applications/$desktop-mimeapps.list for completeness, deprecated, desktop-specific
$XDG_DATA_HOME/applications/mimeapps.list for compatibility, deprecated
$XDG_DATA_DIRS/applications/$desktop-mimeapps.list distribution-provided defaults, desktop-specific
$XDG_DATA_DIRS/applications/mimeapps.list distribution-provided defaultsIn this table, $desktop is one of the names of the current desktop,
lowercase (for instance, kde, gnome, xfce, etc.)Note that if the environment variables such as XDG_CONFIG_HOME and XDG_DATA_HOME are not set, they will revert to their default values.$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.This illustrates one of the trickiest aspects of mimetype associations:
they can be set in many different locations,
and those settings might be overridden in a different location.
However, ~/.config/mimeapps.list is the one that we should use to set our own associations.
This also matches the documentation for the GNOME desktop.To override the system defaults for individual users, you need to create a
~/.config/mimeapps.list file with a list of MIME types for which you want
to override the default registered application.There's also this helpful tidbit:You can use the gio mime command to verify that the default registered
application has been set correctly:
$ gio mime text/html
Default application for “text/html”: myapplication1.desktop
Registered applications:
myapplication1.desktop
epiphany.desktop
Recommended applications:
myapplication1.desktop
epiphany.desktopThe cross-platform command to check mimetype associations is:
xdg-mime query default application/pdfFor GNOME, the command is:
gio mime application/pdfFor KDE Plasma the command is:
ktraderclient5 --mimetype application/pdfWhen I look at my ~/.config/mimeapps.list file,
it looks something like this:
[Added Associations]
application/epub+zip=calibre-ebook-viewer.desktop;org.gnome.FileRoller.desktop;
<snip>
application/pdf=evince.desktop;qpdfview.desktop;okularApplication_pdf.desktop;<snip>
<snip>
[Default Applications]
application/epub+zip=calibre-ebook-viewer.desktop
<snip>
application/pdf=evince.desktop;You can see there only one entry for application/pdf under [Default Applications];
so evince.desktop is the default handler for PDF files.
I don't have Mendeley installed, but one way to make it the default PDF handler
is to put its desktop file here instead of evince.desktop.
Notice we're trusting the documentation here that ~/.config/mimeapps.list
is the correct file; we don't actually know that for sure.
We'll come back to this in part 3.
Option 2: read the source code.
xdg-open is a shell script that behaves differently
depending on the value of $XDG_CURRENT_DESKTOP.
You can see how this works here:
if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
case "${XDG_CURRENT_DESKTOP}" in
# only recently added to menu-spec, pre-spec X- still in use
Cinnamon|X-Cinnamon)
DE=cinnamon;
;;
ENLIGHTENMENT)
DE=enlightenment;
;;
# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
GNOME*)
DE=gnome;
;;
KDE)
DE=kde;
;;Since you are using i3,
the DE variable will be set to generic and the script will call
its open_generic() function,
which in turn will call either run-mailcap or mimeopen
depending on what is installed.
Note that you can get some extra information
by setting the XDG_UTILS_DEBUG_LEVEL, e.g.
XDG_UTILS_DEBUG_LEVEL=4 xdg-open ~/path/to/example.pdfHowever, the debug information is not that informative for our purposes.
Option 3: trace the opened files.
From the previous investigations,
we know that mimetype associations are stored in files somewhere on the hard drive,
not e.g. as environment variables or dconf settings.
This means we don't have to rely on documentation,
we can use strace to determine what files the xdg-open command actually opens.
For the application/pdf mimetype, we can use this:
strace -f -e trace=open,openat,creat -o strace_log.txt xdg-open /path/to/example.pdfThe -f is to trace child processes since xdg-open doesn't do everything by itself.
The -e trace=open,openat,creat is to trace just the syscalls open, openat, and creat.
These are from the man page from man 2 open or online.
The -o strace_log.txt is to save to a log file to inspect later.
The output is somewhat voluminous,
but we can ignore the lines that say ENOENT (No such file or directory)
since these files do not exist.
You can also use other commands such as xdg-mime or gio mime.
I found that gio mime read these files in my home directory:~/.local/share//mime/mime.cache
~/.config/mimeapps.list
~/.local/share/applications
~/.local/share/applications/mimeapps.list
~/.local/share/applications/defaults.list
~/.local/share/applications/mimeinfo.cacheIt also read these system-level files:/usr/share/mime/mime.cache
/usr/share/applications/defaults.list
/usr/share/applications/mimeinfo.cache
/var/lib/snapd/desktop/applications
/var/lib/snapd/desktop/applications/mimeinfo.cacheTo look for application/pdf associations, this should do the trick:
grep 'application/pdf' ~/.local/share//mime/mime.cache ~/.config/mimeapps.list ~/.local/share/applications ~/.local/share/applications/mimeapps.list ~/.local/share/applications/defaults.list ~/.local/share/applications/mimeinfo.cache /usr/share/mime/mime.cache /usr/share/applications/defaults.list /usr/share/applications/mimeinfo.cache /var/lib/snapd/desktop/applications /var/lib/snapd/desktop/applications/mimeinfo.cache | lessFrom here you can see where Mendeley's desktop file is getting added.I have some applications (Calibre, texdoc) open PDFs with Mendeley. Opening
PDFs from Thunar, Thunderbird, Firefox etc. opens evince, the expected
default.Firefox and Thunderbird have their own default application settings.
I believe texdoc relies on xdg-open.
I'm not sure about Thunar,
but I doubt it is relying on xdg-open.
So ultimately this is probably due to:xdg-open having different fallbacks than other applications on i3; andMendeley's installer adding mimetype associations in some files but not others.Addendum: xdg-open should not use the mimeinfo.cache file on i3,
but if you need to regenerate it, this is the command to use:
update-desktop-database ~/.local/share/applicationsand here is the documentation:Caching MIME Types
To make parsing of all the desktop files less costly, a
update-desktop-database program is provided that will generate a cache
file. The concept is identical to that of the 'update-mime-database' program
in that it lets applications avoid reading in (potentially) hundreds of
files. It will need to be run after every desktop file is installed. One
cache file is created for every directory in $XDG_DATA_DIRS/applications/,
and will create a file called $XDG_DATA_DIRS/applications/mimeinfo.cache.https://specifications.freedesktop.org/desktop-entry-spec/0.9.5/ar01s07.html
Related:https://askubuntu.com/questions/939027/pdf-book-opens-in-mendeley-when-openned-from-calibrehttps://askubuntu.com/questions/992582/how-do-mimeinfo-cache-files-relate-to-mimeapps-listHow to make xdg-open follow mailcap settings in Debianxdg-open opens a different application to the one specified by xdg-mime query |
Similar to this question, I have some applications (Calibre, texdoc) open PDFs with Mendeley. Opening PDFs from Thunar, Thunderbird, Firefox etc. opens evince, the expected default.
It seems that those applications use xdg-open since:
$ xdg-mime query default application/pdf
mendeleydesktop.desktopI tried to find where this comes from but was unsuccessful; I fixed it with
xdg-mime default evince.desktop application/pdfThe question remains: where did xdg-open get the idea that Mendeley should be the default PDF viewer from?
I'm using Ubuntu 16.04 with i3 4.11. xdg-open is at version 1.1.0 rc3.
| Why does xdg-open use Mendeley as default for PDFs? |
I guess you have bash-completion installed, which automatically loads the completion it ships for the op command when you try to complete a command line starting with your op alias.
You can avoid this by:Choosing a different alias (and looking at the files in /usr/share/bash-completion/completions/ to make sure you pick a safe name); orAdding complete -o default -o bashdefault op to your ~/.bashrc to instruct bash-completion not to use the shipped completion (see "How can I override a completion shipped by bash-completion?" in the FAQ at the GitHub repository linked above).
Of course, if you are defining an alias to a command for which a completion file exists on your system, you may use the completion function defined there instead of resetting the completion to its default behavior. Note, though, that this would probably require you to explicitly load the completion function. The resulting .bashrc snippet could be:
alias your_alias=aliased_command
_completion_loader aliased_command
complete -F completion_function your_alias |
I've set an alias to xdg-open adding alias op="xdg-open" to my ~/.bashrc file.
The command op file.pdf works, but I'm not able to autocomplete when typing, for example, op fi and hitting TAB.
This is kind of annoying as the point of setting the alias is to save time. How can I fix this?
| xdg-open autocomplete not working when calling it with alias |
If you are using an LXDE desktop environment, xdg-open opens file:// URLS with the pcmanfm program. It strips the file:// part of the URL and calls pcmanfm with the remaining part, since pcmanfm supports only normal paths as arguments, not URLs.
xdg-open does not do any other replacements, so %20 is not translated into a space. This is a bug (feel free to open a bug report for this in Debian).
A fix is described below.
For other desktop environments, the open programs support correctly file:// URLs.Workaround:
Unset some environment variables, so that xdg-open uses the generic open handler which supports all needed replacements:
XDG_CURRENT_DESKTOP= DESKTOP_SESSION= xdg-open "/home/sashoalm/Has Spaces.txt"Bugfix:
Copy the xdg-open script to /usr/local/bin (so that it is not overwritten by upgrading your system) and add the line
file="$(printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")"to the xdg-open script above the # handle relative paths comment line.
Bugfix 2:
Or simply replace replace detectDE() with:
detectDE()
{
DE=gnome
} |
I noticed that xdg-open doesn't handle percent encoded urls. For example, these lines will succeed (provided the files exist):
xdg-open "/home/sashoalm/Has Spaces.txt"
xdg-open file:///home/sashoalm/NoSpaces.txtBut this one will fail:
xdg-open file:///home/sashoalm/Has%20Spaces.txtEdit: This is my version of xdg-utils
sashoalm@aspire:~$ apt-cache policy xdg-utils
xdg-utils:
Installed: 1.1.0~rc1+git20111210-6+deb7u1
Candidate: 1.1.0~rc1+git20111210-6+deb7u1
Version table:
*** 1.1.0~rc1+git20111210-6+deb7u1 0
500 http://ftp.bg.debian.org/debian/ wheezy/main amd64 Packages
100 /var/lib/dpkg/statusEdit 2: This is the trace:
sashoalm@aspire:~$ bash -x xdg-open file:///home/sashoalm/Has%20Spaces.txt
+ check_common_commands file:///home/sashoalm/Has%20Spaces.txt
+ '[' 1 -gt 0 ']'
+ parm=file:///home/sashoalm/Has%20Spaces.txt
+ shift
+ case "$parm" in
+ '[' 0 -gt 0 ']'
+ '[' -z '' ']'
+ unset XDG_UTILS_DEBUG_LEVEL
+ '[' 0 -lt 1 ']'
+ xdg_redirect_output=' > /dev/null 2> /dev/null'
+ '[' xfile:///home/sashoalm/Has%20Spaces.txt '!=' x ']'
+ url=
+ '[' 1 -gt 0 ']'
+ parm=file:///home/sashoalm/Has%20Spaces.txt
+ shift
+ case "$parm" in
+ '[' -n '' ']'
+ url=file:///home/sashoalm/Has%20Spaces.txt
+ '[' 0 -gt 0 ']'
+ '[' -z file:///home/sashoalm/Has%20Spaces.txt ']'
+ detectDE
+ unset GREP_OPTIONS
+ '[' -n LXDE ']'
+ case "${XDG_CURRENT_DESKTOP}" in
+ DE=lxde
+ '[' xlxde = x ']'
+ '[' xlxde = x ']'
+ '[' xlxde = x ']'
+ '[' xlxde = xgnome ']'
+ '[' xlxde = x ']'
+ DEBUG 2 'Selected DE lxde'
+ '[' -z '' ']'
+ return 0
+ '[' x = x ']'
+ BROWSER=www-browser:links2:elinks:links:lynx:w3m
+ '[' -n :0 ']'
+ BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:www-browser:links2:elinks:links:lynx:w3m
+ case "$DE" in
+ open_lxde file:///home/sashoalm/Has%20Spaces.txt
+ echo file:///home/sashoalm/Has%20Spaces.txt
+ grep -q '^file://'
++ echo file:///home/sashoalm/Has%20Spaces.txt
++ sed 's%^file://%%'
+ local file=/home/sashoalm/Has%20Spaces.txt
+ echo /home/sashoalm/Has%20Spaces.txt
+ grep -q '^/'
+ pcmanfm /home/sashoalm/Has%20Spaces.txt
+ '[' 0 -eq 0 ']'
+ exit_success
+ '[' 0 -gt 0 ']'
+ exit 0 | xdg-open doesn't handle percent encoded "file:///" urls with LXDE |
The shared-mime-info repository
already specifies the application/pgp-keys mimetype.
You can see it here:
<mime-type type="application/pgp-keys">
<comment>PGP keys</comment>
<acronym>PGP</acronym>
<expanded-acronym>Pretty Good Privacy</expanded-acronym>
<sub-class-of type="text/plain"/>
<generic-icon name="text-x-generic"/>
<magic priority="50">
<match type="string" value="-----BEGIN PGP PUBLIC KEY BLOCK-----" offset="0"/>
<match type="string" value="-----BEGIN PGP PRIVATE KEY BLOCK-----" offset="0"/>
<match type="big16" value="0x9501" offset="0"/>
<match type="big16" value="0x9500" offset="0"/>
<match type="big16" value="0x9900" offset="0"/>
<match type="big16" value="0x9901" offset="0"/>
</magic>
<glob pattern="*.skr"/>
<glob pattern="*.pkr"/>
<glob pattern="*.asc" weight="10"/>
<glob pattern="*.pgp"/>
<glob pattern="*.gpg"/>
<glob pattern="*.key"/>
</mime-type>https://gitlab.freedesktop.org/xdg/shared-mime-info/-/blob/6bf9e4ff0fb7eff11a02bd937045bf5dc291841a/data/freedesktop.org.xml.in#L282
or here on your own machine:
/usr/share/mime/packages/freedesktop.org.xml
However, it does not use the *.pub glob pattern,
probably to avoid conflicts with MS Publisher format.
One workaround is just to rename the files as e.g. *.asc files.
But let's continue on, assuming that renaming the files is not an option.
Here is the mimeinfo file we need
(note that it must be named pgp-keys.xml):
$ cat pgp-keys.xml
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/pgp-keys">
<comment>PGP keys</comment>
<acronym>PGP</acronym>
<expanded-acronym>Pretty Good Privacy</expanded-acronym>
<sub-class-of type="text/plain"/>
<generic-icon name="text-x-generic"/>
<magic priority="10">
<match value="-----BEGIN PGP PUBLIC KEY BLOCK-----" type="string" offset="0"/>
</magic>
<glob weight="10" pattern="*.pub"/>
</mime-type>
</mime-info>The advantage of the "magic" part
is that it will look at the beginning of the file for this string,
then determine the mimetype based on whether or not it matches.
This means that files with mimetype application/vnd.ms-publisher
can still have the .pub file extension
and live in relative harmony
alongside public keys that also have the .pub file extension.
To achieve this, we must install the mimeinfo file.
To install it for a single user:
xdg-mime install --mode user pgp-keys.xml
update-mime-database ~/.local/share/mimeTo install it system-wide:
sudo xdg-mime install --mode system pgp-keys.xml
sudo /usr/bin/update-mime-database /usr/share/mimeI've tested the outcome with an example public key from here:
https://www.intel.com/content/www/us/en/security-center/pgp-public-key.html
and an example MS Publisher file from here:
https://github.com/apache/tika/blob/0bf11aec86079b8f1ae2f1ea680910ba79665c4f/tika-parsers/src/test/resources/test-documents/testPUBLISHER.pub
You can try it yourself with the git repository here:
https://github.com/nbeaver/custom-pub-file-mimetype
|
This is part 2 of How to install a new (custom) mime type on my Linux system using CLI tools?
Using the steps in the accepted answer at the above question, I created the following mime-type mx-publickey.xml
<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-publickey">
<comment>Custom type for public key files (plain text)</comment>
<glob-deleteall/>
<glob pattern="*.pub"/>
</mime-type>
</mime-info>I installed it system-wide with this command:
# xdg-mime install --mode system mx-publickey.xmlI added the desired icon:
xdg-icon-resource install --context mimetypes --size 256 x-publickey-icon.png text-x-publickeyThen I tested it. My '*.pub` files still have the old association:
$ xdg-mime query filetype id_rsa_test.pub
text/plain$ xdg-mime query default text/plain
org.kde.kate.desktopWhat additional steps are required to associate '*.pub` files with my new mime-type?
Edit:
I performed the following steps, but *.pub public key files are still not being opened by default with Kate from Electron applications.
# xdg-mime default org.kde.kate.desktop text/x-publickey# xdg-mime query default text/x-publickey
org.kde.kate.desktop$ xdg-mime query default text/x-publickey
org.kde.kate.desktopNext I used the GUI tools (KDE System Settings > Applications > File Associations) and associated *.pub public key files with Kate. Electron applications still refuse to open *.pub files with Kate.
Electron apps previously used Okular. Afer the xdg-mime default command shown above, the Okular association is gone, but nothing has replaced it. Electron apps now present a KIO dialog asking me to pick the application to use. (That's better than forcing me to use the wrong application, but it is still not correct behavior. It appears Electron applications are looking other places for the file associations. I would like to understand that.)
Am I missing a needed .desktop file in some location?
Another thought: After the above steps, I believe I should now see an entry for text/x-publickey in /usr/share/applications/mimeinfo.cache. However, there is not one.
| How to associate a new (custom) mime type with files (based on file extension)? |
Make the mime-info file
$ vi ~/.local/share/mime/packages/x-r-noweb.xml$ cat ~/.local/share/mime/packages/x-r-noweb.xml
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="text/x-r-noweb">
<comment>R noweb</comment>
<glob pattern="*.Rnw"/>
</mime-type>
</mime-info>Update mime database
$ update-mime-database ~/.local/share/mime/$ xdg-mime query filetype rnoweb0.Rnw
text/x-r-noweb
$ mimetype -d rnoweb0.Rnw
rnoweb0.Rnw: R noweb
$ mimetype rnoweb0.Rnw
rnoweb0.Rnw: text/x-r-nowebNow, you can set the default application
$ xdg-mime default nice-app.desktop text/x-r-noweb
# (or edit ~/.local/share/applications/mimeapps.list)$ xdg-mime query default text/x-r-noweb
nice-app.desktop |
I'm trying to set the default application for R noweb files but fail to find the place where this is specified. The reason for this is that my file managers seem to determine the file type by filename extension (.Rnw) rather than or in addition to the scheme specified by freedesktop.org (that is: mimeapps.list, mimeinfo.cache, defaults.list...)
I tried pcmanfm and thunar as file managers. They agree in determination of the file type but differ from the xdg-mime query filetype utility. See below for minimal example and config files.
Moreover, the xdg-mime utility seems to ignore the local mimeapps.list, yet the filemanager honours it.
The question is: Is my assumption right that file types are determined by name extension in these file managers and where do I find the associated configuration?
I use Awesome WM as window manager an pcmanfm as desktop manager.
Update: I found this tutorial on file extensions in pcmanfm, but my problem is still that mime type and inferred type by pcmanfm don't match (rnoweb.Rnw is MIME type text/plain, rnoweb0.Rnw is inode/x-empty, yet pcmanfm lists both as R Sweave file)
Update2 [SOLVED]:
@mji proposed an xml file to be put in ~/.local/share/mime/packages. This file already exists as /usr/share/mime/text/x-r-sweave.Rnw. It turns out that changing the <comment> tag in that file changes the Description column in thunar and pcmanfm. It also assigns the MIME type x-r-sweave to the files. I found this already in my question, but overlooked it (I searched for x-r-noweb)Minimal example:
I created four files in an empty directory. Two empty, two with sample content:
touch plain0 rnoweb0.Rnwcat > plain <<EOF
text
EOFcat > rnoweb.Rnw <<EOF
<<>>=
1+1
@
EOFI run xdg-mime query filetype and xdg-mime query default on these files to obtain the following results:
filename MIME type Default app
-------------------------------------------------
plain text/plain medit.desktop
plain0 inode/x-empty
rnoweb0.Rnw inode/x-empty
rnoweb.Rnw text/plain medit.desktopHowever, thunar and pcmanfm list the type of the *.Rnw files as "R Sweave file" and the plain* files as plain text document ("Einfaches Textdokument" in German). Default application listed in the file managers is RStudio for the *.Rnw and GVim for plain*.
Plain text files are opened with GVim, disagreeing with the xdg-mime utility but in accordance to settings in my local .local/share/applications/mimeapps.list
The only files on my system matching locate mimeinfo and locate mimeapps are
/etc/xdg/mimeapps.list
/usr/share/applications/mimeinfo.cache
~/.local/share/applications/mimeapps.list
~/.local/share/applications/mimeinfo.cachegrepping for the ocurrence of rstudio (rstudio.desktop) in these files yields (similar results summarized in {...})
/usr/share/applications/mimeinfo.cache
application/x-r-data=rstudio.desktop;
application/x-r-project=rstudio.desktop;
text/css=rstudio.desktop;
text/html=firefox.desktop;abiword.desktop;calibre-ebook-edit.desktop;rstudio.desktop;elinks.desktop;
text/javascript=rstudio.desktop;
text/x-R=rstudio.desktop;
text/x-markdown=rstudio.desktop;
text/x-r=rstudio.desktop;
text/x-r-{doc,markdown,history,html,presentation,profile,source,sweave}\
=rstudio.desktop;
text/x-tex=texstudio.desktop;gvim.desktop;rstudio.desktop;no other files mentioned in XDG spec contain any occurrence of rstudio.
grepping for the text/plain MIME type, I obtain:
/etc/xdg/mimeapps.list : text/plain=medit.desktop;
/usr/share/applications/mimeinfo.cache : text/plain=medit.desktop;libreoffice-writer.desktop;gvim.desktop;abiword.desktop;
~/.local/share/applications/mimeapps.list : text/plain=gvim.desktop
~/.local/share/applications/mimeapps.list : text/plain=gvim.desktop; | How does filetype determination by filename extension in addition to XDG spec (mimeapps.list) work |
xdg-open is attempting to comply with the standards...
An @ mark is a delimiter between user- and host-names, and without the user-name it is unexpected (and not standard). If you want to use it in a different way, you will have to encode it.
Further reading:Clarification of Proper Use of "@" (at sign) in URI-style Components
Can I use an at symbol (@) inside URLs? |
I'm trying to get xdg-open to properly handle URIs with the pattern of ob://@username but it seems that xdg-open is stripping the @ symbol. Is there someway to prevent this without modifying xdg-open itself?
My openbazaar.desktop file consists of the following:
[Desktop Entry]
Name=OpenBazaar Client
Exec=openbazaar "%u"
Terminal=false
Type=Application
MimeType=x-scheme-handler/obIf I put a character before the @ (i.e. ob://a@username) it doesn't remove it. I've verified that it's not an issue with running openbazaar ob://@username so I'm wondering if there's something I can do in the .desktop file to prevent it from doing this.
| Why does xdg-open remove @ from a URI if it's the first character in the path? |
The Arch Wiki says:Inside a desktop environment (e.g. GNOME, KDE, or Xfce), xdg-open simply passes the arguments to that desktop environment's file-opener application (gvfs-open, kde-open, or exo-open, respectively), which means that the associations are left up to the desktop environment. When no desktop environment is detected (for example when one runs a standalone window manager, e.g. Openbox), xdg-open will use its own configuration files.So, they are not replacements, but backends.
|
Related to this answer on my previous question.
So, XDG can handle it on its own:It can manage default applications - xdg-mime
It can open file with associated application - xdg-open.Why do desktop environments make their own replacements for xdg-open? Like gvfs-open, kde-open, or exo-open,...
Isn't xdg-open enough? If not, what does it lack?
| Why do desktop environments make custom xdg-open replacements? |
Association between MIME types and applications defers to the Desktop Entry Specification, which states thatLines beginning with a # and blank lines are considered comments and will be ignored, however they should be preserved across reads and writes of the desktop entry file.
Comment lines are uninterpreted and may contain any character (except for LF). However, using UTF-8 for comment lines that contain characters not in ASCII is encouraged. |
I want to add comments in my ~/.config/mimeapps.list file.
How do I do this?
Chapter and verse preferred as errors seem to be silently ignored.
| Comments in ~/.config/mimeapps.list |
Open https://us02web.zoom.us/j/77479044122pwd=Nik0ajNiAWRkbXhkbWVJTXJtcklrQT09
translates to:
xdg-open zoommtg://us02web.zoom.us/join?action=join&confno=77479044122&pwd=Nik0ajNiAWRkbXhkbWVJTXJtcklrQT09
There's a bunch of other shite on the final URL, but I reckon that's all you need.
I divined this from moving /usr/bin/xdg-open to /usr/bin/xdg-open.real and changing /usr/bin/xdg-open to:
#!/bin/shlogger -t xdg-open "$*" xdg-open.real "$*"Then chmod +x /usr/bin/xdg-open
After that (and a URL or so) you can grep /var/log/syslog for xdg-open and see what happens.
|
Hi I want to open specific link with specific application. To be more specific, I want to open zoom links https://us02web.zoom.us/j/something?pwd=somethingsomething with desktop-ish zoom application (someting like pwa browser app, but not a native pwa app. Created with: -> three dots -> more tools -> create shortcut). Currently if I tell xdg-open to open this link it'll just send me to my default browser instead of zoom application. So how do I change it and is it possible?
| How to xdg-open specific links with different apps |
You should be able to find the file in one of these folders:/usr/share/applications
/usr/local/share/applications
~/.local/share/applicationsSee https://wiki.archlinux.org/index.php/Desktop_entries for reference.
|
I can open a Python source file using xdg-open, e.g.,
$ xdg-open Documents/tmp/paramk.py
Waiting for Emacs...
$what happens is that emacsclient is invoked and xdg-open returns when I close the Emacs' frame.
Out of curiosity I tried
$ xdg-mime query filetype Documents/tmp/paramk.py
text/x-python
$ xdg-mime query default text/x-python
userapp-emacsclient-CHYLDY.desktop
$Always curious, I wanted to know the details of the emacsclient invocation but …
$ locate userapp-emacsclient-CHYLDY.desktop
$ apt-file search userapp-emacsclient
$ My question: what trick the desktop system is doing behind my back?Addendum
$ cat /etc/issue
Debian GNU/Linux bullseye/sid \n \l$ | Where is the relevant .desktop file? |
A solution is almost indicated in the question: hinder xdg-open from choosing exo-open. A brute-force approach is to copy /usr/bin/xdg-open to /usr/local/bin (/usr/local/bin is earlier in PATH unless PATH has been modified) and to patch it to use open_generic instead of exo_open (unlike the XFCE4-specific exo-open, open_generic does honor xdg mime types)
--- /usr/bin/xdg-open 2020-03-31 03:20:01.000000000 +0200
+++ /usr/local/bin/xdg-open 2020-07-18 10:12:20.133132390 +0200
@@ -691,15 +691,11 @@
open_xfce()
{
- if exo-open --help 2>/dev/null 1>&2; then
- exo-open "$1"
- elif gio help open 2>/dev/null 1>&2; then
- gio open "$1"
- elif gvfs-open --help 2>/dev/null 1>&2; then
- gvfs-open "$1"
- else
+ #if gvfs-open --help 2>/dev/null 1>&2; then
+ # gvfs-open "$1"
+ #else
open_generic "$1"
- fi
+ #fi
if [ $? -eq 0 ]; then
exit_success |
I am trying to register new mimetypes under XFCE4. In particular, I would like to register the protocol zoommtg so I can launch Zoom meetings from links in the webbrowser Chrome. Chrome will launch xdg-open here, which in turn launches exo-open. exo-open seems to ignore mimetype registrations of the type
xdg-mime default ZoomLauncher.desktop x-scheme-handler/zoommtgAlso manually adding
[Default Applications]
x-scheme-handler/zoommtg=ZoomLauncher.desktopto either $HOME/.config/mimeapps.list or $HOME/.local/share/applications/mimeapps.list does not lead to xdg-open via exo-open recognizing the zoommtg protocol.
How can new mimetypes be registered under XFCE4?
Notes:
xfce4-mime-settings does not offer the option to add new mimetypes.
The Chrome browser does not offer the option anymore (tested here: Google Chrome V. 86) to manually define commands to handle protocol types (chrome://settings/handlers only offers the option to allow websites to handle protocols (e.g. mailto: to a site with webmail)).
| How to register new mimetypes not available in xfce4-mime-settings so that they are recognized with xdg-open under XFCE4? |
xdg-open is just a shell script that detects Desktop Environment and call the corresponding program (gvfs-open for gnome , exo-open for XFCE, mate-open, etc.)
So the limitations for launching an executable are derived from the corresponding launcher of each DE, which is gvfs-open in your case.
Looking at gvfs-open man page, this app (similar to the other DE apps) just calls the default application registered per file type as it is defined by gvfs-mime settings.
In your case , gvfs-open tries (and fails) to find a corresponding application to launch a firefox file.
If you run xdg-open (or gvfs-open) with an html link like https://www.google.com , then should work correctly; gvfs-open will search mime database to find how to handle the html link, mime will advise to call firefox, and firefox will be called.
Looking at xdg-open shell script functions, there are some functions that extract the Exec entry out of the corresponding .desktop file and under some Desktop Environments the command found in Exec section of .desktop file is just executed as it is by xdg-open.
In other words, you do not have to call xdg-open or gvfs-open to launch executables like firefox.
Just launch "firefox" and should be executed (i.e popen "/usr/bin/firefox")
PS: Or you might even need to call (exec firefox &)
You could even extract Exec entries by all .desktop files with a grep loop like this:
for file in $(find /usr/share/applications/ -type f -name '*.desktop'); do
executable=$(grep -m1 "^Exec=" "$file") #some files have more than one Exec entry
echo "$file - $executable"
done |
I am trying to write a function launchSystemFile which works like windows ShellExecuteEx from the command line or from C++.
If I ShellExecuteEx a blah.txt it opens it in the default editor.
If I ShellExecuteEx a firefox.exe it launches the executable.
I have been doing from C++ popen "xdg-open blah" and it works great except for executables.
Is there anyway to make xdg-open execute an executable? Such as Firefox at path /usr/lib/firefox/firefox?
I tried xdg-open "/usr/lib/firefox/firefox" but this fails with the error message:gvfs-open: /usr/lib/firefox/firefox: error opening location: No application is registered as handling this file | Launch executable with xdg-open |
I've managed to fix this by going to System Settings -> Applications -> Web Browser and setting parameter Open http and https URLs to in the following browser -> firefox
This works with KDE 5, but should work similar in previous versions.
|
xdg-open opens normal web pages in Firefox, such as xdg-open http://google.com. However, images do not. For example, xdg-open https://i.imgur.com/JfKwovX.jpg opens the image in Gwenview. I tried setting Firefox as default for (all?) urls with
xdg-mime default firefox.desktop x-scheme-handler/http
xdg-mime default firefox.desktop x-scheme-handler/https
xdg-settings set default-web-browser firefox.desktopHowever, this doesn't seem to work for *.jpg urls. How can I make xdg-open open all urls in Firefox?
| How can I open all urls in my browser with xdg-open? |
$ export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
$ xdg-open https://stackoverflow.com/questions/24683221
/usr/bin/xdg-open: 882: /mnt/c/Program: not foundThat error message hints a lot at word splitting in action.
And that's what it is. xdg-open is a shell script that treats $BROWSER as a colon-separated list of browsers to try (similar to how $PATH works), and for each one, it tries to run
$browser "$url"with the $browser unquoted. That means it gets split on whitespace(*), and there's nothing you can do about it. The downside of that is that paths with spaces won't work, and paths with glob characters might be a problem. The upside is that you can use it to pass arguments (provided that those arguments then don't need embedded whitespace etc.).
(* that's with the default IFS, which the script seems to use, unless it gets a modified value from outside the script and is run with a shell that neglects to reset IFS at the start of the script.)
The simplest workaround would probably be to create a symlink without whitespace in its path, point that to the browser and add the path to the symlink to $BROWSER.
|
I use WSL2 (Ubuntu 22.04.1 LTS) and need to refer to edge-browser for xdg-open. Due to the space in the path I get an error. How can I escape the space? The path is shown corrrectly in exported variable BROWSER.
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ xdg-open https://stackoverflow.com/questions/24683221
/usr/bin/xdg-open: 882: /mnt/c/Program: not found
/usr/bin/xdg-open: 882: /mnt/c/Program: not found
xdg-open: no method available for opening 'https://stackoverflow.com/questions/24683221'
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ export BROWSER='/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ xdg-open https://stackoverflow.com/questions/24683221
/usr/bin/xdg-open: 882: /mnt/c/Program: not found
/usr/bin/xdg-open: 882: /mnt/c/Program: not found
xdg-open: no method available for opening 'https://stackoverflow.com/questions/24683221'
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ $BROWSER
-bash: /mnt/c/Program: No such file or directory
oliverk@KPW00WP3Q:/mnt/c/Users/E547766/Documents$ export
declare -x BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" | Escape spaces in path in export variable (Ubuntu 22.04.1 LTS) |
As you say, Association between MIME types and applications specification is the relevant specification, but it doesn’t describe the file format in much detail. However, it defers to the Desktop Entry Specification for the file format; it’s not particularly explicit, but I think theThe value is a semicolon-separated list of desktop file IDs (as defined in the desktop entry spec).mention (regarding the format of key value pairs) is a good indication.
There is a validation tool for .desktop files, desktop-file-validate, but it can’t be used on MIME type lists because MIME types aren’t valid .desktop file keys.
Looking at the code, e.g. for xdg-open, shows that the file format is very simple: tools look up keys in sections, and they do that by starting at the top of the relevant file, looking for the first occurrence of the section between square brackets, then the first occurrence of the key followed by an “=” sign. So effectively, when looking for a given key in a given section, the first line matching the key which also happens to be in the right section will be used.
This has a number of consequences:sections can be repeated
nonsensical lines can be present, they will be ignored
any line not containing “=” or square brackets is effectively a comment |
Is there a way of checking for syntax errors in ~/.config/mimeapps.list?
Errors seem to be silently ignored:I added fdsobojaba to the bottom of the file
I ran xdg-open on an existing file
There was no error in .xsession-errorsHow do I verify mimeapps.list? Or at worst, where is the definition of the file's format?
| Syntax check ~/.config/mimeapps.list |
xdg-open is typically for X applications. As far as I know, there's not going to be a way to get it to understand and launch a Windows executable such as Brave.
Many WSL distributions, including Ubuntu 20.04 when installed from the Store, include the wslview command as an alternative for opening the default Windows applications. For others who may be on different distributions, if it isn't available by default, it can be installed as part of the wslu package.
wslview . will open the directory in whatever application Windows would normal use for directory browsing. This would typically be explorer.exe, but in my case I use Directory Opus instead.
I'm not sure how exactly you would override the default directory browser for Windows, though. If Brave isn't set up to do this when you run start . from PowerShell or CMD, I don't think it's going to work for wslview either. See this question for more details on that aspect.
If all else fails, you should always be able to create an alias (or better, shell function) that calls Brave on a path.
|
I'm in a Windows Subsystem for Linux (WSL) Ubuntu 20.04 LTS.
My ~/.zshrc file currently has the following appended to the end of the file.
export BROWSER='/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exeWhen I try to run
xdg-open .It fails to open the current working directory because the current browser is not compatible.
When running xdg-open ., I expect as if my ~/.zshrc uses:
export BROWSER="powershell.exe /C start"But only in the case where xdg-open is used. I would like to use brave.exe for all other cases as my default browser.
What is the best way to achieve the above?
| Windows browser specific to program within WSL |
I couldn't find a clean way, so this is a work-around; open each file then run a busy-loop waiting for "the" matching process to exit. I've also updated your for loop so that you're not parsing ls and are quoting the filename parameter:
#!/bin/bashfor i in *.pdf
do
xdg-open "$i"
t=$(tty)
t=${t##/dev/}
s=$(ps -o session= -p $$)
while pgrep -f "$i" --terminal "$t" --uid "$(id -u)" --session "$s" >/dev/null 2>&1
do
sleep 1
done
doneThe assumption here is that xdg-open will open the file; that process gets forked off by the desktop environment and control returns to the script. The script then gathers the tty, session, and current user ID and asks pgrep to look for (the) process matching all of these criteria:full process name includes the filename from the loop
the associated terminal is the one we're running from
the UID of the process matches ours
the process session matches ours... all in an attempt to catch only the corresponding process that xdg-open launched.
When that process no longer exists, we continue with the for loop on to the next file.
If the one-second delay is too long, you could replace that (on Linux) with a sub-second sleep, or a simple : for no waiting at all.
|
I have a lot of documents to view, and I'd like to view them one by one, so the next opens when I close the previous.
I've done this with evince before, with
for i in `ls | grep .pdf`; do evince $i; doneHowever doing the same with xdg-open fails because xdg-open does not block like evince does.
Is there a way to run the same for loop, but with xdg-open, so that when I close the application that was opened, the next iteration of the for loop runs?
| xdg-open block until spawned process is killed |
In the end, I have rolled my own: open-uri-in-native-app. A short bash script and a desktop file.
Here’s an excerpt of the script to be set as the handler for https links:
#!/usr/bin/env bash
URI=$1
if [[ $URI =~ ^https://zoom.us/j/ ]]; then
ZOOM=$(xdg-mime query default x-scheme-handler/zoommtg)
if [[ -n $ZOOM ]]; then
NEW=$(echo $URI | sed -E 's@https://zoom.us/j/@zoommtg://zoom.us/join?confno=@; s@\?pwd=@\&pwd=@')
gtk-launch $ZOOM $NEW
exit 0;
fi
fi
BROWSER=$(xdg-mime query default x-scheme-handler/http)
gtk-launch $BROWSER $URI |
Android has a convenient feature: certain https links that have associated local apps installed are opened directly in these apps, skipping the browser page. How do I achieve this in Linux?
I have Zoom installed on my computer. When someone shares a https://zoom.us/j/NNNN link with me and I click it in e.g. Thunderbird, this link is passed to xdg-open. Xdg-open looks at the URI schema "https" and starts the default browser. The browser navigates to this URI and displays a page whose only function is to transform this URI into a different one: zoommtg://zoom.us/join?confno=NNNN. This new URI is in turn passed to xdg-open who launches Zoom.
I could not find a ready-made solution so far. I imagine a script that looks beyond the URI schema. For example, if it receives a parameter starting with https://zoom.us/j/, it ensures that a handler for zoommtg is configured, in which case it rewrites the URI by itself and passes it to the handler. There is supposedly a limited number of popular schemes, so such a script should be relatively simple to maintain.
The script could be used either as a wrapper for xdg-open or as a handler for https links.
At best I would appreciate a link to an existing software which does that. I’d hate to write a script only for my personal use. If such software doesn’t exist so far, I welcome advice on implementing this in a portable way with a goal to publish it.
| Skip the browser page when opening https URIs for Zoom, Teams, and other native apps |
Solution found thanks to pointers from @Ignacio Vazquez-Abrams.
The issue was actually in the way xdg-open passes an argument to the default application.
If the default application is registered in kde desktop so as to expect a url (%u)
/home/bu5hman/Installs/seamonkey/seamonkey %uthen the whole argument passed to xdg-open is used as a url and the browser navigates to the tag.
if the %u is omitted then the argument passed to xdg-open is tested to see if it is a file and then stripped of information from the # in the url (from the xdg-open script)
# If argument is a file URL, convert it to a (percent-decoded) path.
# If not, leave it as it is.
file_url_to_path()
{
local file="$1"
if echo "$file" | grep -q '^file:///'; then
file=${file#file://}
file=${file%%#*} #<----------
file=$(echo "$file" | sed -r 's/\?.*$//')
local printf=printf
if [ -x /usr/bin/printf ]; then
printf=/usr/bin/printf
fi
file=$($printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")
fi
echo "$file"
}and the page is only opened at the top.
In my case firefox had been registered with %u and seamonkey without, which is why I had different behaviour in the two browsers.
|
I have a function in a bash script (openWebPage) which I want to open a web page and navigate to an id tag within the page.
The url components are held in variables
PIXPAGE="/home/bu5hman/pix/pixpages/media.bu5hman.2005-.video.htm"
TT="tt0078435"The call to the function composes the variables
openWebPage "$PIXPAGE#$TT"Within the function, if I hard code the call to my default browser (seamonkey) directly with a file url which has a tag specified
/home/bu5hman/Installs/seamonkey/seamonkey "file://$1"the page opens at the required tag, however using
xdg-open "file://$1"opens the web page at the top but does not navigate to the tag within the page.
When the browser is called directly it opens with the full url and tag in the navigation bar, but when called using xgd-open it opens with the url stripped of the tag (#tt0078435) in the navigation bar.
It appears that xdg-open strips the tag from the url before passing it to the application.
Aside from using a script to interrogate the system for the default browser and composing a direct call, is there a way to either prevent xdg-open from stripping the tag or an alternative cross platform call to open the web page at the tag?
| xdg-open opens a specified htm file but ignores the tag (#) location within the page |
You'd need to patch xdg-open to detect your desktop environment in detectDE(), and add an open_...() function that delegates to ts-open.
Once your DE is ready, you should contact the xdg-utils maintainers with a patch, either via a bug, or the mailing list.
|
I'm creating a desktop for Linux. As a result, I'm creating a utility called ts-open. However, when xdg-open is run, I want it to open ts-open when it detects that my desktop is running (just like it opens kde-open in KDE.) Is there a way to do this? If it has to be coded into xdg-open is there someone that I can speak to?
| xdg-open backend |
What worked for me on KDE (but on Ubuntu) was to open "File Associations" window from the application launcher (or alternatively open "System Settings" and go to "File Associations" there), then:Create a new MIME type (the "+ Add..." button, bottom left)
Choose "application" in the menu and give "xopp" as type nameYou should now find a new "xopp" entry under the "application" types; choose it andIn "Filename Patterns" click "+Add..." and input the "*.xopp" string
In "Application Preference Order" click "+Add..." and choose Xournal++ app.
You can also choose an icon by clicking on the white rectangle. Look for a xournal-related svg file in your system (in my case I chose /snap/xournalpp/current/usr/share/xournalpp/ui/pixmaps/application-x-xopp.svg)
Click "Apply" and "OK" |
I'm trying to change the default application for the filetype .xopp, which is a file for the xournalpp application. I currently ran the following commands:
xdg-mime query filetype 2022-06-09/note.xoppwhich gave me: application/gzip. How can I make only the files that end in .xopp open in xournalpp? It works when I use a file browser, but when I run:
xdg-open 2022-06-09/note.xoppit opens it in an unzipping program.
I'm currently using Manjaro Linux.
| Xdg-Mime won't change default application for .xopp (Xournalpp) files |
Installing perl-File-MimeInfo package resolved the issue!
More info at Why does `xdg-mime query filetype ...` fail to find a new added file type?
|
I have a MIME definition file which is installed as part of a package:
$ rpm -ql virt-viewer | grep mime
/usr/share/mime/packages/virt-viewer-mime.xml
$ cat /usr/share/mime/packages/virt-viewer-mime.xml
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-virt-viewer">
<sub-class-of type="text/plain"/>
<comment>Virt-Viewer connection file</comment>
<magic priority="50">
<match value="[virt-viewer]" type="string" offset="0"/>
</magic>
<glob pattern="*.vv"/>
</mime-type>
</mime-info>But when I query the MIME database, it identifies it as text/plain
$ xdg-mime query filetype console.vv
text/plainI cannot use xdg-open to open the file with remote-viewer, which is a pain (Google Chrome also does not work here). I tried to force reindexing MIME system cache without any luck:
$ sudo update-mime-database /usr/share/mime/My local mime database is empty. What's interesting is Thunar opens the vv file correctly, it's xdg-open which does not work well. Looks like it must be using a different approach. I don't have GNOME or Nautilus installed at all on my system.
This is Fedora 23 with i3wm.
| XDG resolves filename as text/plain |
The closest you can get with xdg is using url-scheme-handlers, i.e. mailto, http, ftp... and so on.
xdg-settings list default-url-scheme-handlersThis will make Google Chrome the default handler for all https links.
xdg-settings set default-url-scheme-handler https google-chrome.desktopYou can't achieve domain specificity with xdg-open.Using a script that intercepts YouTube links and opens them with a specific application is really the only way.
This is similar to what you're after.
It's the approach you want, only without the yad dialog. It really depends on how and/or what is opening the URL.
|
How can I tell xdg-open to open, say, YouTube URLs in a specific app, but use my default browser for all other URLs?
| Open specific URLs in certain app? |
Typically the standard output & error from desktop environment components is redirected to ~/.xsession-errors or a similar file by default (may vary between distributions), and when you start an application like Firefox via GUI, it would inherit that redirection.
The standard input of a GUI application would typically be /dev/null.
But you can do whatever you want.
Redirecting to /dev/null is a valid option and a common choice, particularly if you aren't interested of any debug output a GUI application might produce on stdout/stderr, or know that the application in question won't produce any.
|
Suppose I launch Firefox from my apps. Is the stdout and stderr redirected to a specific file or is it redirected to /dev/null? If it is indeed redirected to a specific file, I'd also like to know how to how to run applications from the terminal (e.g. nohup, & disown) without knowing where to redirect stdout and stdin. In other words, how would I tell the desktop to launch an app, instead of launching it from terminal myself as a detached process. Of course, if the redirection is to /dev/null, then nohup APP >/dev/null 2>&1 and & disown is sufficient.
| Is it Possible to Read stdout and stderr of Apps Launched From the Desktop? |
You can open the file by adding ./:
xdg-open ./-headlinesAfter.epub |
Usually, a double dash separates options from filenames, but xdg-open does not care:
❯ xdg-open -headlinesAfter.epub
xdg-open: unexpected option '-headlinesAfter.epub'
Try 'xdg-open --help' for more information.
❯ xdg-open -- -headlinesAfter.epub
xdg-open: unexpected option '--'
Try 'xdg-open --help' for more information.Is there any other way?
| How to open a file starting with dash via xdg-open |
xdg-open has nothing to do with the presentation, and has no user options. It is just a wrapper that launches another application from the command line.
What application does the image come up in (it should have an about or help menu)? That's what needs configuration. xdg-open just uses a file association to determine the app to run.
A search on 'webcam reversed image in zoom' got me a one-minute YouTube.
Zoom->Video Settings->Mirror My Video (click).
|
I am using a web cam in Zoom, which opens xdg-open to provide the video feed.
Unfortunately the feed is mirror image, so if I have text in the image then it is reversed and unreadable.
How can I modify the xdg-open settings to have a right facing image?
| Mirror image video using xdg-open |
xdg-open will use the default handler open_generic() function if your desktop environment cannot be detected or is not supported. The default handler does not support the terminal well and would resort to using your default browser to open the url.
The gio open command from glib2 can be used instead, as it has better terminal support.
There are also other alternatives to xdg-open, most of which replace /usr/bin/xdg-open
|
I have set default file manager to ranger (xdg-mime query default inode/directory = ranger.desktop). Yet, when I am not in the terminal already, xdg-open / opens in the browser.
I have checked in /usr/share/applications/ranger.desktop is Terminal=true. Setting TERM=foot (my terminal) in /etc/environment did not help, neither did linking my terminal to /bin/xterm.
| `xdg-open /` opens in browser when not already in terminal |
Programs use XDG mimetype associations when they want to open just the folder. In that case, D-Bus configuration would not matter – xdg-open would just spawn nautilus <url> or similar. (Nautilus itself might use D-Bus internally, but that is not a factor here.)
On the other hand, if your browser wants to open the folder with an item pre-selected (e.g. if you clicked "Open in folder" for a downloaded file), then it needs to directly talk to a file manager. The browser will send a D-Bus function call to org.freedesktop.FileManager1 – if that name is currently claimed by a running process, then that process will handle the call; if the name is not currently claimed then dbus-daemon will look for a .service file with a matching Name= and will spawn whatever binary is specified. (If it finds multiple such .service files, it chooses one more-or-less at random.)
In your case, however, neither of those things is happening. What your screenshot shows is not a file manager at all – it's a file picker dialog, which is traditionally provided built-in to the program's UI toolkit and would run in-process for the app (browser or editor or such). A program built using the Qt toolkit would always use the Qt file picker.
The file picker in your screenshot, used by GNOME apps, is part of the 'GTK' UI library and does not interact with the Nautilus or Thunar file managers in any way. The only relationship it has with Nautilus is that it "looks a bit like" Nautilus, as the code implementing the 'Places' side-bar is copy-pasted between the two.
That being said, Chromium-based browsers are a bit of an odd one here, as they are not GTK-based, instead trying to appear "cross-platform" and running either the GNOME or KDE file picker as a separate helper process. For example, I seem to remember that Chromium used to run zenity --file-selection, which itself is a GTK3 program and uses the GTK3 file picker.
Recently, as part of the app sandboxing features in Flatpak and Snap, most desktops now offer their file picker as a D-Bus service, as part of the "XDG Portals" facility that gives sandboxed apps limited access to the host.
Unlike what I just said earlier, the file picker provided by the portal is a completely separate process which can vary depending on the host desktop, e.g. a Flatpak GTK3 program would use the Qt file picker when it's run in KDE.
Chromium, in its attempt to integrate with both desktops, now appears to deliberately use the file selection portal (even if it is not running inside a Snap or Flatpak sandbox). This means that whichever xdg-desktop-portal-* process is running (e.g. the GTK4 one or the Qt6 one) will be the one to provide the file picker for Chromium (and for Firefox as well), as well as any Flatpak or Snap containerized apps you might have.
(On startup, the main xdg-desktop-portal process uses either $XDG_CURRENT_DESKTOP or $XDG_SESSION_DESKTOP – not sure which – to spawn the appropriate implementation for whatever desktop environment you're logged in to. So if you are running GNOME, it will start the GTK implementation of portals, including the file picker, and KDE will start a Qt implementation, both claiming the same D-Bus service name.)
|
As a bit of background, I'm using Arch Linux with i3 as my window manager and I recently stopped using Nautilus as my default file manager and started using Thunar. The browser I'm using is Brave and I have it configured to ask where a downloaded file should be saved prior to downloading, the problem I'm having is that the file manager that appears when selecting the download location is not Thunar and appears to be Nautilus even though it is uninstalled from my OS. My guess is that it's not actually Nautilus but if possible I would like the file manager that appears when downloading files to be Thunar.
So as a definitive question, how can I update my browser to use my system's default file manager when selecting a download location?
What I have tried
I have specified Thunar as the default file manager for my system using the below, which worked but not for the browser download location file manager.
xdg-mime default thunar.desktop inode/directory
To try and solve for this I have tried updating the following file locations to manually update the default application for inode/directory:/usr/share/application/mimecache.info
~/.config/mimeapps.list
~/.config/mimeinfo.cache
~/.local/share/applications/mimeapps.list
~/.local/share/applications/mimeinfo.cacheThese files were already configured correctly after running the intial command. My understanding is that the browser uses xdg-open to determine how to handle opening a file, which correctly uses Thunar when clicking "Show in folder" in the browser Downloads. However, It seems to be a different configuration for the file manager used when selecting a download location.
As seen in the screenshot below, my OS defines the window that the browser opens to download a file as "All Files" and as mentioned before the window looks like Nautilus but if it was I would expect to see "Nautilus" instead of "All Files". So I'm not sure if this is simply not configurable or if I missed something that needs to be updated to point to Thunar.In addition to this I have tried looking at my Dbus settings and noticed that some people have a file /usr/share/dbus-1/services/org.freedesktop.FileManager1.service which I added with the following content, but didn't solve my problem.
[D-BUS Service]
Name=org.freedesktop.FileManager1
Exec=/usr/bin/thunar --gapplication-serviceI'm not that familiar with xdgutils or Dbus to identify which (if either) would be handling this interaction between my browser and system defaults.
| Browser download location file manager is not using system default file manager |
The issue is that your terminal is in bracketed paste mode, but doesn’t seem to support it properly. The issue was fixed in VTE, but xfce4-terminal is still using an old and unmaintained version of it.
You can try temporarily turning bracketed paste mode off by using:
printf "\e[?2004l" |
I use xubuntu 14.04, 64 bit. Every now and then, when I try to paste some text in xfce4-terminal, instead of the expected text to be pasted, it is surrounded by 0~ and 1~, such as:
0~mvn clean install1~The text is supposed to be mvn clean install -- I verified this by pasting the content in various other applications (gnome-terminal, gedit and others). Every application pastes correctly the content, except xfce4-terminal. I couldn't find any references for this on the internet (unfortunately, it is hard to search for text with special characters on google.com...). Why does this happen?
| Copy-Paste in xfce4-terminal adds 0~ and 1~ |
The -H/-hold option is to keep the terminal emulator Window open once the applications started in it (shell or other) has exited. In that state, nothing more can happen.
If you want to start a command as a job of an interactive shell in the xfce4-terminal terminal emulator and keep the shell running and use it interactively after the application has exited, with bash, you can make use of the $PROMPT_COMMAND environment variable, to have xfce-terminal start an interactive shell that starts the given command just before the first prompt.
xfce4-terminal \
-T eclipse \
--working-directory=/home/stefan/oximity \
-e 'env PROMPT_COMMAND="unset PROMPT_COMMAND; /opt/eclipse/eclipse" bash' \
\
--tab -T arandr \
--working-directory=/home/stefan/oximity \
-e 'env PROMPT_COMMAND="unset PROMPT_COMMAND; arandr /home/stefan/.screenlayout/oximity.sh" bash' \
\
--tab -T bash \
--working-directory=/home/stefan/oximity \
...That way, the commands are jobs of that shell which means you can suspend them with Ctrl-Z and resume them later with fg/bg as if you had entered them at the prompt of that interactive shell.
That assumes though that you don't set the $PROMPT_COMMAND in your ~/.bashrc. Also note that the exit status of the command will not be available in $?.
To make it even more like the command was entered at the shell prompt you can even add it to the history list. Like:
xfce4-terminal -T /etc/motd -e 'env PROMPT_COMMAND="
unset PROMPT_COMMAND
history -s vi\ /etc/motd
vi /etc/motd" bash'That way, once you exit vi, you can press the Up key to recall that same vi command.
An easier way to write it:
PROMPT_COMMAND='unset PROMPT_COMMAND; history -s "$CMD"; eval "$CMD"' \
xfce4-terminal --disable-server \
-T /etc/motd -e 'env CMD="vi /etc/motd" bash' \
--tab -T top -e 'env CMD=top bash'The:
xfce4-terminal -e 'sh -c "cmd; exec bash"'solution as given in other answers works but has some drawbacks:If you press Ctrl-C while cmd is running, that kills the outer sh since there's only one process group for both sh and cmd.
You can't use Ctrl-Z to suspend cmd
Like in the $PROMPT_COMMAND approach, the exit status of the command will not be available in $?.You can work around 1 above by doing:
xfce4-terminal -e 'sh -c "trap : INT; cmd; exec bash"'Or:
xfce4-terminal -e 'sh -ic "cmd; exec bash"'With that latter one, you'll also be able to suspend the process with Ctrl-Z, but you won't be able to use fg/bg on it. You'll be able to continue it in background though by doing a kill -s CONT on the pid of cmd.
|
To keep the overview I like to place multiple commands always in the same order and start them automatically together (gradle, git, database, scala-REPL, jboss...)
-H (hold) seems to mean that the terminal isn't closed after termination, but how do I terminate such a process willfully? Not at all? In such a way that I can continue to use the terminal.
I'm using xubuntu with with xfce4-terminal and bash. Is there a better GUI-solution to startup multiple commands, with the ability to continue working in that window/tab?
Update: If you don't know these commands: Jboss and gradle are continously producing output, which you don't want to have intermixed in the same terminal. And sometimes they need to be interrupted with ^C, and restarted. I don't like to reopen an xfce4-term and navigate to the directory I need to act in.
Database and scala-REPL are interactive so there is no sense in starting them in the background.
My current startup-script just navigates to the desired directories, and opens all tabs in the right order to find them always at the same position, naming every tab for its purpose:
xfce4-terminal -T eclipse --working-directory=/home/stefan/oximity -e "/opt/eclipse/eclipse" \
--tab -T arandr --working-directory=/home/stefan/oximity -e "arandr /home/stefan/.screenlayout/oximity.sh" \
--tab -T bash --working-directory=/home/stefan/oximity \
--tab -T gradle --working-directory=/home/stefan/oximity/med \
--tab -T git --working-directory=/home/stefan/oximity/med \
--tab -T mysql --working-directory=/opt/mini/mysql \
--tab -T jboss --working-directory=/opt/mini/jboss \
--tab -T jboss-log --working-directory=/opt/mini/jboss/standalone/log \
--tab -T scala-REPL --working-directory=/home/stefan/proj/mini/forum -e /opt/scala/bin/scalaEclipse and arandr are detached from the shell and run in their own window, so there the -e (execute) param works. I think for the scala-REPL it works since it is the last command in the list.
| How to run xfce-terminal with different commands per tab and keep using the tabs after the commands have returned? |
You can hold the Shift key to use the normal mouse selection while xterm mouse-tracking is enabled. That works in all terminal emulators that I know (xterm, vte (like xfce-terminal) or rxvt-based ones).
In vim specifically, mouse is normally not enabled by default in terminals. So there's probably a set mouse=a somewhere in you ~/.vimrc or your OS-supplied system vimrc. You can always add:
set mouse=to your ~/.vimrc to disable it. Or:
if !has("gui_running")
set mouse=
endifto avoid disabling it for the GUI versions of vim.
Mouse support is (sort of) advertised in the terminfo database with the kmous capability. Now, not all applications rely on that to decide whether to enable mouse tracking or not.
You could redefine the entry for your terminal (in a local terminfo database) to remove that capability:
infocmp -1x | grep -v kmous= | TERMINFO=~/.terminfo tic -x -
export TERMINFO=~/.terminfoFor applications using ncurses, it's enough to set the XM user-defined capability (not documented in terminfo(5) but mentioned in curs_caps(5) and curs_mouse(3)) to the empty string. That doesn't prevent the application from handling mouse events if they're sent by the terminal, but that prevents the application from sending the sequence that enters the mouse tracking mode. So you can combine both with:
infocmp -1x |
sed '/kmous=/d;/XM=/d;$s/$/XM=,/' |
TERMINFO=~/.terminfo tic -x -
export TERMINFO=~/.terminfo |
I'm asking this question while using xfce4-terminal, but I'm interested in a general solution: is there a way to stop a terminal emulator announcing mouse support in consoles? I need mouse-select and copy-paste much more frequent that I need mouse support in vim or wherever.
| How to disable mouse support in terminal? |
In xfce terminal go to Edit, hover your mouse over Copyand press ctrl+c.
Same goes for paste.
Kill process gets automatically reassigned to ctrl+c+shift.
|
Hello I can't find the option to reassign shortcuts in xfce4-terminal 0.6.3. I'd like to reassign ctrl+c to copy, ctrl+v to paste and ctrl+shift+c to kill process. I know I can do that easily under gnome-terminal but since I'm using xfce I would like to avoid installing all the dependencies for gnome-terminal. Any idea on how to achieve that ?
| How to set ctrl+c to copy, ctrl+v to paste and ctrl+shift+c to kill process in xfce4-terminal? |
Unfortunately, xfce4-terminal doesn't read X resources, so that there is no unified way to make such configuration for all X clients which are xfce4-terminals (even remote ones.)
Start terminal maximized? has already been asked at reddit and answered; that's only a part of the complete correct answer:Change the Exec command in /usr/share/applications/xfce4-terminal.desktop.There are two drawbacks with this answer:/usr/share/applications/ is not the place for customizations; it would be overwritten by distro package upgrades.
It doesn't affect the launcher for the terminal, which in its turn uses exo-open --launch TerminalEmulator. (This problem was pointed out in that thread at reddit.)Solutions:
1. The place for customizations
Per the advice by killermoehre in https://mail.xfce.org/pipermail/xfce/2015-April/034375.html:Never ever change files in /usr (except for /usr/local) directly. They will be overwritten on updates. If you want to make changes, copy them before into ~/.local/share/applications/ (create if necessary).so, I've edited /usr/share/applications/xfce4-terminal.desktop and saved it to ~/.local/share/applications/xfce4-terminal.desktop. The changed line looks like this:
Exec=xfce4-terminal --maximize2. Affecting the behavior of the launcher
By grepping through ~/.local and ~/.config after having configured a custom helper as the Terminal through the menu, I've found the other place that needs to be changed -- ~/.local/share/xfce4/helpers/custom-TerminalEmulator.desktop (--maximize is present at two places):
[Desktop Entry]
NoDisplay=true
Version=1.0
Encoding=UTF-8
Type=X-XFCE-Helper
X-XFCE-Category=TerminalEmulator
X-XFCE-CommandsWithParameter=/usr/bin/xfce4-terminal --maximize -x "%s"
Icon=xfce4-terminal
Name=xfce4-terminal
X-XFCE-Commands=/usr/bin/xfce4-terminal --maximizewhereas I have the following ~/.config/xfce4/helpers.rc:
WebBrowser=firefox
MailReader=thunderbird
FileManager=Thunar
TerminalEmulator=xfce4-terminal |
I'd like to start the Xfce Terminal in Xfce always maximized. (Usually, I do that through the launcher in the panel.)
I've already done that for Emacs by means of X resources; however, xfce4-terminal doesn't read X resources.
How to make it be always started maximized?
| How to start the Xfce Terminal always maximized in Xfce? |
You will need xdotool.
Installation
sudo pacman -S xdotool
Usage
Going to the next workspace
xdotool set_desktop --relative 1
Going to the previous workspace
xdotool set_desktop --relative -1
NOTE: Negative numbers are said to be allowed, but some versions of xdotool do not allow negative numbers or at least give an error. Test negative numbers before you implement scripts with negative numbers.
Work around for going to the previous workspace
If you have n workspaces, then for going into the previous workspace
xdotool set_desktop --relative n-1
where n = number of workspaces.
Example:
n = 8 workspaces
xdotool set_desktop --relative 7
|
I am using Manjaro Linux 18 (Arch Linux based Linux distro). I am using XFCE desktop environment. I have 8 workspaces on my computer. How do I move to the next and previous workspace using the command line?
I have Googled and found multiple apps on Github that are said to do that, but none seem to work.
| How do I move move to the next workspace using command line? |
The process your cmd is supposed to be run in will be killed by the SIGHUP signal between the fork() and the exec(), and any nohup wrapper or other stuff will have no chance to run and have any effect. (You can check that with strace)
Instead of nohup, you should set SIGHUP to SIG_IGN (ignore) in the parent shell before executing your background command; if a signal handler is set to "ignore" or "default", that disposition will be inherited through fork() and exec(). Example:
#! /bin/sh
trap '' HUP # ignore SIGHUP
xclock &
trap - HUP # back to defaultOr:
#! /bin/sh
(trap '' HUP; xclock &)If you run this script with xfce4-terminal -H -x script.sh, the background command (xclock &) will not be killed by the SIGHUP sent when script.sh terminates.
When a session leader (a process that "owns" the controlling terminal, script.sh in your case) terminates, the kernel will send a SIGHUP to all processes from its foreground process group; but set -m will enable job control and commands started with & will be put in a background process group, and they won't signaled by SIGHUP.
If job control is not enabled (the default for a non-interactive script), commands started with & will be run in the same foreground process group, and the "background" mode will be faked by redirecting their input from /dev/null and letting them ignore SIGINT and SIGQUIT.
Processes started this way from a script which once run as a foreground job but which has already exited won't be signaled with SIGHUP either, since their process group (inherited from their dead parent) is no longer the foreground one on the terminal.
Extra notes:
The "hold mode" seems to be different between xterm and xfce4-terminal (and probably other vte-based terminals). While the former will keep the master side of the pty open, the latter will tear it off after the program run with -e or -x has exited, causing any write to the slave side to fail with EIO. xterm will also ignore WM_DELETE_WINDOW messages (ie it won't close) while there are still processes from the foreground process group running.
|
I'm using a bash script script.sh containing a command cmd, launched in background:
#!/bin/bash
…
cmd &
…If I open a terminal emulator and run script.sh, cmd is properly executed in background, as expected. That is, while script.sh has ended, cmd continues to run in background, with PPID 1.
But, if I open another terminal emulator (let say xfce4-terminal) from the previous one (or at the beginning of desktop session, which is my real use case), and execute script.sh by
xfce4-terminal -H -x script.shcmd is not properly executed anymore: It is killed by the termination of script.sh. Using nohup to prevent this is not sufficient. I am obliged to put a sleep command after it, otherwise cmd is killed by the termination of script.sh, before being dissociated from it.
The only way I found to make cmd properly execute in background is to put set -m in script.sh. Why is it necessary in this case, and not in the first one? Why this difference in behaviour between the two ways of executing script.sh (and hence cmd)?
I assume that, in the first case, monitor mode is not activated, as one can see by putting set -o in script.sh.
| Process killed before being launched in background |
Modern terminal application uses additional fonts other than the default one when a character is unknown but xterm uses exclusively a single font (except for the special cases of double-width characters)
The needed char $'\ue0a0', echo $'\ue0a0' is part of OpenSymbol font, we can use it with xterm but as that font does not include normal characters this would make it unusable, thus one solution is to use a patched font that include the needed special char and load it with the following
xterm -fa 'Inconsolata for Powerline'We can as well set the size of the font as follow
xterm -fa 'Inconsolata for Powerline' -fs 16This settings can be applied to the current user by adding the following to ~/.Xresources or system widely on /etc/X11/app-defaults/XTerm
XTerm*faceName: Inconsolata for PowerlineLinks: 1, 2, 3, 4, 5 and 6
|
My xterm supports uni-code. For instance, it displays the Euro sign:
echo -e '\xe2\x82\xac'But it does not display one particular character:
PL_BRANCH=$'\ue0a0'
echo $PL_BRANCHThis character displays properly in another terminal (terminator). I am using same font in both terminals (Inconsolata).
What could be the reason and how can I fix it ?
| Xterm does not display one uni-code character |
My changes to RJ-Adam's answer were rejected, thus I give correcting answer:
User specific configuration can be set in
${XDG_CONFIG_HOME:-~/.config}/xfce4/terminal/terminalrcWhich commonly resolves to:
~/.config/xfce4/terminal/terminalrcEdit that and so xfce4-terminal picks up the changes immediately, if it is running.
You could use sed -i or gawk -i inplace to programmably edit the file and consequently change the settings
See XDG Base Directory Specification for more about which and how configuration settings are read especially concerning system wide configuration which is the base.
|
With terminal emulators like gnome-terminal, it is possible to change settings programmatically, from the command line using dconf and gconf.
But I have trouble finding a similar mechanism for xfce4-terminal.
Specifically, how to select colors or a theme (or preset as it is called in the preferences menu).
I tried finding a corresponding option using xfconf-query but there doesn't seem to be one.
| How to programmatically change settings of xfce4-terminal? |
Yes, sure. Run:
xfce4-terminal --preferencesAnd make: Run a custom command instead of my shell and type fish in the box just below. That's it, close and start xfc4-terminal. That's it. Enjoy.
|
I want to use FISH shell. But I've read FISH is not a POSIX shell so setting it to default shell by chsh is not recommended. What I want is whenever I start xfce4-terminal I would like to start FISH shell instead of bash. Adding exec fish to .bashrc seems to be a solution, but I want a to know if there is a way to start fish without starting it on top of bash.
| How can I make xfce4-terminal start fish shell? |
When bash is run as a non-interactive shell it will not source the .bashrc file and if you use a graphical display manager then the login shell used to run the GUI launcher commands might not have sourced the .profile file. Thus, commands run using the GUI launcher might not have the desired environment variables set when run.
A workaround I found was to tell the terminal emulator to run bash in interactive mode (with the -i flag) and then immediately run fish inside of it:
xfce4-terminal -e 'bash -i -c fish' |
If I run fish from a bash prompt, it will inherit the environment variables I have set in my .bashrc and .profile files, including the important $PATH variable. So far so good.
Now, I want xfce4-terminal, my terminal emulator, to use fish instead of bash. I found that it supports a -e command line parameter for that but if I run xfce4-terminal -e fish from a GUI application launcher1 then I don't get the environment variables from bash. What gives?1 Launching xfce4-terminal from an interactive bash prompt also didn't work but gnome-terminal, who has a similar command line switch did. However, gnome-terminal also didn't get the variables when launched from a GUI shortcut.Edit: I've since bitten the bullet and just made fish into my login shell with chsh --shell /usr/bin/fish. Its much simpler than what I was trying to do before and it avoids some undesirable effects of running fish inside bash (such as having the $SHELL environment variable set to bash)
| How do I create a GUI application launcher for xfce4-terminal with fish but inheriting the environment variables from bash? |
You are describing the feature of VTE (used in XFCE Terminal) which translates wheel-mouse scrolling into up/down cursor-keys when using the alternate-screen. That happens if you are running screen in something like xterm. You can avoid that by preventing screen from using the terminal's alternate screen feature.
For example (see How to disable alternate buffer in GNU screen itself but not for vim, less inside it?), tell screen that the feature does not exist (by putting this in .screenrc):
termcapinfo xterm ti@:te@A similar workaround is used for tmux (see Properly disable terminal capabilities for alternate screen in tmux), putting this in .tmux.conf:
set -ga terminal-overrides ',xterm*:smcup@:rmcup@'This translation of scrolling behavior does not appear to be configurable in VTE-based terminals. It is configurable in xterm, e.g., alternateScroll (patch #282).
Further reading:Make screen work like a terminal (scrolling + alternate screen)
Fixing the alternate screen problem (one of many pages pro/con)
Why doesn't the screen clear when running vi? |
Is there a way to disable scrolling through command history for the Xfce terminal? I don't wish to rely on palm rejection, I'd just like it disabled when I'm using the terminal. Specifically I'm talking about not cycling through previous commands at the prompt when scrolling with mouse/touchpad.
| Disable scroll inside Xfce terminal / Avoid scrolling through command history |
I found the solution. I added this code to the .bashrc file.
if [ $COLORTERM == "xfce4-terminal" ]
then
echo "Welcome to the Xfce4 Terminal"
fi |
I want the Xfce terminal to run a command when it is turned on, for example print a welcome message or some system stats. I want this message to be printed only on the Xfce terminal emulator when it starts, not on some other terminal emulators. Can I achieve this effect by modifying the file terminalrc? How?
| How to make Xfce terminal run a command when it starts? |
The line
"\M-[3~": delete-charis incorrect because it tells bash to look for the meta character for [, which (according to bash) could be the escape character followed by [, or it could be the character formed by OR'ing [ with 0x80, i.e., 0xdb which is Û
The actual key would use just the escape character, so you should use this setting:
"\e[3~": delete-char |
I am using XFCE Terminal emulator 0.4.8.
My ~/.inputrc file:
# Insert Key
"\e[2~": paste-from-clipboard
"\C-v": paste-from-clipboard
"\e[A":history-search-backward
"\e[B":history-search-forward
"\M-[3~": delete-charWhen I click <Del> a tilde is printed instead of deleting the next character. When I remove .inputrc file, it starts working correctly. Googling showed, that this line:
"\M-[3~": delete-charhas helped people to cure this. But not me. I inserted this line into .inputrc, even deleted all the other lines. Doesn't work.
How to fix?
| Tilde when clicking <Del> key |
As mentioned in the documentation from the Xfce documentation page, you can either use the Run Program from the Start menu or you can press ALT + F2.Application Finder
If you know the name of a program and it is not on the panel or in the desktop menu you can use the run dialog. To open the dialog type Alt-F2 or choose the Run Program... option from the desktop menu.Note:
This is not an Xfce only option.
Edit
Alternatively, you can start it from the command line using:
xfce4-appfinder --collapsedThis can be conveniently accessed via Keyboard > Application Shortcuts in the Settings menu by adding a keyboard shortcut of your choice.
|
OS: Linux Mint 18.2 sonya
DE: XFCE
By clicking the menu-button in the panel, there exists the option Run Program .... I want to create a shortcut in Menu/Settings/Settings-Manager/Keyboard/Application-Shortcuts to access this application-launcher from the menu. Does there a terminal command exist which i can use to assign a shortcut-key-combination in order to call this application-launcher? | How to create a shortcut in xfce for "Run Program ..." |
If you are running systemd you can create a service that will start yourt software and then use systemctl enable [your-service] to start it on boot up. If your using openrc(old init) then you can use a similar method just use rc-update add [service] default
|
I am running CentOS 7 with XFCE as my DE. I made a bash script, originally stored in ~/bin (I have since deleted it), which I wanted to have run automatically at startup. I somehow succeeded, but I have tried to remove it from my autostart programs, to no avail. when I run ctrontab -e, I am given an empty file to edit. It is therefore not started through there.
when I open Session and Startup -> Application autostart, the only programs are: spice vdagent, tracker application miner, tracker metadata extractor, tracker user guides miner, XFCE polkit, Xfsettingsd, redshift, power manager, network.
when I find its PID and look through /proc/PID/, the exe is a link to /usr/bin/xfce4-terminal (note: the script started an xfce4-terminal and ran commands on it, then stayed open after printing its output). I don't know where else I could find useful information about what ran this program. cwd is a link to ~, root is a link to /, the rest are empty files pretty much.
the script is no longer in ~/bin, yet is somehow still being run
I also, at one point, installed devilspie2 to manage that terminal window, and messed around with it. I have since uninstalled it. I wouldn't expect it to have anything to do with it, but I figured I'd specify this.where else could it be started from? How would I know?
| Other than crontab, what other ways can one add programs to run at boot time? |
If you use other window managers with XFCE you can manipulate windows in many ways you don't currently have with XFWM. Compiz in particular with the grid and put plugins give you shortcuts to place windows in various positions like a tiling window manager. You'll want to install ccsm (compiz config settings manager) to manage plugin settings and set your shortcuts.
|
In windows 7 using Windows Key + Left or Right arrow makes a window take up half the screen.
XFce 4 has the ability to tile either two windows side by side or 4 windows one in each of four corners (bottom left, bottom right, top left, top right).
Is it possible to add keyboard shortcuts so that you can move windows into these six positions:
(take up left half, take up right half, bottom left, bottom right, top left, top right)?
| keyboard shortcuts for placing an xfce4 window into the corner |
As egmont suggested in a comment, the option to disable the scrollbar can be found by disabling it in the GUI and then, searching in the terminalrc file the added line.
Edit this file: ~/.config/xfce4/terminal/terminalrc
The option to add in the terminalrc file to disable the scrollbar is:
ScrollingBar=TERMINAL_SCROLLBAR_NONE |
I would like to configure xfce4-terminal (in Xubuntu 16.04) only by using the terminalrc file, not by using the GUI interface.
The terminalrc file is the file where I can configure different options according to the xfce4-terminal's documentation.its location: $HOME/.config/xfce4/terminal/terminalrc
examples of option:MiscMenubarDefault=FALSE
MiscToolbarDefault=FALSEIn the previous link, I cannot find any option to disable the scrollbar.
The question is, is there an option in the terminalrc file to disable the scrollbar? And, supposing the answer is yes, what is this option?
| How to disable the xfce4-terminal's scrollbar with an option in the terminalrc file? |
Okay here is what I have on my .zshrc for ctrl+←, ctrl+→ and alt+←, alt+→
## use Ctrl <- and Ctrl -> for jumping to word-beginnings on the CL
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
## the same for alt-left-arrow and alt-right-arrow
bindkey '^[[1;3C' forward-word
bindkey '^[[1;3D' backward-wordOn my system these work for crtl+del and alt+del but I haven't found the keys for ctrl+backspace and alt+backspace.
bindkey '^[[3;5~' kill-word
bindkey '^[[3;3~' kill-wordYou enter those odd characters that represent each key combination by pressing Ctrl+V followed by the key combination you want. For example pressing Ctrl+V followed by Ctrl+← produces ^[[1;5D
|
Hi I'd like to change the key mappings slightly in xfce4-terminal, maybe similar to adding Xterm.VT100.translations to .Xresources.
In particular, I want to make ctrl-backspace delete the last word, and ctrl-delete delete the next word.
Bonus: I'd like to make alt act like ctrl (duplicate functionality) for backspace, delete, left arrow, right arrow.
How to do all or any of these things in xfce4-terminal ?
EDIT:
Progress so far: I'm using bash, and bash uses the the readline library and a bash built-in function, "bind," to map key sequences to readline functions. The functions I need turn out to be "shell-kill-word" and "shell-backward-kill-word." In principle, I should be able to do something like this:
"\C-Rubout":shell-backward-kill-word
"\C-Delete":shell-kill-word
"\M-Rubout":shell-backward-kill-word
"\M-Delete":shell-kill-wordHowever, the xfce4-terminal emulator, or some component higher upstream in the process (could it be the window manager, xfwm4, the Xorg program itself?) is not cooperating. In general, the meta key is translated to an Escape character, for example this works:
"\ey":shell-kill-word <-- Meta + y kills next wordbut with the the backspace and delete keys I'm out of luck. I tested the keycodes from two terminal emulators, xfce4-terminal and xterm, generated by backspace and delete and control-key combinations on my keyboard. Here they are, as reported by emacs's C-h C-l command:
xterm:
backspace: DEL
delete: \e[3~
\C-backspace: \C-h
\C-delete: \e[3;5~
\M-backspace: y-umlaut (y with two dots over it)
\M-delete: nothingxfce4-terminal:
backspace: DEL
delete: \e[3~
\C-backspace: DEL
\C-delete: \e[3;5~
\M-backspace: \e DEL
\M-delete: nothingIn particular, in xfce4-terminal it is impossible to bind \C-backspace to shell-backword-kill-word because it sends the exact same keycode as a regular backspace. And it's impossible to bind \M-delete to shell-kill-word because it doesn't send a keycode at all.
I'm frustrated because one (big) reason for switching to Linux and dealing with all the hardware/software compatibiltiy issues is that Linux is so customizable. I like having my windows get focus when I mouse over them for example, rather then click on them. Addressing problems like this one in modern Linux distros would seem to me to be a high priority task. Unfortunately I don't have time to do all the background research into X, and xfce I need to do to take the next step in solving this problem. Can someone with more knowledge of the Xorg ecosystem point me in the right direction? Perhaps there is an alternative terminal emulator that does this better?
Final piece of info: running emacs in an X window, it gets all but one of the keycodes:
backspace: <backspace>
delete: <delete>
\C-backspace: <C-backspace>
\C-delete: <C-delete>
\M-backspace: <M-backspace>
\M-delete: nothing | Change key mappings for xfce4-terminal |
w displays the information stored in utmp (/var/run/utmp typically on Linux systems). This generally is only updated by “login” sessions, i.e. login (for logins on virtual consoles or serial connections), the display manager (for graphical sessions), the SSH server (for SSH connections), and some (most?) terminal emulators. In the latter case, whether or not they update utmp depends on their built-in support and configuration; for example xterm has the ut flag for this (-ut disables utmp updates, +ut enables them), and GNOME Terminal no longer updates utmp directly at all.
So you’re seeing the entries which have been added to utmp in your case: one added by your display manager (on tty7), and others added by some of the terminal emulators you’re using.
It should be possible to wrap commands to add utmp logging to anything you like, using for example libutempter, but that is apparently not as straightforward as one might hope.
|
If I open terminal and execute w command then it will show:
user tty7 :0 12:04 39:56 36.87s 0.06s /sbin/upstart -Now if open terminator or xterm and execute w command then it will show it's entry in the output of w command like
user tty7 :0 12:04 39:56 36.87s 0.06s
/sbin/upstart -
user pts/2 :0.0 12:50 1.00s 0.02s 0.00s wbut it will not show a new entry when I open gnome-terminal or xfce4-terminal.
Why it is showing new session for terminator and not for xfce4-terminal?
| w command doesn't show all pseudo-terminal sessions |
Launch xev, press the key and use the 2nd value inside the parenthesis in the 3rd line:
KeyPress event, serial 38, synthetic NO, window 0x4200001,
root 0x7b9, subw 0x0, time 18425452, (520,545), root:(522,547),
state 0x0, keycode 51 (keysym 0x5d, bracketright), same_screen YES,
XLookupString gives 1 bytes: (5d) "]"
XmbLookupString gives 1 bytes: (5d) "]"
XFilterEvent returns: False
You'll find bracketleft and slash for the other ones. Thus
(gtk_accel_path "<Actions>/terminal-window/next-tab" "<Alt>bracketright")A worse alternative is to look into /usr/include/X11/keysymdef.h, where you will find lines such as
#define XK_bracketright 0x005d /* U+005D RIGHT SQUARE BRACKET */ |
I am trying to change my xfce4 terminal keybindings by editing the accels.scm file.
One of the changes I lines I wrote is (gtk_accel_path "<Actions>/terminal-window/next-tab" "<Alt>]"). However, this is not working: it seems that gtk needs me to use some name like "RightSquareBracket" or something of the sort instead of simply "]". The same happens with [ and /. I searched for some list with name-key correspondences for gtk without luck.
Do you know where I can find these correspondences? Or at least what are the strings corresponding to [, ] and /?
| gtk name for [, ] and / |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.