Hot answers tagged

114

You can send dd a certain signal using the kill command to make it output its current status. The signal is INFO on BSD systems (including OSX) and USR1 on Linux. In your case: kill -INFO $PID You can find the process id ($PID above) with the ps command; or see pgrep and pkill alternatives on mac os x for more convenient methods. More simply, as AntoineG ...


87

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


66

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


66

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


63

Mac OS X has been certified as Unix by The Open Group from 10.5 onward: 10.11 (El Capitan) 10.10 (Yosemite) 10.9 (Mavericks) 10.8 (Mountain Lion) 10.6 (Snow Leopard) 10.5 (Leopard) Apple's page on The Open Group site only lists the current version of OS X as I write this, and in the past it only listed the current and prior versions. Nevertheless, all of ...


59

It indicates the file has extended attributes. You can use the xattr command-line utility to view and modify them: xattr -l file # lists the names of all xattrs. xattr -w attr_name attr_value file # sets xattr attr_name to attr_value. xattr -d attr_name file # deletes xattr attr_name. xattr -c file # deletes all xattrs. xattr -h # prints help


56

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


55

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


54

Under OS X (didn't try on Linux), you can simply type Ctrl+T in the terminal running dd. It will print the same output as kill -INFO $PID, plus the CPU usage: load: 1.40 cmd: dd 34536 uninterruptible 3.49u 64.58s 5020305+0 records in 5020304+0 records out 2570395648 bytes transferred in 4284.349974 secs (599950 bytes/sec) I found out about it reading ...


53

The history of MacOS is a little bit more convoluted. I was very interested in this in the late 90's as Mach had been pitched around the world as a faster way of building a Unix system. The origin of the kernel is a bit more complicated. It all starts with AT&T distributing their operating system to some universities for free. This Unix was ...


52

In some sense, it is a UI convention with history that goes back all the way to 1984. Since Windows and X11 both post date the original Mac GUI, one might say that Windows does it the Windows way "just to be different" rather than suggesting that the Mac is the oddball. Back in the earliest days of the Macintosh, you could only run one application at a ...


49

MacOS: alias ll='ls -lG' Linux: alias ll='ls -l --color=auto' Stick that in ~/.bashrc.


47

The answer that suggested system_profiler | grep 'System Version' is what I have tried to use in the past, but it has 2 problems. It is slow since it generates a full system_profiler dump of the machine, gathering all hardware and software inventory information. The output of system_profiler has changed over time. e.g. output of grep for 'Serial Number' ...


46

I made the same move years ago. Here are the things I've run into: Your average desktop Linux has a richer userland than that of OS X. You'll probably miss different tools than I did, so no sense getting specific about recommendations for replacements. Instead, just install Fink, MacPorts, or Homebrew first thing. These systems provide a package ...


46

The whole ABI is different, not just the binary format (Mach-O versus ELF) as sepp2k mentioned. For example, while both Linux and Darwin/XNU (the kernel of OS X) use sc on PowerPC and int 0x80/sysenter/syscall on x86 for syscall entry, there's not much more in common from there on. Darwin directs negative syscall numbers at the Mach microkernel and ...


42

You're seeing the escape sequences that tell the terminal to change colors displayed with the escape character shown as ESC, whereas the desired behavior would be that the escape sequences have their intended effect. Commands such as git diff and git log pipe their output into a pager, less by default. Git tries to tell less to allow control characters to ...


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


27

The easiest way is: $ sw_vers -productVersion 10.6.4 From http://tinyapps.org/blog/mac/201008140700_os_x_version_terminal.html: $ sw_vers ProductName: Mac OS X ProductVersion: 10.6.4 BuildVersion: 10F569 $ sw_vers -productVersion 10.6.4 Especially handy when resetting a password in single user mode, since the method varies based on which ...


27

HUGE GOTCHA -- Mac OS filesystem is NOT case sensitive.


27

On OSX, the @ symbol indicates that the file has extended attributes. You can see them using xattr -l, or ls -@. From man 1 ls on OSX 10.9: If the file or directory has extended attributes, the permissions field printed by the -l option is followed by a @ character.


25

$> sudo lsof -iTCP -sTCP:LISTEN $> sudo lsof -iTCP -sTCP:LISTEN -P $> sudo lsof -iTCP -sTCP:LISTEN -P -n $> sudo lsof -iTCP -sTCP:LISTEN -n All return the same 32 entries (... | wc -l) on my heavily used Lion MBP. -P -n prevents lsof from doing name resolution, and it doesn't block. Missing either one of these, it can be very slow. For UDP: ...


25

On OS/X like on many systems (BSDs, Solaris, AIX, IRIX...), the functionality of GNU tac is available in tail with the -r option. So no need to install GNU tac: tail -r the-file


24

Based on the error message that you get, I don't think /dev/urandom is the problem. If it were, I'd expect an error like "no such file or directory". I searched for the error message you got and found this, which seems like it might be relevant to your issue: http://nerdbynature.de/s9y/?176 Basically, specify the locale by prepending the tr command with ...


24

If you want the equivalent to apt-get or yum on Mac OS X, you have two choices. Homebrew: http://brew.sh Macports: http://www.macports.org You can use brew install PACKAGE_NAME or port install PACKAGE_NAME to install the package available.


24

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.


23

On the Unix side, OS X is a descendant of NeXTSTEP, which was derived from 4.3BSD with the core parts of the kernel replaced with Mach. The NeXT programming API, which eventually came to be called OpenStep, is the basis of today's Cocoa API for OS X. Two APIs have diverged greatly since Apple bought NeXT in 1997, though there are ongoing efforts to provide ...


23

Terminal is a terminal emulator. It interprets various control sequences sent by programs (control characters like CR, LF, BS and longer control sequences for commands like “clear screen”, “move cursor up 3 lines”, etc.). Terminal is the same kind of program as xterm, rxvt, Konsole, or GNOME Terminal. Almost all modern terminal emulators support the “xterm” ...


23

For dd, you can send a signal. For other commands that are reading or writing to a file, you can watch their position in the file with lsof. lsof -o -p1234 # where 1234 is the process ID of the command lsof -o /path/to/file If you plan in advance, pipe the data through pv.


23

Three reasons: First, being certified as a Unix says nothing about your licensing, just your compliance to the established standards for being Unix. Second, because being Unix has nothing to do with your licensing, and everything to do with your being like Unix, an originally proprietary system, and one with a long legacy. Finally, don't mistake ...



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