date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,303,114,106,000 |
I read this up on this website and it doesn't make sense.
http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/basic/node32.html
When UNIX was first written, /bin and
/usr/bin physically resided on two
different disks: /bin being on a
smaller faster (more expensive) disk,
and /usr/bin on a bigger slower disk.
... |
What? no /bin/ is not a symlink to /usr/bin on any FHS compliant system. Note that there are still popular Unices and Linuxes that ignore this - for example, /bin and /sbin are symlinked to /usr/bin on Arch Linux (the reasoning being that you don't need /bin for rescue/single-user-mode, since you'd just boot a live CD... | Difference between /bin and /usr/bin |
1,303,114,106,000 |
According to FHS-3.0, /tmp is for temporary files and /run is for run-time variable data. Data in /run must be deleted at next boot, which is not required for /tmp, but still programs must not assume that the data in /tmp will be available at the next program start. All this seems quite similar to me.
So, what is th... |
The directories /tmp and /usr/tmp (later /var/tmp) used to be the dumping ground for everything and everybody. The only protection mechanism for files in these directories is the sticky bit which restricts deletion or renaming of files there to their owners. As marcelm pointed out in a comment, there's in principle no... | What's the difference between /tmp and /run? |
1,303,114,106,000 |
From what I understand, the right place to put your own scripts is /usr/local/bin (for instance a script I use to back up some files). I notice that this folder is currently (by default) owned by root, and my normal user has no access to it. I am the only user on this computer. Shall I change this whole folder to my o... |
By default, the owner and group of /usr/local and all subdirectories (including bin) should be root.root and the permissions should be rwxr-xr-x. This means that users of the system can read and execute in (and from) this directory structure, but cannot create or edit files there. Only the root account (or an administ... | Permissions/ownership of /usr/local/bin |
1,303,114,106,000 |
In a bash sub shell I get the following error when running cd
sudo: cd: command not found
This is expected because I don't have a path. Usually to work around this I just provide the full path like so: (/usr/local/bin/foo)
Much to my surprise, cd does not appear to be in any of the normal places.
which cd
whereis c... |
What cd am I using?
If you're in Bash cd is a builtin. The type command even bears this out:
$ type -a cd
cd is a shell builtin
cd is /usr/bin/cd
cd is /bin/cd
The system will use the first thing in this list, so the builtin will be the preferred option, and the only one that works (see the section below on What is /... | where is `cd` located? [duplicate] |
1,303,114,106,000 |
I wanted to put my work files (code) in /usr/local/src, but I think it's already a folder that has some other semantic meaning.
What is that? Should I put source code there, or is there a better place?
Edit - I am the sole user and admin of the machine, and I don't want to use my home directory because it's on an NFS ... |
According to Linux FHS, /usr is the location where Distribution-based items are placed and /usr/local is the location where you'd place your own localized changes (/usr/local will be empty after a base install). So, for example, if you wanted to recompile an Ubuntu package from source, their package manager would pla... | What is the "/usr/local/src" folder meant for? |
1,303,114,106,000 |
I'm a long time Linux user for over 15 years but one thing I hate with a passion is the mandated directory structure. I don't like that /usr/bin is the dumping ground for binaries or libs in /usr/lib, /usr/lib32, /usr/libx32, /lib, /lib32 etc... Random stuff in /usr/share etc. It's dumb and confusing. But some like it... |
First, an up-front conflict-of-interest disclaimer: I am a long-time GoboLinux developer.
Second, an up-front claim of domain expertise: I am a long-time GoboLinux developer.
There are a few different structures in current use. GoboLinux has one, and tools like GNU Stow, Homebrew, etc, use something quite similar (pri... | What are the alternatives to the FHS? |
1,303,114,106,000 |
I am developing a daemon that needs to store lots of application data, and I noticed that on my system (Fedora 15), there is a /usr/local/etc directory.
I've decided to install my daemon to /usr/local/bin, and I need a place for my config files.
I didn't see this on Wikipedia. Is this non-standard or is this in fact t... |
/usr/local is usually for applications built from source. i.e. I install most of my packages using something like apt, but if I download a newer version of something or a piece of software not part of my distribution, I would build it from source and put everything into the `/usr/local' hierarchy.
This allows for sep... | What is the difference between /etc and /usr/local/etc |
1,303,114,106,000 |
Compare Debian (left) and Ubuntu (right):
$ ifconfig $ ifconfig
bash: ifconfig: command not found eth0 Link encap ...
$ which ifconfig $ which ifconfig
$ /sbin/ifconfig
Then as superuser:
# ifconfig ... |
In the Debian Policy is written that Debian follows the File Hierarchy Standard version 2.3. Note #19 on the standard says:
Deciding what things go into "sbin" directories is simple: if a
normal (not a system administrator) user will ever run it directly,
then it must be placed in one of the "bin" directories. Ordina... | Is there a reason I would not add /usr/local/sbin, /usr/sbin, /sbin to my path on Debian? |
1,303,114,106,000 |
Originally in Unix, /usr was used for user (home) directories. So if I had a user named alex, my home directory would be /usr/alex. (Interestingly, Plan 9, the successor to Unix, still has user directories in /usr.)
Nowadays, of course, we store home directories in /home. (At least on GNU/Linux. I don't know about oth... |
This change was introduced by BSD after 1985 (BSD 4.2 was still documenting /usr) and in or before 1988 (BSD 4.3/SunOS 4.1 hier(7) manual page already documents /home). It was quickly followed by Solaris 2.0 (which kind of merged System V and BSD) and was later adopted by most other Unix vendors.
This is from the Sola... | At what point did the /home directory appear? |
1,303,114,106,000 |
In FHS-2.3, we have /media that holds mount points for removable media such as CD-ROMs and we have /mnt that holds temporarily mounted filesystems.
On the other hand, we have /run/media and /run/mount. For me, the CDs and USBs are mounted on /run/media.
I don't see any clear distinction between them(/media, /mnt, /run... |
FHS v2.3 was released ten years ago. Some things have changed since then (including the introduction of /run1). About three years ago, the Linux Foundation decided to update the standard and invited all interested parties to participate.
You can view the v. 3.0 drafts here and the section that describes /run here.
The... | what is the distinction between /media, /mnt and /run/mount? |
1,303,114,106,000 |
Coming from the Windows world, I have found the majority of the folder directory names to be quite intuitive:
\Program Files contains files used by programs (surprise!)
\Program Files (x86) contains files used by 32-bit programs on 64-bit OSes
\Users (formerly Documents and Settings) contains users' files, i.e. docum... |
Linux distributions use the FHS: http://www.pathname.com/fhs/pub/fhs-2.3.html You can also try man hier.
I'll try to sum up answers your questions off the top of my head, but I strongly suggest that you read through the FHS:
/bin is for non-superuser system binaries
/sbin is for superuser (root) system binaries
/usr... | Standard and/or common directories on Unix/Linux OSes |
1,303,114,106,000 |
There's a system-created /var/backups directory on Debian-based systems. I need a place to store backups of several git repositories (the primaries are on bitbucket). If I store them in /var/backup/git will that break apt-get, or will they get automatically deleted at inopportune times? Is there any reason I shouldn't... |
/var/backups is specific to Debian. It is not specified in the FHS, and its use is not documented in Debian policy (See Debian Bug report logs - #122038). The behavior is described in http://ubuntuforums.org/showthread.php?t=1232703.
While I agree with @fpmurphy that there is little danger of Debian ever removing your... | Is it bad/dangerous/inappropriate to put arbitrary backups in /var/backups? |
1,303,114,106,000 |
According to the Filesystem Hierarchy Standard the /bin directory should contain utilities needed in single user mode. In practice, many Linux distributions make the directory a symbolic link to /usr/bin. Similarly, /sbin is nowadays often a symbolic link to /usr/bin as well.
What's the rationale behind the symlinks?
|
Short summary of the page suggested by don_crissti:
Scattering utilities over different directories is no longer necessary and storing them all in /usr/bin simplifies the file system hierarchy. Also, the change makes Unix and Linux scripts / programmes more compatible.
Historically the utilities in the /bin and /sbin ... | Why is /bin a symbolic link to /usr/bin? |
1,303,114,106,000 |
I'm trying to understand the Filesystem Hierarchy Standard. I have looked up both binaries and libraries, and as I currently understand it:
binaries are files of computer-readable code in binary format, that control the CPU and processor directly with bits.
libraries are functions usable by various programs, for conve... |
Your understanding is mostly correct, but there are a couple of extra things to consider:
'binary' refers to something that isn't human readable. This usually refers to machine code, but many other files are also binary files in this sense, with most multimedia formats being a good example. The FHS however has a mo... | What's the difference between a binary file and a library? |
1,303,114,106,000 |
Can programs installed under /opt be safely symlinked into /usr/local/bin, which is already in the PATH by default in Ubuntu and other Linux distros?
Alternatively, is there some reason to create a separate /opt/bin and add that to the PATH, as in this answer: Difference between /opt/bin and /opt/X/bin directories?
|
There is a difference between /opt and /usr/local/bin. So just symlinking binaries from one to another would be confusing. I would not mix them up.
/opt is for the installation of add-on application software packages, whereas the /usr/local directory is for the system administrator when installing software locally (wi... | How should executables installed under /opt be added to the path? |
1,303,114,106,000 |
I'm wondering what the FHS compliant mount points for internal harddrives and networkshares are? Many different tutorials are suggesting to mount them in subdirectories to /mnt or /media
According to the FHS 3.0 (File Hierarchy Standard):
/media : Mount point for removable media
(This directory contains subdirectori... |
You make your own mount point directories. If you want to ask why, I can only point to the great answer by Wouter Verhelst.
Internal drives
/mnt is a valid place to make your own if you like, and so is /.
/mnt may have been used for this purpose by some historical installation systems, as well as for removable media ... | What are the FHS compliant mount points? |
1,303,114,106,000 |
I am installing a custom package to /opt/package_name, storing configuration files in /etc/opt/package_name and static files in /var/opt/package_name/static/ - all following the conventions suggested by FHS. [1] [2] [3]
I also need to store some logfiles. I want them to be discoverable by analysis tools, so they shoul... |
I would place them in /var/log/package_name; it satisfies the principle of least surprise better than /var/opt/package_name/log. I don't have a citation for this; it simply matches where I'd look for logs.
I might also forego writing my own log files, and instead log to syslog with an appropriate tag and facility; if ... | Where should an /opt package write logs? |
1,303,114,106,000 |
I want to synchronize processes based on lock files (/ socket files). These files should only be removable by their creator user.
There are plenty of choices:
/dev/shm
/var/lock
/run/lock
/run/user/<UID>
/tmp
What's the best location for this purpose? And what way are above locations meant to be used for?
|
/dev/shm : It is nothing but implementation of traditional shared memory concept. It is an efficient means of passing data between programs. One program will create a memory portion, which other processes (if permitted) can access. This will result into speeding up things.
/run/lock (formerly /var/lock) contains lock... | Linux file hierarchy - what's the best location to store lockfiles? |
1,303,114,106,000 |
I saw that in /lib/modules/ I have 7 directories that related to the out of date kernel versions, can I fully delete them? It will not make any changes or hurt my system?
$ ls /lib/modules
5.4.0-26-generic 5.4.0-31-generic 5.4.0-37-generic 5.4.0-40-generic
5.4.0-29-generic 5.4.0-33-generic 5.4.0-39-generic 5.4.0... |
You should run
dpkg -S /lib/modules/*
to check whether any installed package matches those directories. You can delete any directory for which the above says
dpkg-query: no path found matching pattern /lib/modules/...
For directories still matching a package, you should remove the corresponding package first. If you... | Can I remove all the recent kernel versions at /lib/modules/ |
1,303,114,106,000 |
I'm quite new in Linux world, and now I'm trying to understand FHS principles.
In /var/run I found about ten *.pid files like crond.pid which contain just PIDs.
There are more than ten processes running in the system and just ten files.
So what is their purpose and what generated them?
|
The purpose of these files is to provide an easy means for other processes to communicate with them (e.g. send signals). This only makes sense for long running services, that’s why you find much less such files than processes running.
Usually those files are created by the service they represent, you will find a param... | What is the meaning/purpose of *.pid files in /var/run |
1,303,114,106,000 |
According with the FHS about /dev at:
6.1.3. /dev : Devices and special files
it contains:
The following devices must exist under /dev.
/dev/null
All data written to this device is discarded. A read from this device will return an EOF condition.
/dev/zero
This device is a source of zeroed out data. All... |
If you're using Linux, it's never "mandatory" to redirect to /dev/null instead of /dev/zero. As you've noticed, you'll get the same result either way.
That said, you should always redirect to /dev/null if you're discarding data. Because everyone understands that writing to /dev/null means throwing the data away; it's ... | When is mandatory use /dev/zero over /dev/null for write/discard purpose? |
1,303,114,106,000 |
As far as I understand, the traditional place for home directories is beneath /home. Some Linux variants seem to keep them in /var/home, what's the reason for that?
|
My guess is that WebOS is designed to be installed on two different filesystems, a root filesystem that is read-only in normal operation and a filesystem mounted on /var that is read-write in normal operation. Since home directories need to be writable, they are placed somewhere under /var. This kind of setup is fairl... | Why would I keep home directories in /var/home? |
1,303,114,106,000 |
The Filesystem Hierarchy Standard says where to put stuff in a UNIX distribution.
Is the FHS used/designed for use outside of GNU/Linux, or is it mostly limited to GNU/Linux?
|
According to the Wikipedia page the standard is for "Unix and Unix-like operating systems". While it may have grown out of a predominantly GNU/Linux environment, the intention seems to have consistently positioned it as focused on the broader *nix world.
The first version, originally bearing the catchy name, FSSTND, w... | Is the Filesystem Hierarchy Standard a UNIX standard or a GNU/Linux standard? |
1,303,114,106,000 |
It appears that the Postgresql installation is split into three folder locations on Debian:
Configuration: /etc/postgresql
Binaries: /usr/lib/postgresql
Data: /var/lib/postgresql
I understand the benefits of splitting up the configuration files and the data, however, the binaries location is confusing to me -- why w... |
This splitting is pretty typical for most services. I'm on Fedora but most distributions do the same in terms of organizing files based on their type, into designated areas.
Taking a look at the Postgres SQL server:
The configuration files go into /etc/
Executables go into /usr/bin
Libraries go into /usr/lib64/pgsql/... | Logic behind Postgres binary installation path on Debian |
1,303,114,106,000 |
I've been scratching my head over the File System Hierarchy Standard recently and in numerous occasion, when talking about the /usr/local directory, I came across the term "locally installed packages". Could someone please explain what is exactly meant by "local" in this context?
|
A locally installed package under /usr/local, or /opt per the FHS standard, means packages not installed by the default distribution, but packages installed specifically for that system.
The directories /opt/bin, /opt/doc, /opt/include, /opt/info, /opt/lib,
and /opt/man are reserved for local system administrator use... | What is meant by "locally installed package" in the world of Unix? |
1,303,114,106,000 |
I'm building some rpm packages and checking for standards and style conformance using rpmlint. The packages are specific to systems at my place of work and they won't get pushed upstream. Our packages include a variety of software, including in-house software, patched versions of software from the repositories, and ... |
rpmlint is a tool to check RPMs against some sort of packaging policy. Its configuration is typically distribution dependant and it checks packages against the particular distribution policy. Checking your own packages is fine as long as this is what you want.
If your policy differs from the distribution policy, you e... | Why is "dir-or-file-in-usr-local" an error rather than a warning? |
1,303,114,106,000 |
Under the FHS, system packages (e.g. RPMs) install libraries to /usr/lib (or /usr/lib64).
Similarly, libraries compiled using the old "configure;make;make install" routine, which are not part of the system distribution, by default get installed to /usr/local/lib (or /usr/local/lib64).
In general it is considered bad ... |
It has been suggested that /usr/local/lib should be on the default path and it should be considered a 'bug' in Linux variants like Red Hat where it isn't.
This answer https://stackoverflow.com/a/17653893
points out the salient parts of http://linuxmafia.com/faq/Admin/ld-lib-path.html
Many Red Hat-derived distributio... | Why isn't /usr/local/lib on the library path by default? [closed] |
1,303,114,106,000 |
If I'm installing from source, do I need to keep the extracted tarball directory? So if I download the git tarball. I then do:
tar -xvzf git.tar.gz
This will create a git.x.x. directory, into which I cd, then run ./configure etc. Once I'm done with this process, and git, or whatever is installed, do I need to keep t... |
You don't need to keep it. However, you may want to keep the package tarball itself for:
make uninstall
Generally source packages have this as a make target so that you can tidily remove the package from your system if desired. It should not depend on preserving the state of the build, so you can erase the director... | Installing from source - do I need to keep the extracted tarball directory |
1,303,114,106,000 |
This systemd wiki page about the /usr merge, under Myth #6, states that /bin has traditionally been a symlink to /usr/bin on System V UNIX.
What is the motivation for this? For backwards compatibility it makes sense, but I don't understand why it was like this in the early days. (Or, am I misunderstanding? Did early U... |
The short answers are, yes, it was done for compatibility (lots of programs referenced /bin/sh and /bin/ed), and in the early days /bin and /usr/bin contained totally disjoint sets of files. /bin was on the root filesystem, a small disk that the computer's boot firmware had to be able to access, and held the more crit... | Why does System V traditionally symlink /bin to /usr/bin? |
1,303,114,106,000 |
My objective is to have the physical storage for the Linux FHS read/write directories (/home, /srv, /tmp, /var) on a separate (logical or physical) disk from the potentially read-only rest of the root file system.
I know I can create four partitions on my second disk and use each partition for one of the beforemention... |
One option is to use a distro with a merged /usr; then you can mount /usr RO and the rest RW, and have most of the relevant stuff RO. This doesn't catch /etc, though, which you might want. Not quite a solution, more a workaround.
Another is to make a single BTRFS volume with subvolumes for all the mounts you want, the... | How to split FHS read-only and read/write directories across two disks with Linux/systemd, without partitioning the raed/write disk? |
1,303,114,106,000 |
I'm working on a FHS2-conforming application that used to store data in $sharedstatedir (i.e. $(prefix)/com, e.g. /usr/local/com).
This directory is no more in FHS 3.0, and it seems that we need to start using either
/var/lib, which should store
Variable state information
or more verbosely,
state information perta... |
You should choose /var/lib.
/usr/com does not exist in FHS 2.3 or FHS 3. FHS 2.3 FHS 3.0
sharedstatedir is a concept in GNU autotools and GNU coding standards
GNU and freestandards.org do not always align.
The issue you mention came up in a 2006 mailing list post. In the case of Red Hat, the conclusion was to use /v... | Where to store shared data in FHS 3.0? |
1,303,114,106,000 |
I notice on my system (Manjaro Linux) that:
I have an empty directory named /net
This directory is not mentioned in the Filesystem Hierarchy Standard
What is the intention behind this directory (quoting chapter and verse)?
Is it like /mnt (which is for temporary mounts) but for network (eg sshfs, nfs) mountpoints?... |
Yes, it is very similar to /mnt and is designed to contain nfs shared directories from remote hosts.
If there is a NFS server named nfsserver sharing a directory named shared-directory, you can access it just by listing or reading files in /net/nfsserver/shared-directory[/filepath].
This featured is provided by the au... | Purpose of /net directory |
1,451,398,260,000 |
Reading Filesystem Hierarchy Standard I was considering those directories:
/opt: Optional application software packages.
/home: Users' home directories, containing saved files, personal settings, etc.
I was more inclined to use /opt but many tutorials use /home (e.g. Archlinux wiki)
Question
Where should I install ... |
Considering /home is generally used for end users' home directories, it is not a good practice to mount general use filesystems in /home, as it may lead to a confusion later on with other sysadmins, whom, one day, will take over this system from you upon your departure for greener pastures.
I am not familiar with seaf... | Where should I install seafile-server: /opt or /home? |
1,451,398,260,000 |
The Linux FHS (Filesystem Hierarchy Standard) refers to directories of the following form:
/lib<qual>
It describes such directories as follows:
There may be one or more variants of the /lib directory on systems which support more than one binary format requiring separate libraries.
Similarly, it refers to director... |
"Qualifier"
a word or phrase, especially an adjective, used to attribute a quality to another word, especially a noun.
(in systemic grammar) a word or phrase added after a noun to qualify its meaning.
The strings 32 and 64 are qualifiers to the path /usr/lib that qualifies the path's use. With 32, making it /usr/lib... | What does <qual> stand for in the FHS? |
1,451,398,260,000 |
I want to add some scripts for custom administrative work to a Linux server (Ubuntu 12.04). Ultimately those scripts are callback scripts from at least one daemon (PostgreSQL in my case but that shouldn't matter). In order for the daemon to find my script, I must provide the full path; I used /opt/<package>/bin as per... |
When I add that path to PATH in /etc/environment, the user can call the script without providing the full path but the daemon can not; it just says "not found".
According to this source, which is IBM AIX documentation (I could not find anything else) but is presumably true in general:1
The first file that the oper... | How to add new elements to PATH for daemons (or other best practices)? |
1,451,398,260,000 |
I need to ensure that, when deleting a specific user from a system, all of his/her files are removed. User creation/deletion will happen a lot on this system, so I want to reuse UID's and want to ensure the new user does not have access to any files of the old user.
My question is two-fold:
Is there a general and eas... |
I did a bit of research of my own. Main source: http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/c23.html
Long story short: there is nothing that prohibits a user from creating files. However, in standard linux FHS, only some directories are writeable by everyone. As long as you use a distribution that follows ... | Which directories are writeable in a system following FHS? |
1,451,398,260,000 |
I have a PHP script running on my LAMP server that requires certain files in order to produce HTML content. The script is publicly accessible (i.e. http://example.com/script.php) but the files required by the script must secured. I could probably place the files in any directory other than /var/www and they would be r... |
In /var/www, create a folder public_html and reconfigure that as your root directory for Apache. Files in /var/www can be included, but not accessed directly.
| Where to securely place files needed by PHP in Linux filesystem (according to FHS) |
1,451,398,260,000 |
I'm quite new in the UNIX world, so feel free to let me know if my question is silly.
So-called Filesystem Hierarchy Standard states that the /var directory is supposed to keep data like logs and caches of including but not limited to local packages:
/var contains variable data files. This includes spool directories... |
/var is kind of global directory for a system, and all cache-data and logs of all users appear to be shared among them.
This is partially incorrect. Not all cache and logs are stored under /var, and what is stored there is not necessarily shared by all users. Applications and/or the OS own what is stored in /var.
Th... | Why isn't the var directory user-specific? |
1,451,398,260,000 |
I have recently created my first custom systemd service to run a script early in my machine's boot sequence. The custom .service file is being copied to /etc/systemd/system, which I understand to be the correct location for custom services which are not deployed via packages or part of the operating system distributio... |
You are exactly right about /etc/systemd/system/*.service being an appropriate place for your custom service file.
As for your script, put it in /usr/local/... instead of /usr/.... That's because this script is written by you. Here are some reasons why this convention exists:
Files in /usr/{bin,lib,share}/ are owne... | Where should a shell script for a custom systemd service be installed? |
1,451,398,260,000 |
When I was studying bash, I found it very helpful to go and study the bash scripts already present on a clean install of Linux—/etc/profile, for instance, and anything in /etc/rc.d/init.d/. These are often quite advanced scripts, and by studying them I ensured I learned about many obscure features not covered in most... |
Try:
grep -w sed /etc/init.d/*
grep -w sed /etc/grub.d/*
grep -w sed /usr/bin/*
The first yields 25 scripts and the second 47 on my system (debian).
The -w option restricts grep to looking for sed as a whole word. This way, matches to words like used or supposedly are avoided.
| Are there any sed scripts built in to mainstream Linux distros? |
1,451,398,260,000 |
I have some sources I want to compile using make. The sources will be compiled into a driver I'm going to use. What is the correct place for such files? /usr/share? /opt? /usr/local/...?
Edit: the driver is going to be a kernel driver, and I'll be using dkms for the installation. The distro I'll be using is Ubuntu, bu... |
It's really up to you but normally sources are stored in /usr/src as mentioned in the comments. Since system-wide installed applications could install their sources in this directory as well, to avoid possible conflicts, you could use /usr/local/src instead but again in the end no one stops you from storing sources an... | What is the correct place for driver sources? |
1,451,398,260,000 |
I just noticed that the /root/ has 700 permission by default on Ubuntu, Debian as well as Nixos. Why is this handled differently than other directories for example /bin/?
What is so special about /root/ besides just being the home directory of the root user?
I wanted to give a user permission to view a directory with... |
It is of course possible to change this permission but inadvisable.
The basic principle here is that root is NOT to be used as a regular user. You only login as root to perform security sensitive operations such as system upgrades. Therefore anything you must do as root should not in general be viewable by other use... | Why does the /root/ directory have 700 permission by default? |
1,451,398,260,000 |
I created some scripts for administrative tasks etc, I made them to be independent from environment - every dependency is injected through arguments. However it is annoying to provide to script commonly used dependencies every time I run it, and I don't want to hardcode in it any local information, so I created wrappe... |
Forget the wrapper stuff:-)
All you need is a .file (dot file) with the user configuration options, in the $USER directoy. You can have one in /etc for system wide config options as well.
Make your script check for these .fils (dot file) and if they exist, use them.
HTH,
.
| Where to put wrapper scripts? |
1,451,398,260,000 |
Possible Duplicate:
Resources to learn linux architecture in detail?
I migrated to UNIX (Linux, Ubuntu) and I'm trying to understand the organisation of files and directories. I stumbled upon File Hierarchy Standard (quite old it seems) and it made me wonder if this is the ACTUAL standard that is used.
Also may I ... |
Here it is: The FHS 2.3 Specification
| Where can I find the Official File Hierarchy Standard for UNIX? [duplicate] |
1,451,398,260,000 |
Is it safe to remove /usr/lib32, /usr/libx32 directories and their links on /lib32, libx32, on 64bit only (no multiarch enabled) Debian Linux 10? They are empty.
Since this new file system hierarchy is used, I'm considering removing them to reduce clutter in /.
|
Yes, if they are empty, it’s safe to remove them. If you actually install packages which ship them (e.g. libc6-x32) and remove them, the directories are removed; so removing them manually in your case is fine.
| Is it safe to remove /usr/lib32 and /usr/libx32, on 64bit only Debian Linux 10 |
1,451,398,260,000 |
I have a bit of a struggle with using avrdude to flash my microcontroller.
It dependends of libm.so.6 GLIBC_2.29 which it cannot find. It looks under /usr/lib/libm.so.6 where this file does actually resides BUT it also resides in /lib/lib.so.6.
So as I was running
sudo pacman -S glibc
to install/update the library... |
Please note that the installed glibc is an incomplete C runtime.
In order to complete the C runtime you may need to copy in
additional headers that match the compiler you are using since the use
of --sysroot will restrict their lookup to the sysroot.
It is very possible to have multiple versions of glibc on th... | GLIBC_2.29 can not be found for avrdude even after downloading it |
1,451,398,260,000 |
Is file /etc/vfstab Solaris specific. I mean it only exists in SunOS/Solaris and there is no such file in other UNIX-es/Linux/*BSD.
|
No. /etc/vfstab is used by Solaris but it is specific to all SVR4 systems.
This is the equivalent of the UNIX-es/Linux/*BSD /etc/fstab. In fact the old SunOS 4.x was using /etc/fstab as well.
Here is a small list of known equivalent for /etc/fstab used by other proprietary OS:
IBM AIX (3.x and 4.x): /etc/filesystems
... | Is file /etc/vfstab Solaris specific? |
1,451,398,260,000 |
I read an article and it states that "bin" "dev" "etc" "lib" "root" "sbin" directories should be in the same filesystem as the root directory, that is, they should not be mounted as a separate filesystem.
I'm a little confused, for example, in many distributions now the "sbin" "bin" and "lib" directories are symbolic ... |
The current line of thought is that /usr should be integrated to /, and a few distributions simply symlink /bin,/sbin,/lib to the equivalents in /usr as you saw. E.g. Debian, which will only support merged /usr starting with the next release (bookworm), and Fedora appears to have done the merge in Fedora 17, already i... | Which directories should be on the same filesystem as the root "/" filesystem? |
1,451,398,260,000 |
I'm building a Linux system that doesn't have a /usr directory. Getting the toolchain to work was surprisingly easy, but I'm hitting this irritation with a lot of auto* scripts: configure, etc. often seem to assume env is in /usr/bin.
A workaround is to do ln -sv .. /usr during the build, but obviously that's aestheti... |
You may find /usr unaesthetic, but that is the way the universe works. Almost every Unix out there has /usr/bin/env — as far as I know, the only extant Unix that doesn't is SCO OpenServer, and it's not a big extant. By not having /usr/bin/env, you aren't just violating the FHS, you're violating an extremely widespread... | Hardcoded /usr/bin/env in configure scripts |
1,451,398,260,000 |
Aside from the kernel itself, the Filesystem Hierarchy Standard is perhaps the only major feature common to all linux systems. Some obscure distributions modify it only slightly: stali, for example, uses a simplified version, while nixos adds too it (leaving /etc and /bin out of sight and out of direct control). Both,... |
Does the kernel assume it's existence?
No; the kernel assumes very little about the contents of the file systems it’s used with. The kernel will look for /etc/init in some circumstances (along with /sbin/init etc.), and a few staging drivers use helpers in etc, but the kernel will work fine without /etc.
GLibc cert... | What if I wanted /etc to be called something else? |
1,451,398,260,000 |
FHS-3.0 describes it as:
Shareable, readonly data. That means that /usr should be shareable between various FHS-compliant hosts and must not be written to.
I am a bit confused by what this means. Does this means that the binaries or whatever other files inside should be copy-pasteable onto another machine, and have ... |
I think what it means is only that distros shouldn't assume that an installation has sole ownership of /usr, not that everything in /usr is expected to work with all FHS-compliant systems. I think I have heard of /usr being served over the network (via NFS for example) for a bunch of systems running the same distro. S... | What is the /usr directory in Linux? |
1,451,398,260,000 |
Lintian tag description:
The Filesystem Hierarchy Standard forbids the installation of new directories in /usr/bin other than /usr/bin/mh.
However, all I can find the linked document is
This is the primary directory of executable commands on the system.
This allows executable commands to go there, but it does not... |
Section 4.4.2 of the FHS, version 3.0, specifically states
There must be no subdirectories in /usr/bin.
Since you’re using Lintian, I suppose you’re targeting Debian or a derivative; in such an environment, the appropriate location for your binaries is a package-specific subdirectory of /usr/lib. Debian and its deri... | Is subdirectory in /usr/bin really forbidden by FHS |
1,451,398,260,000 |
Where should I deploy application plugins? Nobody will ever use them. Does it make sense to put them in /usr/lib?
|
Yes, it makes sense to put them in /usr/lib, at least in some cases. According to the FHS, you should use an application-specific directory under /usr/lib, e.g. /usr/lib/yourapp. You can structure content there however you wish (see The Gimp, whose plugins end up in /usr/lib/gimp/2.0/plug-ins, and many other examples ... | Where to place application plugins (.so)? |
1,451,398,260,000 |
I would previously just use /tmp however this seems to persist after boot, it also seems to be have the disadvantage about literally writing to the disk as opposed to a ramdisk / tmpfs.
I thought perhaps /run/ but this seems (at least on my Nixos system) to be owned by the root user.
Is there any recommended directory... |
On any systemd-based system, the location matching your requirements most closely is your subdirectory of /run/user, or rather, the directory indicated by $XDG_RUNTIME_DIR. This is flushed whenever the owning user session stops (typically, when the user logs out).
As far as the FHS goes, it doesn’t specify storage pro... | Is there a recommended path for storing temporary files in a tmpfs/ramdisk which also does not need to be persisted after boot? |
1,451,398,260,000 |
I was searching for the configuration for purging the /tmp and /var/tmp directories on a CentOS 7 default installation. After some searching, I came across the file /usr/lib/tmpfiles.d/tmp.conf which contains the actual retention periods.
I'm interested to learn the logic behind that file's placement. How could I hav... |
How could I have deduced that location without random googling, given that there is no unit called "tmpfiles"?
% apropos tmp -l
systemd-gpt-auto-generator (8) - Generator for automatically discovering and mounting root, /home/, /srv/, /var/ and /var/tmp/ partitions, as well as discovering and enabling swap partition... | Systemd: Logic behind configuration files in /usr/lib/ |
1,451,398,260,000 |
I have some sshfs mounts which I want to put in a Linux filesystem location following the Filesystem Hierarchy Standard.
The standard is strangely silent on where network mounts should be placed:
media Mount point for removeable media
mnt Mount point for mounting a filesystem temporarily
Mounting under /net ... |
The FHS is defining directory names and usage. Creating a custom directory directly under the root one is considered risky as it might conflict with a future version of the standard or with a new OS owned directory.
Unlike many other Unix and Unix like OSes file system standards (e.g. freeBSD and Solaris), the FHS fai... | Where should sshfs mounts be placed in the filesystem? |
1,451,398,260,000 |
I am writing a piece of software (C++) which generates Python scripts.
Where should these temporarily existing scripts be placed in the file system?
I read a couple pages about the Filesystem Hierarchy Standard, but I didn't find any reference to generated scripts.
/usr/bin does not seem to be a good idea as it might ... |
Temporary files whose lifetime doesn't exceed that of the program that creates them, and in particular aren't supposed to survive a reboot, go into /tmp. Or rather, the convention is to use the directory indicated by the environment variable TMPDIR, and fall back to /tmp if it isn't set.
You can execute files in /tmp.... | Where should generated scripts be placed in the filesystem? |
1,451,398,260,000 |
In Filesystem Hierarchy Standard it is said as to the /boot folder that it must contain static files of the boot loader. And there is another rule which states that
Programs necessary to arrange for the boot loader to be able to boot a
file must be placed in /sbin.
Can someone explain what this line is about, probab... |
The FHS also says "/boot stores data that is used before the kernel begins executing user-mode programs".
In case of GNU GRUB, the GRUB modules (normal.mod for example) are stored in a sub-directory of /boot, specifically at /boot/grub/<GRUB architecture name>/.
Programs necessary to arrange for the boot loader to b... | Misunderstanding of a rule about /boot folder (FHS) |
1,354,360,686,000 |
Is it possible to compare two directories with rsync and only print the differences? There's a dry-run option, but when I increase verbosity to a certain level, every file compared is shown.
ls -alR and diff is no option here, since there are hardlinks in the source making every line different. (Of course, I could del... |
You will propably have to run something like
rsync -avun --delete in both directions.
But what are you actually trying to accomplish?
Update:
rsync -avun --delete $TARGET $SOURCE |grep "^deleting "
will give you a list of files that do not exist in the target-directory.
"grep delet" because each line prints : deleti... | rsync compare directories? |
1,354,360,686,000 |
With
diff -r
I can do this task, however it takes so long because diff checks file's content.
I want something that determine that two files are the same regarding of their size, last modified, etc. But no checking bit by bit the file (for example a video takes sooo long).
Is there any other way?
|
rsync compares only metadata by default.
rsync -n -a -i --delete source/ target/
explanation:
-n compare but do not actually copy or delete <-- THIS IS IMPORTANT!!1
-a compare all metadata
-i print one line of information per file
--delete also report files which are in target but not in source
note: it is importan... | Compare directories but not content of files |
1,354,360,686,000 |
Tools like fdupes are ridiculous overkill when dealing with jpg or h264 compressed files. Two such files having the exact same filesize is already a pretty good indication of them being identical.
If, say, in addition to that, 16 equidistant chunks of 16 bytes are extracted and compared and they are the same as well t... |
czkawka is an open source tool which was created to find duplicate files (and images, videos or music) and present them through command-line or graphical interfaces, with an emphasis on speed. This part from the documentation may interest you:
Faster scanning for big number of duplicates
By default for all files grou... | Is there a tool or script that can very quickly find duplicates by only comparing filesize and a small fraction of the file contents? |
1,354,360,686,000 |
I have two files.
File 1:
A0001 C001
B0003 C896
A0024 C234
.
B1542 C231
.
upto 28412 such lines
File 2:
A0001
A0024
B1542
.
.
and 12000 such lines.
I want to compare File 2 against File 1 and store the matching lines from File 1. I tried Perl and Bash but none seems to be working.
The latest thing I tried was s... |
You can use awk:
$ awk 'FNR==NR{a[$1];next}($1 in a){print}' file2 file1
A0001 C001
A0024 C234
B1542 C231
| Compare two files for matching lines and store positive results [duplicate] |
1,354,360,686,000 |
I am trying to find a way to determine if a text file is a subset of another..
For example:
foo
bar
is a subset of
foo
bar
pluto
While:
foo
pluto
and
foo
bar
are not a subset of each other...
Is there a way to do this with a command?
This check must be a cross check, and it has to return:
file1 subset of file2 : ... |
If those file contents are called file1, file2 and file3 in order of appearance, then you can do it with the following one-liner:
# python3 -c "x=open('file1', mode='rb').read(); y=open('file2', mode='rb').read(); print(x in y or y in x)"
True
# python3 -c "x=open('file2', mode='rb').read(); y=open('file1', mode='r... | How to know if a text file is a subset of another |
1,354,360,686,000 |
I have two files that essentially contain a memory dumps in a hex format. At the moment I use diff to see if the files are different and where the differences are. However, this can be misleading when trying to determine the exact location (i.e. memory address) of the difference. Consider the following example showing... |
This could be an approach:
diff <(nl file1) <(nl file2)
With nl number the lines that diff recognizes the lines line by line.
| Compare two files strictly line-by-line, without insertions or deletions |
1,354,360,686,000 |
I am trying to save space while doing a "dumb" backup by simply dumping data into a text file. My backup script is executed daily and looks like this:
Create a directory named after the backup date.
Dump some data into a text file "$name".
If the file is valid, gzip it: gzip "$name". Otherwise, rm "$name".
Now I wan... |
@deroberts answer is great, though I want to share some other information that I have found.
gzip -l -v
gzip-compressed files contain already a hash (not secure though, see this SO post):
$ echo something > foo
$ gzip foo
$ gzip -v -l foo.gz
method crc date time compressed uncompressed ratio u... | How can I check if two gzipped files are equal? |
1,354,360,686,000 |
I have two files with sizes 124665 and 124858 in bytes and want to check whether file1 is a prefix of file2 or not.
|
Supposing you have the size of file1 in the variable FILE1_SZ and your head implementation supports the (non-standard) -c option:
if head -c "$FILE1_SZ" file2 | cmp -s - file1; then
echo "file1 is a prefix of file2"
else
echo "file1 is not a prefix of file2"
fi
| How to check whether file1 is a prefix of file2? |
1,354,360,686,000 |
Will it be possible to use diff on a specific columns in a file?
file1
Something 123 item1
Something 456 item2
Something 768 item3
Something 353 item4
file2
Another 123 stuff1
Another 193 stuff2
Another 783 stuff3
Another 353 stuff4
output(Expected)
Something 456 item2
Something 768 item3
Another 193... |
awk is a better tool for comparing columns of files. See, for example, the answer to: compare two columns of different files and print if it matches -- there are similar answers out there for printing lines for matching columns.
Since you want to print lines that don't match, we can create an awk command that prints t... | Using Diff on a specific column in a file |
1,354,360,686,000 |
I'd like to compare directories with binary files. Actually, I'm not interested in what the actual differences between files are, but to know if there's a differ (and what files differ). Previously I used meld, but it's cannot compare binary files.
What such file comparison tool can do this?
NOTE: It doesn't matter if... |
This can easily be done with diff. For example:
$ ls -l foo/
total 2132
-rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:13 bash
-rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:13 bash2
-rwxr-xr-x 1 terdon terdon 118280 Nov 18 13:13 ls
$ ls -l bar/
total 1124
-rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:14 bash
-rwxr-xr-x ... | How to compare directories with binary files |
1,354,360,686,000 |
In Ubuntu, is there any to find duplicate folders in a directory (i. e., folders with the same content)? I think there are already some command-line tools available for finding duplicate files (such as fdupes), but I want to find duplicate folders instead. That is, find folders which match in terms of the contents of... |
#!/bin/bash
shopt -s dotglob
for file in "$1"/*; do [[ -f "$file" ]] && d1+=( "$(md5sum < "$file")" ); done
for file in "$2"/*; do [[ -f "$file" ]] && d2+=( "$(md5sum < "$file")" ); done
[[ "$(sort <<< "${d1[*]}")" == "$(sort <<< "${d2[*]}")" ]] && echo "Same" || echo "Different"
You can see it in action here:
$ m... | Find all folders in a directory with the same content |
1,354,360,686,000 |
When I set the -s parameter, diff also print files, that are different.
diff -s $FIRST_FILE $SECOND_FILE
|
One possible solution may be:
diff -s $FIRST_FILE $SECOND_FILE > /dev/null
if [ $? -eq 0 ]; then
echo "The files are identical"
fi
NOTE: It changed the question text.
| Silent result with two identical files in diff: how to show them? |
1,354,360,686,000 |
Suppose that I have the two files with the following content:
$ cat File1.txt
Apple
orange
watermelon
avocado
lime
$ cat File2.txt
orange
Apple
lime
watermelon
avocado
Basically, there is no difference, as both have same values.
I am using the diff command:
diff File1.txt File2.txt
and it shows files are different... |
Compare the sorted files.
In bash (or ksh or zsh), with a process substitution:
diff <(sort File1.txt) <(sort File2.txt)
In plain sh:
sort File1.txt >File1.txt.sorted
sort File1.txt >File2.txt.sorted
diff File1.txt.sorted File2.txt.sorted
To quickly see the differences between sorted files, comm can be useful: it sh... | I want to compare values of two files, but not based on position or sequence |
1,354,360,686,000 |
Suppose I have two files a.txt and b.txt.
I want to find all the words in a.txt which appear in b.txt.
Is there a specific command to do that?
|
With bash, zsh and some implementations of ksh:
comm -12 <(tr -s '[:space:]' '[\n*]' < a.txt | sort -u) \
<(tr -s '[:space:]' '[\n*]' < b.txt | sort -u)
There, word is a sequence of non-spacing character (beware that with GNU tr, that doesn't work with multi-byte spacing characters).
comm finds the common li... | finding all the words in a text file appearing in another text file |
1,354,360,686,000 |
I have a ~1GB image that I'm writing to a 8GB SD card via the dd tool. I'd like to verify that it was written without corruption by reading it back and comparing its hash with original one.
Obviously, when I read it back via dd the size of resulting image matches size of my SD card, therefore checking hashes are usele... |
Determine the size of the image, for example with \ls -l my.img (not ls -lh, that would give you an approximate size; \ls protects against an alias like ls='ls -h') or with stat -c %s my.img.
If you want to check the copy against the original just this once, then just compare the files. Using hashes is useless for a o... | How one can re-read image with dd so it will match one you just wrote? |
1,354,360,686,000 |
Consider for example a source code file, where the functions are drastically shuffled around. Is there is a command to check if the reordering of lines is the only change?
(that means no lines are added, removed or changed)
|
The simple answer is: "compare the sorted version of both files".
In bash:
diff <(sort file1) <(sort file2)
Obviously, this does not mean the two files have the same semantic as source files of a programming language (supposing are both syntactically correct).
| How to determine if file is just a permutation of another one? |
1,354,360,686,000 |
I need to compare two txt files. Every line of both txt files contain entries. One entry per line. The new file contains entries the old one lacks. I have tried to use diff and vimdiff but these don't work because the lines may be in different order.
For example:
OLD FILE
alpha
beta
gama
NEW FILE
delta
omega
beta
al... |
start cmd:> awk 'FNR == NR { oldfile[$0]=1; };
FNR != NR { if(oldfile[$0]==0) print; }' file1 file2
delta
omega
rho
phi
| Finding new lines in one file compared with another [duplicate] |
1,354,360,686,000 |
I have two large tab-delimited files (>10GB) and I know that when they're sorted, they're identical in content.
However, I'm interested in the order of rows and the index of the swapped ones when they share the same "key" (key here being defined as rows grouped based on Source and Location columns).
In other words, ro... |
This is one of those rare occasions when I'd probably use getline due to the size of your input files so we only save a handful of lines in memory at a time instead of >10G:
$ cat tst.awk
BEGIN {
OFS = "\t"
print "Group_Source:Location", "df1.index", "df2.index"
}
NR != FNR { exit }
{ srcLoc = $3 ":" $4 }
srcL... | Extract the indexes of rows that are swapped in order between two files |
1,354,360,686,000 |
File# 1:
test1,1
test2,2
test3
File# 2:
test2
test1
test4
Desired Output:
test4
|
You can use grep for this:
$ grep -vwf <(cut -d, -f1 file1) file2
test4
Explanation
grep options:
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-w, --word-regexp
Select only those lines containing matches that form
whole words.
-f FILE, --file=FILE
Ob... | Compare 2 files based on the first column and print the not matched |
1,354,360,686,000 |
I am looking from something which gives me an output of comm -3 on two sorted outputs (line-by-line comparison, only additional/missing lines from either side) but which looks more like the output from diff -y, e.g. in that it uses the whole width.
file1:
bar/a
bar/feugiat
bar/libero
bar/mauris
bar/scelerisque
bar/urn... |
You could pipe to:
expand -t "$((${COLUMNS:-$(tput cols)} / 2))"
Or for the angle brackets:
awk -v cols="${COLUMNS:-$(tput cols)}" '
BEGIN {width = cols/2-1; space = sprintf("%*s", width, "")}
/^\t/ {print space ">", substr($0, 2); next}
{printf "%-*s<\n", width, $0}'
If your tput doesn't output the number of ... | Naive line-by-line comparison like "comm -3" but looking like "diff -y" |
1,354,360,686,000 |
Can I compare two text files skipping N symbols from start of the each line?
For example file1:
2018-05-31 12:00:00 This is the first line of text.
2018-05-31 12:00:00 This is the second line of text.
2018-05-31 12:00:00 This is the third line of text.
2018-05-31 12:00:00 This is the forth line of text.
2018-05-31 12:... |
Using cut:
diff <(cut -c 20- file1) <(cut -c 20- file2)
Note: with GNU cut the -c character option actually works on bytes not characters, but this should be fine as long as your output starts with date/time stamps and not special characters.
| Compare text files skipping N symbols from each line |
1,354,360,686,000 |
$ cmp -b file1 file2
file1 file2 differ: 12 byte, line 2 is 154 l 151 i
in this response what do '154' and '151' refer to?
|
The GNU version of cmp (which you are using) prints the differing bytes when given the -b option. If no printable representation of the byte can be shown, cmp will display
[...] control bytes as a ^ followed by a letter of the alphabet and precede bytes that have the high bit set with M- (which stands for "meta").
... | `cmp -b file1 file2` responses: "file1 file2 differ: 12 byte, line 2 is 154 l 151 i", what is '154' and '151' in reference to? |
1,354,360,686,000 |
I want to quickly compare files in two different directories to see if the files are the same (same content). I want to see the results in Kompare (I'm on KDE - Kubuntu 12.04).
Here's my diff command:
diff -EwbBsy /directory/one /directory/two
(That command would suit me even better if it ignored any files in /direct... |
It doesn't seem to be able to handle the -y switch which does the side-by-side style of diff, but you can use the unified diff (-u). You can't mix these 2 styles so it's either -y or -u. So doing this worked for me:
$ diff -EwbBsu /directory/one /directory/two | kompare -o -
This will not show the entire file with th... | How to pipe diff into Kompare? |
1,354,360,686,000 |
How can I set custom application which is being invoked when I press "Differences" button in "File Conflict" dialog?
I did not find corresponding option in "File Management Preferences".
I did not find it using "dconf Editor" in org.mate.caja.*.
I did not find it in files located at /usr/share/caja and ~/.config/caja... |
Do you have meld installed? If so, the "Differences..." button is provided as part of meld's integration. To change the application invoked would apparently require uninstallation of meld (in which case the "Differences..." button will no longer be present) and installation of a custom application designed to similarl... | Set custom application for file comparison in caja |
1,354,360,686,000 |
What is an easy way I can compare the first 20 lines (or n lines) of two files?
I had set up an automated pg_dump, but it turns out the dumps being created are corrupt and now won't restore.
I still have a good dump file from a year ago, and I want to compare the first 20 lines between the two files.
What's an easy wa... |
Using a shell with process substitutions (<(...)), e.g. bash or zsh:
diff <( head -n 20 file1 ) <( head -n 20 file2 )
This run head -n 20 on each file to get the first 20 lines of each, in two separate process substitutions. Each process substitution will be expanded to the pathname of a file where the output of the... | Compare the first 20 lines of two files |
1,354,360,686,000 |
I have a command that produces a lists of strings followed by newlines, a, and a file containing a list of strings followed by newlines, b.txt. I need a command that calculates the symmetric difference of the output of a and contents of b.txt. Ideally this command should operate in a pipeline, as a is potentially very... |
Your sort solution may be a bit faster if you sort the files separately, then
use comm to find the non-common lines:
sort a.txt -o a.txt
sort b.txt -o b.txt
comm -3 a.txt b.txt | sed 's/^\t//'
Alternatively, if one of your data files is not too large, you can read it all into an associative array then compare the oth... | Symmetric Difference Pipe? |
1,601,408,329,000 |
I am mirroring a Subversion repository tag with svn2git and I want to be sure that when I checkout particular revisions, those I obtain from the git mirror match those from Subversion. My main problem is that subversion tags can be updated, and I need to ensure that checking out the matching tag in the git mirror, mat... |
diff -qrN is about as fast as it gets to compare two directory trees. The -q option makes it quit early when files differ. Since you expect the files to be identical most of the time, it doesn't matter all that much: the comparison tool has to read and compare the whole files anyway.
The only improvement you can make ... | What optimized tools are available for comparing directory contents? |
1,601,408,329,000 |
I have a folder.
I have one copy of this folder locally and one on a server. I edited my local folder as I wanted and then rsync it to the server.
Is there any way of comparing those two copies, local and remote, and get back a list of files that are on the remote one and not the local one?
|
The following rsync command executed on the local machine lists the files that exist on the remote host but not the local host.
rsync -av --dry-run --delete somedir/ user@remote:~/somedir/
The --dry-run switch only lists the files, without actually doing something, the --delete switch in combination with -v (verbose)... | Get files on remote copy but not local |
1,601,408,329,000 |
I have two folders with 200 txt files each, all files named like file1.txt, file2.txt, file3.txt, etc., on both folders.
Is there a way to use one command to compare file1 in both folders, file2 in both folders, etc., and list if they are the same or not? I just want to know which files are the same or not, not the di... |
The -q option to diff makes it only list the names of files with differences (or missing from one of the directories):
diff -q folder1 folder2
| Comparing a bunch of files on different folders |
1,601,408,329,000 |
Suppose I have same version of linux kernel but I changed some driver lines. Is there any way to compare these kernels and list the results. The result would be helpful to go back if I changed a lot in original drivers.
|
The traditional method:
diff -r dir1 dir2
That gives you a file-by-file difference, which can be kind of wordy. If you have Gnu diff,
you can try:
diff -r --brief dir1 dir2
| Compare two similar directories and list differences between files |
1,601,408,329,000 |
I have a hard time using Linux' built-in tools to rip an audio cd (sound juicer, rhythmbox). The reason likely being my drive, which vibrates a lot and cannot read the disk continuously. Playing the disk in any audio player results in short pauses and stutter-y playback. Ripping the CD results in noticeable artefacts.... |
To rip an audio CD you should really use a tool such as cdparanoia.
This will handle jitter and error correction, will retry as necessary, and try to create a "perfect" datastream.
Typically you would use this to create the wav files, which can then be converted to FLAC format as necessary.
There are other tools, incl... | How can I copy a .wav file from an audio cd and verify it? |
1,601,408,329,000 |
I have two home folders: /home/masi and /home/masi_backup and I would like to find the differences between files of the two directories.
Pseudocode
vimdiff <`ls -la /home/masi` <`ls -la /home/masi_backup`
How can you compare the differences of ownerships between the two directories?
|
Something like this:
vimdiff <(find /home/masi -printf "%P %u:%g %m\n" | sort) <(find /home/masi_backup -printf "%P %u:%g %m\n" | sort)
(this gives names without the leading /home/masi or /home/masi_backup, owning user and group, and permissions — the latter weren't mentioned in the question but seem useful, drop %m ... | Find differences of ownerships between two home folders? |
1,601,408,329,000 |
I'm completely new to bash. I have a requirement that needs to do the following:
Iterate through a directory A's and directory B's folders with the same name
Find two files that have the same name and compare them (im using diff <(file1) <(sort file2) to compare the files)
If there no differences delete the file in ... |
You can do something like this:
for file in /path/to/dirA/*; do
fileName=${file##*/}
diff -q <(sort "$file") <(sort /path/to/dirB/"$fileName") &&
rm /path/to/dirB/"$fileName"
done
That will iterate over all files in dirA, saving each as $file. Note that $file will include the path, so it will be /path/to... | Delete file when there is no difference |
1,601,408,329,000 |
I got a requirement where I need to compare two files wrt to each columns and write the corresponding difference in another file along with some identification showing mismatched columns. Pointing out the mismatched columns is my main problem statement. For example we have files like:
File 1
1|piyush|bangalore|dev
1|... |
Python 3.x solution:
diff_marked.py script:
import sys
file1_name = sys.argv[1]
file2_name = sys.argv[2]
with open(file1_name, 'r') as f1, open(file2_name, 'r') as f2:
f1_lines = f1.readlines() # list of lines of File1
f2_lines = f2.readlines() # list of lines of File2
for k,l in enumerate(f1_lines):
... | Comparing two files and writing mismatched rows along with mismatched columns. Pointing out the mismatched columns is my main problem statement |
1,601,408,329,000 |
I have a list from an inventory and another list from management. I'm trying to find the IP's that are similar between both files then output that is similar into another file:
I tried using diff but, the output did not made sense.
diff -buy list1 list2
then I tried to use egrep using IP's from list 1but, I think I... |
Solution in bash or a similar shell with process substitution using the <(...) form:
comm -1 -2 <(sort list1) <(sort list2)
Should you have duplicate entries in list2 then add the -u option to the sort call.
| Compare different IPs in two files? [closed] |
1,601,408,329,000 |
I have two files:
aaaa 11 0.4 12 0.2
aaab 40 0.1 99 0.2 69 0.3
aaac 222 0.5 21 0.3
aaad 2 0.1
aaae 33 0.3
....
and
aaaa
aaac
aaae
....
I need to compare the first column of first file with second file and if a element is present in second file, write each line of the first file to a separate file. I have a script th... |
With those files, you could use grep like:
grep -wf file2 file1
though you'll need to dos2unix file2 first since it has \r characters at the end.
This will match whole words with -w and read the patterns from the file with -f. This would actually match the patterns anywhere in the line, but with the sample input you... | Comparing single column of a file with another |
1,601,408,329,000 |
I have a directory sub1 with the following files:
$ wc -l *
5 file1.csv
5 file3.csv
1 file4.csv
In sub2, I have the following:
$ wc -l *
5 file1.csv
5 file2.csv
1 file3.csv
5 file4.csv
1 file5.csv
In the first directory, I might have files with added lines, which then go to the second dir. In this example, I might ... |
Here is a quick and dirty shell "one-liner" with example output:
$ join -j2 <(cd sub1; wc -l *) <(cd sub2; wc -l *) | awk '$2!=$3'
file3.csv 5 1
file4.csv 1 5
total 11 17
The total line is an artifact from the output of wc. It can be removed with another filter:
$ join -j2 <(cd sub1; wc -l *) <(cd sub2; wc -l *) | aw... | How to find files with same name but different line count in two directories? |
1,601,408,329,000 |
I have a file (call it A, for reference) that may be a fragment of some other extant file on my system. I can't use cmp because I don't know how many bytes may be missing from the start of A (or, at least, I can't use it without brute forcing through the -i flag). Is there a way for me to discover whether A is already... |
Not knowing how big the chunk (A) is ... have you considered grep'ing for its content using -a?
| binary compare two files, failing only if first never matches any part of the second |
1,601,408,329,000 |
I have 2 files, each containing the same amount of 4-lines records, in the same order:
fileA:
record1 line1=header
record1 line2 X <= this is different but should be ignored
record1 line3 id ABC
record1 line4
record2 line1=header
record2 line2
record2 line3 id DEF <= this is different
record2 line4
fileB:
record1 lin... |
For your updated input, based strictly on 4-line records, you can use modulo arithmetic to maintain arrays of the current records, and check the 3rd lines for a match every 4th line:
$ awk '
{a[FNR%4] = $0; getline b[FNR%4] < "fileB"}
!(FNR%4) && b[3] != a[3] {
for(i=0;i<4;i++) print b[i%4]
}
' fi... | Compare every nth line in 2 files and save (asymmetric) context |
1,601,408,329,000 |
In a Unix command line context I would like to compare two truly huge files (around 1TB each), preferable with a progress indicator.
I have tried diff and cmp, and they both crashed the system (macOS Mojave), let alone giving me a progress bar.
What's the best way to compare these very large files?
Additional Details:... |
You can use pv as a progress indicator, and pipe that to the shasum function to check the hash to see if they are identical.
pv file1 | shasum
1.08MiB 0:00:00 [57.5MiB/s] [====================================>] 100%
303462e848ecbec5f8ab12718fa6239713eda1c6 -
pv file2 | shasum
1.08MiB 0:00:00 [57.5MiB/s] ... | How to compare huge files with progress information |
1,601,408,329,000 |
File 1:
happy
sad
calm
palm
File 2:
palm
dream
calm
I want to compare the two files and display only those line that are common in both the files, but I want to maintain the order of File 2. My output should be:
palm
calm
I know I can use comm after sorting the files but I want to maintain the order. Is there any w... |
Use grep:
$ grep -Ff f1 f2
palm
calm
man grep:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings (instead of regular
expressions), separated by newlines, any of which is to be
matched.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. If ... | Compare two files line by line without comm (I need to maintain order of file 1) |
1,601,408,329,000 |
I have 2 directories
$ tree dir{1..2}
dir1
├── file1
└── file2
dir2
├── file1
└── file2
I want to compare all files in dir1 with all files in dir2 using ansible
and print differences like this
output:
${file1} from ${dir1}:
diff content
${file1} from ${dir2}:
diff content
and it will loop through all files to print... |
For example, given the files
shell> ssh admin@test_11 ls -1 /tmp/dir[1,2]
/tmp/dir1:
file1
file2
/tmp/dir2:
file1
file2
shell> ssh admin@test_13 ls -1 /tmp/dir[1,2]
/tmp/dir1:
/tmp/dir2:
and the differences
shell> ssh admin@test_11 diff /tmp/dir1/file1 /tmp/dir2/file1
31,32d30
< User1:*:1002:1004:My User1:/home/Us... | ansible comparing all files in 2 directories and printing the difference |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.