Tag Info

Hot answers tagged

64

From your other questions I take it you're using OS X. The default HFS+ filesystem on OS X is case-insensitive: you can't have two files called "abc" and "ABC" in the same directory, and trying to access either name will get to the same file. The same thing can happen under Cygwin, or with case-insensitive filesystems (like FAT32 or ciopfs) anywhere. ...


61

It isn't a shebang, it is just a script that gets run by the default shell. The shell executes the first line //usr/bin/env go run $0 $@ ; exit which causes go to be invoked with the name of this file, so the result is that this file is run as a go script and then the shell exits without looking at the rest of the file. But why start with // instead of ...


18

In bash, . and source are synonyms. Looking into bash source code, file builtin/source.def, you can see . and source use the same internal function source_builtin: $BUILTIN source $FUNCTION source_builtin $SHORT_DOC source filename [arguments] Execute commands from a file in the current shell. Read and execute commands from FILENAME in the current shell. ...


17

The addition of keys to the agent is transient. They last only so long as the agent is running. If you kill it or restart your computer they're lost until you re-add them again. From the ssh-agent man page: excerpt #1 ssh-agent is a program to hold private keys used for public key authentication (RSA, DSA, ECDSA). The idea is that ssh-agent is started ...


16

The problem most probably is that your ls has set option --color to auto which basically means that output should be coloured only if it is connected to terminal, otherwise (output connected to a pipe or a file) no colors are emitted. If you want to have colors is such cases you should set --color option to always, so try ls --color=always | less -R If ...


15

Because builtins are part of the shell. Any bugs or history they have are bugs and history of the shell itself. They are not independent commands and don't exist outside the shell they are built in. The equivalent, for bash at least, is the help command. For example: $ help while while: while COMMANDS; do COMMANDS; done Execute commands as long as a ...


12

This can be do the same thing with purge: sync && echo 3 > /proc/sys/vm/drop_caches From man proc: /proc/sys/vm/drop_caches (since Linux 2.6.16) Writing to this file causes the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. To free ...


11

This is by design: programs that produce colored output typically do so only when their output goes to a terminal, not when it's sent to a pipe or to a regular file. The reason is that data sent on a terminal is presumably read by a human, whereas data piped to a program or written to a file is likely to be parsed by some program, so it shouldn't contain ...


10

I think this should do it: tar -xzf file.tar.gz -C ~/locationX folder1 -C ~/locationY folder2 The -C option means to change to the specified directory before doing the extraction. Specifying filename arguments after the tarfile name restricts the extraction to just those files or directories. And you can repeat this -Changing directories as you do. Note ...


10

This behavior is totally normal, it's due to how bash manages pipe usage. pipe is implemented by bash using the pipe syscall. After that call, bash forks and replaces the standard input (file descriptor 0) with the input from the right process (grep). The main bash process creates another fork and passes the output descriptor of the fifo in place of the ...


9

This is POSIX's definition of .dot: The shell shall execute commands from the file in the current environment. If file does not contain a /<slash>, the shell shall use the search path specified by $PATH to find the directory containing file. Unlike normal command search, however, the file searched for by the .dot utility need not be ...


9

This is what Bash while loops do: while /path/to/application.app do : done It will run the application, and if it terminates successfully run the body of the loop. : is the shell's no-op command (the loop has to have a body, so that's what we put there); after that it goes back to the top and runs the program again. If it fails, the loop stops running ...


8

As suggested in the comments, OS X primary is a real Unix since it is certified by The Open Group (owner of the UNIX™ trademark), allowing it to legally claim itself to be UNIX. Primary requirement for being UNIX certified is being conforming to the POSIX standard(s). Second one is being able to pay The Open Group the certification process. I think the ...


8

The difference is that Windows implicitly has . in the path, which is something it inherited from DOS, which always was a single user system. Mac OS X is build on Unix, which is a multi user system. And for security reasons it does not have . implicitly in the path. When . is not in the path, then to run a command in the current directory, one has to ...


8

STDOUT and STDERR don't have colors. What has color is your terminal (emulator); it has one foreground (and one background color) set at a time. It should also be noted that STDOUT and STDERR are not singular -- they're per process output streams. There is no global STDOUT that applies to all programs. These streams are routed to your terminal, but they ...


8

If you don't want to be challenged every time for your password then I'd recommend setting it to NOPASSWD in your /etc/sudoers file rather than hardcode your password in your logins. At least this way your primary login's password will remain intact and not be completely exposed in your .bashrc. To make this change run the command sudo visudo, and change ...


