Hot answers tagged

159

This is binfmt_misc in action: it allows the kernel to be told how to run binaries it doesn't know about. Look at the contents of /proc/sys/fs/binfmt_misc; among the files you see there, one should explain how to run Mono binaries: enabled interpreter /usr/lib/binfmt-support/run-detectors flags: offset 0 magic 4d5a (on a Debian system). This tells the ...


99

Laptop batteries typically have onboard firmware to control safe charging & discharging of the battery, report battery charge level to the OS, and prevent thermal runaway, which is what will cause an Li-ion battery to explode (or more accurately, catch fire). Most modern ones also contain mechanical failsafes to prevent such fires & explosions. This ...


78

/dev/zero is an example of a "special file" — particularly, a "device node". Normally these get created by the distro installation process, but you can totally create them yourself if you want to. If you ask ls about /dev/zero: # ls -l /dev/zero crw-rw-rw- 1 root root 1, 5 Nov 5 09:34 /dev/zero The "c" at the start tells you that this is a ...


71

On my system it gets the uptime from /proc/uptime: $ strace -eopen uptime open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 open("/lib/libproc-3.2.8.so", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 open("/proc/version", O_RDONLY) = 3 open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3 ...


55

I ran this: strace -o spork.out bash -c "echo 1234 >> some-file" to figure out your question. This is what I found: open("some-file", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3 No file named "some-file" existed in the directory in which I ran the echo command.


54

The order of switches is free, but -f has a mandatory argument which is the file that tar will read/write. You could do tar -zf foo.tar.gz -xv and that will work, and has your requirement of a non-specific order of switches. This is how all commands that have options that have arguments work.


45

This is not only done in Bash, it's required by the standard. From the Single Unix Specification: Appended output redirection shall cause the file whose name results from the expansion of word to be opened for output on the designated file descriptor. The file is opened as if the open() function as defined in the System Interfaces volume of POSIX.1-2008 ...


41

/media/cdrom is a convention for the mountpoint, while /dev/cdrom is the special device that could be mounted on the former. You need both, because they serve different purposes: most applications do not read directly from the special device, but can read from a filesystem (something that is mounted)


37

Make the password manager run under a separate user. You can't send signals to (=kill) processes run under a different user unless you're root. All processes will still be killable by root. For closer details, see kill(2).


37

The Linux Standard Base (LSB) has a list of applications: [ du install mv strings ar echo install_initd newgrp strip at ed ipcrm nice stty awk egrep ipcs nl su basename env join nohup sync batch expand kill ...


36

Passing a password to sudo in a script is utterly pointless. Instead, add a sudo rule adding the particular command you want to run with the NOPASSWD tag. Take care that the command-specific NOPASSWD rule must come after any general rule. saeid ALL = (ALL:ALL) ALL saeid ALL = (root) NOPASSWD: service lightdm start But this is probably not useful anyway. ...


36

wc shows 3 characters more because your example file contains a fancy Unicode apostrophe ’ (most likely because you copied the contents from a browser or text editor): $ cat file Amy looked at her watch. He was late. The sun was setting but Jake didn’t care. $ wc file 1 16 82 file With plain ASCII apostrophe ': $ cat file2 Amy looked at her ...


33

I would highly recommend running Linux in a VM. All the software is available freely to download and there is no practical difference between running in a VM and running natively for the purposes of learning the command line. Furthermore, Linux command line mostly consists of bash + GNU coreutils, which is very different from BSD Unix (and OS X is a ...


31

You can. You just have to set the executable bit on the /a/b directory. That will prevent being able to see anything in b, but you can still do everything if you go directly to a/b/c. % mkdir -p a/b/c % chmod 711 a/b % sudo chown root a/b % ll a/b ls: cannot open directory a/b: Permission denied % touch a/b/c/this.txt % ls a/b/c this.txt Beware that ...


29

That library has a main() function or equivalent entry point, and was compiled in such a way that it is useful both as an executable and as a shared object. Here's one suggestion about how to do this, although it does not work for me. Here's another in an answer to a similar question on S.O, which I'll shamelessly plagiarize, tweak, and add a bit of ...


28

Execute as root: # swapoff -a And to make that change permanent, edit /etc/fstab and remove or comment-out the swap entry.


28

You can use the echo or find commands instead of ls: echo * or: find -printf "%M\t%u\t%g\t%p\n"


28

Whether the order matters depends on whether you start the options with a minus $ tar -cfvz casual.tar.gz snapback.txt bucket.txt tar: casual.tar.gz: Cannot stat: No such file or directory tar: Exiting with failure status due to previous errors $ tar cfvz casual.tar.gz snapback.txt bucket.txt snapback.txt bucket.txt This unusual behavior is documented in ...


27

Most of the /dev entries are block device inodes or character device inodes. One previous answer has many details about that, which I am not going to repeat. But /dev/tcp which is mentioned in your question is not explained by any of the existing answers. /dev/tcp and /dev/udp are different from most other /dev entries. The block and character devices are ...


27

Looking in the source, it does use O_APPEND. For bash 4.3.30 in make_cmd.c line 710-713 read: case r_appending_to: /* >>foo */ case r_append_err_and_out: /* &>> filename */ temp->flags = O_APPEND | O_WRONLY | O_CREAT; break;


26

A new install will seldom break your system (unless you do weird stuff like mixing source and binary). If you use precompiled binaries in Ubuntu then you can remove them and not have to worry about breaking your system, because a binary should list what it requires to run and your package manager will list what programs rely on that program for you to ...


26

The tool to display inode detail for a filesystem will be filesystem specific. For the ext2, ext3, ext4 filesystems (the most common Linux filesystems), you can use debugfs, for XFS xfs_db, for ZFS zdb. For btrfs some information is available using the btrfs command. For example, to explore a directory on an ext4 filesystem (in this case / is dev/sda1): # ...


26

I think all batteries can explode. The question is if Linux (an operating system using the Linux kernel) will generate more heat or not. With good use of the fan (equally good use of the fan as other operating systems might employ), the cooling should be equal or better, thus resulting in a similar (or perhaps even reduced) risk of battery explosion. There ...


25

The main risks developing kernel modules are that you can crash your system much more easily than with regular code, and you'll probably find that you sometimes create modules that can't be unloaded which means you'll have to reboot to re-load them after you fix what's wrong. Yes, a VM is fine for this kind of development and it's what I use when I'm ...


24

A ping cannot be 0 bytes on Linux, Windows or any other platform that claims to be able to send pings. At the very least the packet must contain an IP header and a non-malformed no-trick-playing ping will also include an ICMP header, which is 8 bytes long. It is possible that windows differs in how they output the bytes received. Linux tells you the size ...


24

It seems to be a purely arbitrary choice. It could be anything, but somebody1 felt 4 million is enough. Use the source: /* * A maximum of 4 million PIDs should be enough for a while. * [NOTE: PID/TIDs are limited to 2^29 ~= 500+ million, see futex.h.] */ #define PID_MAX_LIMIT (CONFIG_BASE_SMALL ? PAGE_SIZE * 8 : \ (sizeof(long) > 4 ? 4 * 1024 * ...


24

I'll answer your questions out of order: the release team chooses code names; the next two releases are Stretch and Buster; and I don't think we're worried about running out of names yet... As pointed out by eyoung100, Strech is the octopus in Toy Story 3, and Buster is Andy's dog. Also, Sid is the name of the next-door kid who breaks all his toys. "Still ...


24

You can also use the printf command, instead of echo: printf '%s\n' * printf is superior to echo in this situation in that echo does not respect the "double dash" (--) to signify the end of the argument list (on some systems, including Ubuntu 14.04 which is what I tested it on): llama@llama:~$ mkdir -p Misc/unix210948 llama@llama:~$ cd !$ cd ...


24

Manual pages for a library would go in section 3. For good examples of manual pages, bear in mind that some are written using specific details of groff and/or use specific macros which are not really portable. There are always some pitfalls in portability of man-pages, since some systems may (or may not) use special features. For instance, in documenting ...


23

So there are basically two different types of thing here: Normal filesystems, which hold files in directories with data and metadata, in the familiar manner (including soft links, hard links, and so on). These are often, but not always, backed by a block device for persistent storage (a tmpfs lives in RAM only, but is otherwise identical to a normal ...



Only top voted, non community-wiki answers of a minimum length are eligible