Hot answers tagged

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


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


18

Shell Session Limit The limits set via ulimit only affects processes created by the current shell session. The "soft limit" is the actual limit that is used. It could be set, as far as it is not greater than the "hard limit". The "hard limit" could also be set, but only to a value less than the current one, and only to a value not less than the "soft ...


18

OS X is sufficient to learn the command line as it is a certified UNIX and conforms to POSIX. If you are looking at Linux specific command line book you have to keep in mind that the userland tools in OS X are derived from BSD while the tools on Linux are GNU and there are some subtle (and not so subtle) differences between them. If you want to learn ...


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


12

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

It's not an endless looping, it's just GNU find reporting that echo died of a SIGPIPE (because the other end of the pipe on stdout has been closed when head died). -execdir is not specified by POSIX. And even for -exec, there's nothing in the POSIX spec that says that if the command is killed by a SIGPIPE, find should exit. So, would POSIX specify ...


9

Some good answers so far, but one more reason to stay away from the default OS X command line tools is they are very old versions. For example, OS X's grep is from 2004, and bash is from 2007! The reason is that Apple refuses to ship tools licenced under the GPL3. If you didn't want to install Linux proper, you could manually install the latest versions ...


9

The following script will check the dates of all files specified on the command line: It requires GNU versions of sed, date, and stat $ cat check-dates.sh #! /bin/bash for f in "$@" ; do # get date portion of filename fdate=$(basename "$f" .txt | sed -re 's/^.*(2015)/\1/') # convert it to seconds since epoch + 1 day fsecs=$(echo $(date +%s -d ...


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


8

tee doesn't know anything about colors. But some applications produce colored output only when their output goes to a terminal, not when it goes to a regular file or to a pipe. In such cases, check if the application can be told to produce colored output anyway. For example, under OSX, for ls, you need to set the environment variable CLICOLOR_FORCE. If an ...


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


7

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.


7

This seems to be from prezto defining a function overriding diff. It may well have a way of disabling that, but I don't know what it is. You have a few options: /usr/bin/diff or command diff will both run the diff command, rather than the function. unset -f diff will remove the diff function. You could put that in your shell configuration. As you've found, ...


7

To check which options a partition was mounted with, you can use the mount -l command. This will output a bunch of lines that look like this: sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) I've highlighted the part you should be looking at. Just check the line for the partition ...


6

The default shell for root on OS X is /bin/sh. Its sh is also a version of bash, but when invoked with the name sh Bash: tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or as a non-interactive shell with the --login ...


6

On OS/X, like on all systems where they are supported except Linux, opening /dev/fd/x is like doing a dup(x), the resulting fd more or less points to the same open file description as on fd x and in particular will have the same offset within the file. Linux is the exception here. On Linux, /dev/fd/x is a symlink to /proc/self/fd/x and /proc/self/fd/x is a ...


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

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


6

I would say that it is misleading to call getpid() a "linux system call". That gives the impression that it is a Linux-specific system call, which it isn't. Actually, getpid() and many other system calls are specified by POSIX, and you will find it implemented on both Linux and MacOS and on many other systems, with identical behaviour. The majority of ...


6

Find uses readdir() to get the content from directories. As readdir() is a library function that implements caching and as find even without caching cannot know that the called program removes a just discovered directory, a standard find call will always cause such errors. There is a clean solution for your problem: find . -depth ... (replace ... by the ...


6

This should do: for i in {1..5}; do printf '#%s/Z\n' "$(openssl rand -hex 4)" done >passwords.txt I replaced the multiple calls to echo with a single call to printf. Having the call to openssl wrapped inside a command substitution has the side effect of making the line ending disappear, and that newline character was the cause of the badly-placed ...


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.


5

These quotation marks are often used because they look nice, similar to the quotation marks in printed books (which are different at the beginning and end of the quoted passage). These quotation marks may also have been added by your local troff configuration (or, could be removed by it!). The actual file may not contain these characters literally. You ...



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