Tag Info

Hot answers tagged

65

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


64

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


20

You either have trailing whitespace, or a corrupt filesystem. Try for i in tftp.plist* do echo "'$i'" done That should output something like 'tftp.plist' 'tftp.plist ' note the quotes and the extra space. If it outputs the exact same thing twice, you likely have a corrupt filesystem. Try ls -i tftp.plist* this will give you the inode numbers ...


16

The problem most probably is that your ls program has set option --color=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 ...


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


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


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


8

You can remove the first 12 lines with: tail -n +13 (That means print from the 13th line.) 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: ...


8

Man pages are written in the troff/nroff markup language. Troff, which is meant for preparing output to a phototypesetter (or to files in formats such as PostScript or PDF), will automatically change the ` and ' characters in the input into curved quotation marks, ‘ and ’. Nroff, which is what the man command runs when the output is to a terminal, will pass ...


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


7

Sure, of course, since you can develop portable software that runs on both MacOS and Linux. Be sure to test it on Linux at regular intervals to make sure you haven't unintentionally added something unportable. If you want to use Linux-specific features then you will have more of a hard time. Depending on what it is you do, the program may compile on MacOS ...


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

With GNU find: find . -name foo.mp4 -printf '%h\n' With other finds, provided directory names don't contain newline characters: find . -name foo.mp4 | sed 's|/[^/]*$||' Or: find . -name foo.mp4 -exec dirname {} \; though that means running one dirname command per file. If you need to run a command on that path, you can do (standard syntax): ...


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


6

The ls version in Mac OS X is based on BSD ls, and doesn't support long-format options including --help. See the ls manpage or man ls on your system for details.


6

You could use grep with -A and -B to print exactly the parts of the file you want to exclude but add the -n switch to also print the line numbers and then format the output and pass it as a command script to sed to delete those lines: grep -n -A1 -B2 PATTERN infile | \ sed -n 's/^\([0-9]\{1,\}\).*/\1d/p' | \ sed -f - infile Another way with comm: comm ...


6

don's might be better in most cases, but just in case the file is really big, and you can't get sed to handle a script file that large (which can happen at around 5000+ lines of script), here it is with plain sed: sed -ne:t -e"/\n.*$match/D" \ -e'$!N;//D;/'"$match/{" \ -e"s/\n/&/$A;t" \ -e'$q;bt' -e\} \ ...


6

First, this is about a lot more than just coreutils. The BSD equivalent to GNU findutils is also quite different, pretty much every command related to dynamic linkage is different, etc. And then on top of that, you have to deal with versioning differences: OS X still ships a lot of older software to remain on GPL2 instead of GPL3, such as Bash 3.x instead ...


5

I fixed the issue by simply adding the --alldrivers when installing refind. Yosemite dual boot works now like before. Fast, and everything is reconized in the refind boot menu. install.sh --alldrivers


5

The stat command that you saw from “everyone on the internet” is the one from GNU coreutils, which is found on non-embedded Linux and Cygwin. It could also be the one from BusyBox, which is commonly found on embedded Linux. OSX has a different stat utility (the one from FreeBSD/NetBSD/OpenBSD), with a similar purpose but different options and a different ...


5

There is other way to make things faster: Use grep -f file1 file2 >output.txt. You could also use gnu parallel: http://www.gnu.org/software/parallel/parallel_tutorial.html


5

xargs seems to be what you want: echo install update doctor | xargs -n1 brew


5

A read-only file system can only be read (therefore it is named read-only). To delete files on this file-system you have to remount it read-write.


5

You can use tr: LC_ALL=C tr -d '[:blank:]\n' < file_in > file_out Since when you have to work with 10k files, a better solution would be: find . -type f -exec perl -i.bak -pe 's/ |\t|\n//g' {} +


5

According to this article, the main difference between this and the normal duplicate (⌘D) function is that file ownership is retained. The normal duplicate function preserves file permissions but not ownership. The best equivalent to this behavior on OSX is the ditto command. You can simply use sudo ditto src dst and it will preserve everything by default. ...


5

Perhaps the closest thing to what you are looking for is MacPorts (or some other package management system like Homebrew). It can be used to install software(including many Unix software) easily.



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