Hot answers tagged linux
249
System calls aren't handled like regular function calls. It takes special code to make the transition from user space to kernel space, basically a bit of inline assembly code injected into your program at the call site. The kernel side code that "catches" the system call is also low-level stuff you probably don't need to understand deeply, at least at ...
93
su - invokes a login shell after switching the user. A login shell resets most environment variables, providing a clean base.
su just switches the user, providing a normal shell with an environment nearly the same as with the old user.
Imagine, you're a software developer with normal user access to a machine and your ignorant admin just won't give you root ...
63
That depends on what you mean by “Unix”, and by “Linux”.
UNIX is a registered trade mark of The Open Group. The trade mark has had an eventful history, and it's not completely clear that it's not genericized due to the widespread usage of “Unix” refering to Unix-like systems (see below). Currently the Open Group grants use of the trade mark to any system ...
43
The {} syntax is Bash syntax not tied to the for construct.
mkdir {A..Z}
is sufficient all by itself.
http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion
42
When applying permissions to directories on Linux, the permission bits have different meanings than on regular files.
The write bit allows the affected user to create, rename, or delete files within the directory, and modify the directory's attributes
The read bit allows the affected user to list the files within the directory
The execute bit allows the ...
42
There is a manual, you just have to know where it is. It can be accessed with the man command. If you are unsure how to use it, type man man. The man command is very important; remember it even if you forget everything else.
The manual contains detailed information about a variety of topics, which are separated into several sections:
General commands
...
41
/proc/$pid/maps
/proc/$pid/mem shows the contents of $pid's memory mapped the same way as in the process, i.e., the byte at offset x in the pseudo-file is the same as the byte at address x in the process. If an address is unmapped in the process, reading from the corresponding offset in the file returns EIO (Input/output error). For example, since the first ...
40
In my mind, the only benefit you really get from compiling your own linux kernel is:
You learn how to compile your own linux kernel.
It's not something you need to do for more speed / memory / xxx whatever. It is a valuable thing to do if that's the stage you feel you are at in your development. If you want to have a deeper understanding of what this ...
39
If you want to know what's different so you can use the system more efficiently, here is a commonly referenced introduction to BSD to people coming from a Linux background.
If you want more of the historical context for this decision, I'll just take a guess as to why they chose FreeBSD. Around the time of the first dot-com bubble, FreeBSD 4 was extremely ...
37
The whole ABI is different, not just the binary format (Mach-O versus ELF) as sepp2k mentioned.
For example, while both Linux and Darwin/XNU (the kernel of OS X) use sc on PowerPC and int 0x80/sysenter/syscall on x86 for syscall entry, there's not much more in common from there on.
Darwin directs negative syscall numbers at the Mach microkernel and ...
36
Linux has wide support for lots of different hardware architectures and platforms from tiny embedded boards to massive computing arrays. While other good kernels are available, the coverage and quality of hardware drivers available for Linux far surpass any other platform.
The Linux kernel source is open and can easily be modified to run on various custom ...
35
While -R is posix well-defined, -r is not portable!
On Linux, in the GNU and BusyBox implementations of cp, -r and -R are equivalent.
On the other side, as you can read in the POSIX manual page of cp, -r behavior is implementation-defined.
* If neither the -R nor -r options were specified, cp shall take
actions based on the type and ...
35
With host from the dnsutils package:
$ host unix.stackexchange.com
unix.stackexchange.com has address 64.34.119.12
(Corrected package name according to the comments. As a note other distributions have host is different packages: Ubuntu bind9-host, openSUSE bind-utils, Frugalware bind.)
33
This probably doesn't answer your question directly, but I've found strace to be really cool when trying to understand the underlying system calls, in action, that are made for even the simplest shell commands. e.g.
strace -o trace.txt mkdir mynewdir
The system calls for the command mkdir mynewdir will be dumped to trace.txt for your viewing pleasure.
33
The reason is Unix does not lock an executable file while it is executed or even if it does like Linux, this lock applies to the inode, not the file name. That means a process keeping it open is accessing the same (old) data even after the file has been deleted (unlinked actually) and replaced by a new one with the same name which is essentially what a ...
31
ZFS is not in the official Linux kernel, and never will be unless Oracle relicenses the code under something compatible with the GPL.
Additionally, NetApp claims they own patents on some technology used in ZFS. NetApp settled their lawsuit with Sun after the Oracle buyout, but that settlement doesn't protect any other Linux distributor. (Red Hat, Ubuntu, ...
31
A good way to inspect what a command is:
type l
If it's a program or a script, it will give you its location, if it is an alias, it will tell you what it's aliased to, if it's a function, it will print the funciton; otherwise, it will tell you if it is a built-in or a keyword.
Examples:
$ type find
find is /usr/bin/find
$ type connecthome
connecthome is ...
31
As Heinzi said below, the best way is to use dig with the +short argument.
dig +short unix.stackexchange.com
If +short is unavailable for some reason, any one of the following should work:
host unix.stackexchange.com | awk '/^[[:alnum:].-]+ has address/ { print $4 }'
nslookup unix.stackexchange.com | awk '/^Address: / { print $2 }'
dig ...
31
Ctrl+C sends a SIGINT to the program. This tells the program that you want to interrupt (and end) it's process. Most programs correctly catch this and cleanly exit. So, yes, this is a "correct" way to end most programs.
There are other keyboard shortcuts for sending other signals to programs, but this is the most common.
30
First of all, there is. The problem is not that there is no unified package manager, the problem is there are ten of them--seriously.
Let's take my favorite: poldek. Its a user front end for package management that can run on several different distros and manage either rpm or deb packages. Poldek doesn't do the stuff rpm does (it leaves that to rpm) and ...
30
Another option is to use blkid:
$ blkid /dev/sda1
/dev/sda1: UUID="625fa1fa-2785-4abc-a15a-bfcc498139d1" TYPE="ext2"
This recognizes most filesystem types and stuff like encrypted partitions.
You can also search for partitions with a given type:
# blkid -t TYPE=ext2
/dev/sda1: UUID="625fa1fa-2785-4abc-a15a-bfcc498139d1" TYPE="ext2"
/dev/sdb1: ...
28
Here are some suggestions on how to understand the "spirit" of Unix, in addition to the fine recommendations that have been done in the previous posts:
"The Unix Programming Environment" by Kernighan and Pike: an old book, but it shows the essence of the Unix environment. It will also help you become an effective shell user.
"Unix for the Impatient" is a ...
27
Nothing new at all. Citation below are from https://lkml.org/lkml/2011/5/29/204
I decided to just bite the bullet, and call the next version 3.0. It
will get released close enough to the 20-year mark, which is excuse
enough for me, although honestly, the real reason is just that I can
no longe rcomfortably count as high as 40.
I especially like:
...
26
$? expands to the exit status of the most recently executed foreground pipeline. See the Special Parameters section of the Bash manual.
In simpler terms, it's the exit status of the last command.
26
I think the oft quoted Chinese proverb explains it well:
If you give a man a fish, he will have a single meal. If you teach him
how to fish, he will eat all his life.
While you might think "But it's only one question, why can't they just tell me the answer", it's because the forums would become so full from people asking obvious questions that it ...
25
Most users do not need to compile their own kernel, their distribution has done this work for them. Usually distributions will include a set of patches to either integrate with certain parts of the way the distribution works, backports of device drivers and fixes from newer, but unreleased versions of the kernel or features that they are pioneering with ...
25
Simple answer: You can't, root can do everything.
You can set the "i" attribute with chattr (at least if you are on ext{2,3,4}) which makes a file unchangeable but root can just unset the attribute and delete the file anyways.
More complex (and ugly hackish workaround):
Put the directory you want unchangeable for root on remote server and mount it via NFS ...
25
First and foremost, and I realize that it was not one of the terms from your question, you must understand metadata. Succinctly, and stolen from Wikipedia, metadata is data about data. That is to say that metadata contains information about a piece of data. For example, if I own a car then I have a set of information about the car but which is not part of ...
25
While openness is certainly part of it, I think the key factor is Linus Torvald's continued insistence that all of the work, from big to small, has a place in the mainline Linux kernel, as long as it's well done. If he'd decided at some point to draw a line and say "okay, for that fancy super-computer hardware, we need a fork", then completely separate ...
25
Defragment is (or was) recommended under Windows because it had a poor filesystem implementation. Simple techniques such as allocating blocks for files in groups rather than one by one keep fragmentation down under Linux. Typical Linux filesystems only gain significantly from defragmentation on a nearly-full filesystem or with unusual write patterns. Most ...
Only top voted, non community-wiki answers of a minimum length are eligible