8

It runs because by default executable file is assumed to be /bin/sh script. I.e. if you didn't specify any particular shell - it is #!/bin/sh. The // is just ignored in paths - you can consider is at as single '/'. So you can consider that you have shell script with first line: /usr/bin/env go run $0 $@ ; exit What does this line do? It runs 'env' with ...


7

You can use the following command: openssl x509 -inform PEM -in cacert.pem -outform DER -out certificate.cer


7

With zsh on terminals that support 16 colors or more à la xterm: preexec() printf '\e[90m' # set foreground color to grey before running # the command precmd() printf '\e[m' # reset the foreground color before issuing the # next prompt. Note that commands may change the terminal's foreground color ...


7

You can remove the first 12 lines with: tail -n +12 Some implementations of head like GNU head support: head -n -12 but that's not standard. tail -r file | tail -n +12 | tail -r would work on those systems that have tail -r (see also GNU tac) but is sub-optimal. Where n is 1: sed '$d' file You can also do: sed '$d' file | sed '$d' to remove 2 ...


7

In Debian and Ubuntu, /bin/sh is dash, which is a POSIX-compliant shell. If you specify #!/bin/sh, you must limit yourself to POSIX statements in your script. (The advantage being that dash starts faster than bash, so your script can get its job done in less time.) On many (most?) other Linux systems, /bin/sh is bash, which is why many scripts are written ...


7

For starters, if you can make the assumption that Bash is preinstalled (which, to my knowledge is the case on all the systems you list), use the following hashbang to be compatible: #!/usr/bin/env bash this invokes whatever bash happens to be configured, no matter whether it's in /bin or /usr/local/bin. While on most systems across a wide range ...


6

The pipe does not behave like ;. It starts both the processes together. Which is why the grep command showed up too. So when you gave ps aux | grep myprocess , the ps aux included the grep myprocess, so the grep included that in its output. To check this, I gave two dd commands on my test server like this: [sreeraj@server ~]$ dd if=/dev/urandom ...


6

When I'm only interested in presence of a process, I use pgrep which doesn't show this behaviour, e.g.: $ pgrep myprocess 1900 In other cases (when i'm interested in more info), I usually add a '| grep -v grep' to discard grep lines, e.g.: $ ps -ef | grep myprocess| grep -v grep hth.


6

I recommend to use rather sort -V data.txt -V stands for "version sort" and it basically handles correctly both alphabetical and numerical characters, so that if you would have more files, say: f1.txt f10.txt f2.txt a1.txt a10.txt a2.txt then sort -V will give you a1.txt a2.txt a10.txt f1.txt f2.txt f10.txt whereas sort -k 1.2n or sort -n -k 1.2: ...


5

Your problem is that you try to enter C code into a shell prompt, this doesn't work for obvious reasons. You could either put it into a correct C file, compile it and get a valid binary you could execute: #include <linux/kd.h> #include <sys/ioctl.h> #include <fcntl.h> #include <unistd.h> #include <err.h> #include ...


5

OS X currently comes with a FreeBSD sed from 2005. Most of the differences below also apply to other BSD sed versions. OS X's sed uses -E for ERE and GNU sed uses -r. -E is an undocumented alias for -r in GNU sed. Newer versions of FreeBSD sed support both -E and -r. OpenBSD sed only supports -E. -i '' works with OS X's sed but not GNU sed. -i works with ...


5

VirtualBox comes with a series of command line tools all prefixed with VBox. The command you are looking for is VBoxHeadless --startvm "my vm name" You can see a short description of its options via VBoxHeadless --help. If you don't know the name of the virtual machine you can find out via: VBoxManage list vms To to run upon startup on Mac OS X you ...


5

The issue is indeed that the Finder's way of modifying permissions doesn't only affect the indicated bits as one might think. For some reason it zeroes out the first octal of the file's mode and it leaves the executable bits untouched. So, some vital programs get their setuid/setgid and sticky bits stripped off which makes them either useless or behave ...


5

If the filesystem takes over the whole disk, OS X currently uses a name like /dev/disk5. If the disk is partitioned, it adds an s# suffix, like /dev/disk5s2 for the second partition. (s is short for "slice," a BSDism functionally equivalent to a partition.) Disks are numbered sequentially in discovery order by the OS, on boot, so you may have to experiment ...



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