Hot answers tagged

161

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 ...


123

Some commands (eg chown) can accept either a username or a numeric user ID, so allowing all-numeric usernames would break that. A rule to allow names that start with a number and contain some alpha was probably considered not worth the effort; instead there is just a requirement to start with an alpha character. Edit: It appears from the other responses ...


100

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 ...


80

/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 "...


74

here is a test on ubuntu 14.04 using numbers: root@ubuntu:~# useradd 232 root@ubuntu:~# mkdir /home/232 root@ubuntu:~# chown 232.232 /home/232 root@ubuntu:~# passwd 232 Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully root@ubuntu:~# login c2 login: 232 Password: Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.4.0-22-...


72

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 open("/etc/...


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.


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)


38

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 ...


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).


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 ...


35

The fastest way to create a file in a Linux system is fallocate: fallocate -l 50G file From man: fallocate is used to manipulate the allocated disk space for a file, either to deallocate or preallocate it. For filesystems which support the fallocate system call, preallocation is done quickly by allocating blocks ...


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 ...


32

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 ...


29

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


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

The problem is that those /proc files on Linux appear as text files as far as stat()/fstat() is concerned, but do not behave as such. Because it's dynamic data, you can only do one read() system call on them (for some of them at least). Doing more than one could get you two chunks of two different contents, so instead it seems a second read() on them just ...


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

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, Stretch 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 ...


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 ...


25

The problem is caused by the TasksMax systemd attribute. It was introduced in systemd 228 and makes use of the cgroups pid subsystem, which was introduced in the linux kernel 4.3. A task limit of 512 is thus enabled in systemd if kernel 4.3 or newer is running. The feature is announced here and was introduced in this pull request and the default values were ...


25

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 ...


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

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 ...


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 ...


23

The closest equivalent to a human-readable (and human-chosen) name for a computer running Linux is the default hostname stored in /etc/hostname. On some (not all) Linux distributions, this name is entered during installation as the computer's name (but with network hostname constraints, unlike Mac OS X's computer name).


22

This can easily be done using ImageMagick identify -format '%n %i\n' -- *.gif 12 animated.gif 1 non_animated.gif identify -format %n prints the number of frames in the gif; for animated gifs, this number is bigger than 1. (ImageMagick is probably readily available in your distro's repositories for an easy install)



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