Hot answers tagged

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


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


30

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


22

The open utility on Mac does not read from standard input, but take its arguments from the command line. To open the current working directory, you would have to say $ open "$( pwd )" or $ open "$PWD" or simply $ open . as pointed out in the comments below. With the -f flag, open can be made to read from standard input, but only to open whatever ...


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


14

I don't have a Mac so I can't test it, but the solution should be something like: open "`pwd`" Not all programs take their input from stdin which would be necessary for the pipe to work.


12

The ._ files are how OS X bsdtar handles OS X-specific extended attributes and resource forks. To keep them from being added to your tar files, you can pass COPYFILE_DISABLE=1 as an environment variable to tar. COPYFILE_DISABLE=1 tar cf newTar.tar /your/files


11

pipe the file thrught xxd to see a hex output side-by-side of the ascii, this will let you see if there are extra characters which you can't see or are unprintable. $ cat file one‏ and ‏two $ cat file | wc 1 3 18 $ cat file | xxd 00000000: 6f6e 65e2 808f 2061 6e64 20e2 808f 7477 one... and ...tw 00000010: 6f0a ...


11

This statement is odd: split("0,2,4,5,7,9,11,12",a,","); It repetitively splits a constant string to create an array a. If you move that into a BEGIN section, the program should work the same — without allocating a new copy of the a array for each input-record. Addressing comments: the for-loop and expression do not allocate memory in a simple ...


11

On OSX, uname -s returns Darwin (most Linux uname programs return Linux). As a general rule (aside from personal use), uname has quirks for different systems. In autoconf, scripts use config.guess, which provides consistent information. For example in my Debian 7, x86_64-pc-linux-gnu and in OSX El Capitan x86_64-apple-darwin15.5.0 You could use if-...


10

From the command line you can use the tar command.


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


9

Increase your virtual hard disk space to 12 GB or more. I faced similar issue and the above resolved my issue.


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

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


8

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


7

if [[ $(uname -s) == Linux ]] then doThis else doThat fi


7

Well, if you know your IP starts with 10.16, it's trivial: ifconfig -a | grep -oP '\b10\.16\.[0-9.]+\b' Or, if your grep doesn't support -P or -o: ifconfig -a | awk '/10\.16\./ && /inet/{print $2}' If not, you could find all lines starting with inet and print their second field: ifconfig -a | awk '$1=="inet"{print $2}' That, however, would ...


7

The other answers are totally correct. If you want an easy shorthand, you can do as @fd0 proposed, and just use open . to open the current directory. The current directory is named . (a single dot) in Unix, the parent directory .. (two dots).


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

The answer is given in a mailing list comment by Stefan Dösinger entitled Wine 64 bit OSX has a ABI incompatibility with Win64 - OSX overwrites a CPU register that Win64 applications expect to remain untouched. Apple can’t change the ABI because there are already 64 bit OSX apps that expect things to work that way. A potential workaround may be to run ...


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


6

Missing Loop Conditional Your syntax is invalid. You may have other problems with your code as well, but this message is likely coming from the fact that you can't have a do keyword as if it were a block; you need to have one of the loop conditionals as well. You currently have: *) do test -n '$folder' && echo ...


6

pwd | xargs open xargs shoves its standart input into the arguments of its first argument.


5

Different commands support different option styles. The major trends are: getopt(): getopt() is a 30 year old programming API to parse options. It's widely available and the only POSIX standard. It only supports single letter options some of which can take arguments. Several options can be combined together for brevity. Example: tail -fn -2: an argument-...


5

Means folk can leverage this to get a root shell, thereby bypassing your security, eg :!/bin/sh from within vim. Or :r /etc/shadow and :w /etc/shadow. And so on...


5

Assuming you are using bash you could run for f in *.dat; do mkdir -p "${f:5:2}"; mv "$f" "${f:5:2}/"; done or (if there are too many files for for f in *.dat to work) while read f; do mkdir -p "${f:5:2}"; mv "$f" "${f:5:2}/"; done < ls



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