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


23

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


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

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


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

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


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

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

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.


8

From the command line you can use the tar command.


8

Man pages historically have been written in the troff/nroff markup language, although there are alternatives now such as DocBook. 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 ’. (See the ...


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


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

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


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

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


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


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


5

The latest version of the HFS+ utilities on Debian are, as far as I can tell, from 2006 and lacking a maintainer. Apple released Time Machine in 2007, and when they did they introduced some quite significant changes to HFS+ (particularly to do with hard links to directories). It is highly likely that the HFS+ tools on Debian cannot deal very well with a Time ...


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


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