Tag Info

Hot answers tagged

37

Using cat Since your file is short, you can use cat. cat filename Using less If you have to view the contents of a longer file, you can use a pager such as less. less filename You can make less behave like cat when invoked on small files and behave normally otherwise by passing it the -F and -X flags. less -FX filename I have an alias for less ...


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

The following is what I ended up using to reliably create a temporary directory that works on both Linux and Darwin (Mac OS X), without hardcoding $TMPDIR or /tmp: mytmpdir=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'` Background The GNU mktemp command requires no arguments. Plain mktemp will create a temporary file in the system temporary ...


10

Moving a file to the location of an already existing file replaces the existing file. In this case the /dev/null device file is replaced, just as any normal file would be. To avoid this use the -i (interactive, warns before overwriting) or -n (no clober) option for mv. /dev/null only performs its special function as a bit-bucket then the device is opened as ...


9

On Linux, you could use the immutable flag using chattr to achieve read-only on a filesystem level (requires appropriate permissions though). I don't use OS X and do not know if it has something similar, but you could achieve "after script is run, test.txt still exist" using: #!/bin/sh mv test.txt test.bak trap "mv test.bak test.txt" EXIT rm -f test.txt ...


8

Umm, because you overwrite the special file with normal one? What did you expect to happen? dev/null is not a directory, it is a file pointing to a null device. When you mv something to it, you delete the original and replace it with whatever you moved: $ file /dev/null /dev/null: character special $ sudo mv file /dev/null $ file /dev/null /dev/null: ...


8

Looking at the source code for mv, http://www.opensource.apple.com/source/file_cmds/file_cmds-220.7/mv/mv.c : /* * If rename fails because we're trying to cross devices, and * it's a regular file, do the copy internally; otherwise, use * cp and rm. */ if (lstat(from, &sb)) { warn("%s", from); return (1); } return (S_ISREG(sb.st_mode) ? ...


8

The main reason that X terminal applications run non-login shells by default is that in the beginning of time, your .Xsession would have run the .profile to set up your initial login items. Then, since that was all set up already, terminal apps didn't need to run it, they could run the .bashrc. Discussion of why this would matter is at ...


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


7

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


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


6

For the shebang line, use: #!/usr/bin/env perl env will search the PATH at execute the first perl that it finds. If you want to specify any options for perl, just add them to the end of the line above. If more than one perl is installed, env will run the first one it finds in PATH.


6

Or, you can have sh take care of it for you: #!/bin/sh exec perl -x "$0" "$@" #!/usr/bin/perl ... Yes, that's sh and Perl all in one file. From man perlrun: -x tells Perl that the program is embedded in a larger chunk of unrelated text, such as in a mail message. Leading garbage will be discarded until the first ...


6

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


5

You probably want to run some variant of Darwin, probably PureDarwin, rather than FreeBSD.


5

With exiftool: $ exiftool -q -p '$FileName $ImageSize' ./*.mp4 foo.mp4 640x480 test.mp4 1280x800


5

You can use following command to display content of a text file. cat filename


5

tl;dr: it's doable but you will have to work just a little bit. If you don't have the ability to use Ethernet, and are installing from netinst media, you're basically screwed (although if you're really determined you can make it work). When I originally wrote this answer, I'd only done this once, but now I'm doing it again on a different Mac, so I've split ...


5

If you can install smartmontools on your Mac, then run a selftest on the disk smartctl -t long /dev/disk1 This will take a few hours. Then query the result with: smartctl -a /dev/disk1


5

I may have found something: The ls command on OS X has this switch: -O Include the file flags in a long (-l) output. The result is: $ ls -O Info.plist -rw-r--r-- 1 root wheel compressed 15730 11 jui 15:02 Info.plist I just checked (experimentally) that du always reports 0 for HFS+ compressed files. Copying compressed files uncompress them; ...


5

It seems you are asking two or three questions. To use ssh to tunnel, I advise you start a non-interactive session ssh -C2qTnN -D 8080 user@IP That will put the ssh tunnel in the background. Use the proxy: You then configure your browser or system settings to use the proxy on localhost port 8080. Stop using the proxy: You then re-configure your system ...


5

maxproc and maxfiles might go unlimited in previous OSX versions, however in Mavericks, they have an artificial maximum value. To increase default maxproc and maxfiles in launchctl, append the following lines to /etc/launchd.conf (create if it does not yet exist): limit maxfiles 16384 16384 limit maxproc 2048 2048 Be aware: those numbers are about as ...


5

Yes: Install Homebrew brew install coreutils ln -s /usr/local/bin/gtac /usr/local/bin/tac or use MacPorts to install coreutils in a similar way.


5

basename operates on its command line argument, it doesn't read from standard input. You don't need to call the basename utility, and you'd better not: all it would do is strip off the part before the last /, and it would be slow to call an external command for each entry, you can use a text processing utility instead. find ~ -type f | sed 's!.*/!!' | sort ...


5

The way it's supposed work is that, at the point when you get a shell prompt, both .profile and .bashrc have been run. The specific details of how you get to that point are of secondary relevance, but if either of the files didn't get run at all, you'd have a shell with incomplete settings. The reason terminal emulators on Linux (and other X-based systems) ...


5

Using awk: awk ' BEGIN { fields[1] fields[3] fields[4] fields[5] fields[6] fields[7] last_field=8 } ( NR%21 in fields ) { printf($0",") } NR%21==last_field' in_file.txt Or better yet: awk ' NR%21 ~ /^(1|3|4|5|6|7)$/ { printf($0",") } NR%21==8' in_file.txt GNU sed has a nice extension to match the nth line after a ...


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

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


4

Since Mac OS X 10.8, you should be able to use the caffeinate(8) command. Try caffeinate -s ssh server.example.com.



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