Hot answers tagged

285

Generally, you should use kill -15 before kill -9 to give the target process a chance to clean up after itself. (Processes can't catch or ignore SIGKILL, but they can and often do catch SIGTERM.) If you don't give the process a chance to finish what it's doing and clean up, it may leave corrupted files (or other state) around that it won't be able to ...


229

Emptying the buffers cache If you ever want to empty it you can use this chain of commands. # free && sync && echo 3 > /proc/sys/vm/drop_caches && free total used free shared buffers cached Mem: 1018916 980832 38084 0 46924 355764 -/+ buffers/cache: 578144 ...


210

I'd recommend getting it directly from a DNS server. Most of the answers here all go over HTTP to a remote server. Some of them require parsing of the output, or rely on the User-Agent header to make the server respond in plain text. They also change quite frequently (go down, change their name, put up ads, might change output format etc.). The DNS ...


195

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


190

Randal Schwartz used to frequently post "Useless use of (x)" on lists. One such post was about kill -9. It includes reasons and a recipe to follow. Here is a reconstructed version (quoted below). (Quote abomination) No no no. Don't use kill -9. It doesn't give the process a chance to cleanly: 1) shut down socket connections 2) clean ...


189

You can use getent, which comes with glibc (so you almost certainly have it on Linux). This resolves using gethostbyaddr/gethostbyname2, and so also will check /etc/hosts/NIS/etc: getent hosts unix.stackexchange.com | awk '{ print $1 }' Or, as Heinzi said below, you can use dig with the +short argument (queries DNS servers directly, does not look at /etc/...


189

That's probably because your /etc/sudoers file (or any file it includes) has: Defaults requiretty ...which makes sudo require a TTY. Red Hat systems (RHEL, Fedora...) have been known to require a TTY in default sudoers file. That provides no real security benefit and can be safely removed. Red Hat have acknowledged the problem and it will be removed in ...


180

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


162

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


150

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


147

x86 (32-bit a.k.a. i386–i686 and 64-bit a.k.a. amd64. In other words, your workstation, laptop or server.) FAQ: Do I have… 64-bit (x86_64/AMD64/Intel64)? lm Hardware virtualization (VMX/AMD-V)? vmx (Intel), svm (AMD) Accelerated AES (AES-NI)? aes TXT (TPM)? smx a hypervisor (announced as such)? hypervisor Most of the other features are only of interest ...


145

As far as I know, the only condition under which sl shows the current directory is when you mistype it as ls.


143

First, think: What is a directory? It's just a list of items (files and other directories) that live within. So: directory = list of names. Read bit = If set, you can read this list. So, for example, if you have a directory named poems: You can ls poems and you'll get a list of items living within (-l won't reveal any details!). You can use command-line ...


123

To tar and gzip a folder, the syntax is: tar czf name_of_archive_file.tar.gz name_of_directory_to_tar The - is optional. If you want to tar the current directory, use . to designate that. To construct your filename, use the date utility (look at its man page for the available format options). For example: cd /var/www && sudo tar czf ~/...


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


115

I believe if you want to override the DNS nameserver you merely add a line similar to this in your base file under resolv.conf.d. Example $ sudo vim /etc/resolvconf/resolv.conf.d/base Then put your nameserver list in like so: nameserver 8.8.8.8 nameserver 8.8.4.4 Finally update resolvconf: $ sudo resolvconf -u If you take a look at the man page for ...


114

Linux automatically detects SSD, and since kernel version 2.6.29, you may verify sda with: cat /sys/block/sda/queue/rotational You should get 1 for hard disks and 0 for a SSD. See this answer for more information...


113

blockdev --getsize64 /dev/sda returns size in bytes. blockdev --getsize /dev/sda returns size in sectors. Source: man page on my Ubuntu system.


105

For disk I/O trending there are a few options. My personal favorite is the sar command from sysstat. By default, it gives output like this: 09:25:01 AM CPU %user %nice %system %iowait %steal %idle 09:35:01 AM all 0.11 0.00 0.01 0.00 0.00 99.88 09:45:01 AM all 0.12 0.00 0.01 0.00 ...


103

I don't know why sftp does this but you can only recursive copy if the destination directory already exists. So do this... sftp> mkdir bin sftp> put -r bin


103

ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB. If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead. If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane ...


102

Is it safe to raise that value and what would be the consequences of a too high value? Yes, it's safe to raise that value and below are the possible costs [source]: Each used inotify watch takes up 540 bytes (32-bit system), or 1 kB (double - on 64-bit) [sources: 1, 2] This comes out of kernel memory, which is unswappable. Assuming you set the max at ...


101

This is highly platform-dependent. Also different methods may treat edge cases differently (“fake” disks of various kinds, RAID volumes, …). On modern udev installations, there are symbolic links to storage media in subdirectories of /dev/disk, that let you look up a disk or a partition by serial number (/dev/disk/by-id/), by UUID (/dev/disk/by-uuid), by ...


101

The forward slash / is the delimiting character which separates directories in paths in Unix-like operating systems. This character seems to have been chosen sometime in the 1970's, and according to anecdotal sources, the reasons might be related to that the predecessor to Unix, the Multics operating system, used the > character as path separator, but the ...


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


98

Kernel Version If you want kernel version information, use uname(1). For example: $ uname -a Linux localhost 3.11.0-3-generic #8-Ubuntu SMP Fri Aug 23 16:49:15 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux Distribution Information If you want distribution information, it will vary depending on your distribution and whether your system supports the Linux ...


96

Here are the commands you need to run, if you just want to get it done: sudo add-apt-repository ppa:git-core/ppa -y sudo apt-get update sudo apt-get install git git --version As of Dec 2014, I get git 2.2.0 that way, while the version in the Ubuntu Trusty repositories is 1.9.1. Note that add-apt-repository is installed via: sudo apt-get install python-...


93

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


90

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


85

The find command is the primary tool for recursive, filesystem operations. Use the -type d expression to tell find you're interested in finding directories only (and not plain files). The GNU version of find supports the -empty test, so $ find . -type d -empty -print will print all empty directories below your current directory. Use find ~ -… or find "$...



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