This might seem like a silly question but I haven't been able to find a clear answer.
This website states that the dash is optional in
ps aux
However, ps aux works but ps -aux brings up the error no user named 'x'. Any ideas what the issue may be here? Running Mac 10.8.2. Thanks
man ps
will give you this:
The biggest change is in the interpretation of the -u option, which now
displays processes belonging to the specified username(s). Thus, "ps
-aux" will fail (unless you want to know about user "x"). As a conve-
nience, however, "ps aux" still works as it did in Tiger.
Back in the day (from the late 1970s), there were basically two varieties of UNIX, the AT&T version from Bell Labs and the BSD version from UC Berkeley. The options to ps were different in the two versions. OS X now mostly conforms to the modern UNIX standard which follows the AT&T options to ps. But since the BSD ps didn't require a leading '-' option and so many people were used to typing 'ps aux', Apple has decided to leave that sequence with its original BSD interpretation.
Related
Many times I find myself in the situation of having to follow the evolution of a log file on Windows. Is there an equivalent of the Linux
tail -f <filename>
command on a Windows terminal, preferably without having to install external software? Other SO posts talk about installing third-party programs.
In Powershell you can use Get-Content with the -Wait flag:
Get-Content filename.log -Wait
You can shorten Get-Content to gc. That question suggested as a possible duplicate has an answer which mentions this and some useful extra parameters -
see https://stackoverflow.com/a/188126. I'm not sure if it's really a duplicate, though, since that question is talking about general Windows alternatives to Linux tail, rather than about tail -f.
In Powershell use:
cat .\<file_name> -Tail 10 -Wait
Yes. you can use tail on windows, which is a small price to pay to get access to a lot of GNU-tools on windows as well as tail. Because its bundle with git for windows, its pretty heavily tested and stable.
First install git-bash from https://gitforwindows.org/
Next, put git-bash on windows path using and reboot your workstation:
setx path "%path%;C:\Program Files\Git\bin\"
Now, you should be able to use tail -n 20 -F logging_file.log to tail any file and show the last 20 lines.
If you are on Linux/Unix and you want to continuously see logs you can use the following command:
ssh username#10.15.3.3 'bash -c "tail -n 20 -F /c/Users/username/Desktop/logging_file.log"'
I know you said without external program. But for the people who have already installed the Windows Subsystem for Linux (WSL) and they cannot make tail work properly in Ubuntu 16.04 LTS I found this thread where somebody found a workaround:
In case anyone finds this through Google, it seems that inotify support in WSL is limited to WSL file accesses, not win32 file accesses, so you have to tell tail not to use it:
tail -f /mnt/c/path/to/file ---disable-inotify
(yes, three dashes)
Get-Content filename -Wait -tail 1
this worked for me, as said by nikobelia, just added the tail option and it works as expected!
I am running Mac OS X ( 10.9.4 ) using the built in Terminal, and bash version:
3.2.51(1)-release (x86_64-apple-darwin13)
At one point in the past, there was a CLI command I could issue that would show me what was going on with my drives, kind of like a tail -f system.log but deeper into the system where it would look at the actual drives and what was going on. A fully idle machine, say one that was sleeping and I was ssh'd into, would show a page that was doing little or nothing. Saving a file, or doing anything disk related, and tons of data would scroll past, which you could pipe to a file and grep through.
I have goggled and can't find this command.
Not sure about Mac OS X, but on Linux, there are several:
iostat
iotop
sar
dstat
vmstat
iozone
Most of them should be available on Mac OS X. I know that iostat is.
Or you can always look in
/sys/block/[device]/stat
or
/proc/diskstats
This was in fact a duplicate of question noted by anishane.
The command I was looking for was fs_usage but lsof, while not exactly what I wanted, is a close second in being helpful to track down the problems I'm running into.
I think you are looking for iosnoop. Seems like it is a wrapper on dstat only, as when I ran it without sudo it gave me the following error.
% iosnoop
dtrace: system integrity protection is on, some features will not be available
dtrace: failed to initialize dtrace: DTrace requires additional privileges
I'd like to mount a Samba drive in OS X using bash. This line does the trick:
mount -t smbfs //$SAMBAUSER#$ADRESS/$NAMEOFSHARE $MACOSXPATH
only one problem. I want it done without user input - which means no password can be manually put in. And I'm not going to ask my users to download fink just so they can install expect (as seen here).
I tried applying the accepted solution to a similar StackOverflow problem shown here by doing this:
echo "mypassword" | mount -t smbfs //$SAMBAUSER#$ADRESS/$NAMEOFSHARE $MACOSXPATH --stdin
but no luck - that doesn't work and Mac OS X tells me I used mount command improperly:
usage: mount [-dfruvw] [-o options] [-t ufs | external_type] special node
mount [-adfruvw] [-t ufs | external_type]
mount [-dfruvw] special | node
Any suggestions? This would be easy with an expect script - but that would ruin the user experience to have that prerequisite in my mind.
If mount(8) can't just call the mount syscall on the filesystem, it looks for a program to help it. On FreeBSD and Mac OS X, those helper programs follow the naming convention mount_XXX, where XXX is the -t argument's value.
That means you want to check the mount_smbfs(8) man page, which tells us about -N:
-N Do not ask for a password. At run time, mount_smbfs reads the ~/Library/Preferences/nsmb.conf
file for additional configuration parameters and a password. If no password is found,
mount_smbfs prompts for it.
Unfortunately the man page trail ends with one for nsmb.conf that doesn't mention anything about storing passwords. On FreeBSD 8.0, at least, the solution is to put a password key with a plain text(!) password value under a [SERVER:USER] heading. That would be type C according to the linked nsmb.conf man page.
So it seems that you'll want to dump a pre-configured nsmb.conf into your user's ~/Library/Preferences/ directory and then call your mount command with -N. As far as I know you can't provide a hashed value, which is not especially awesome. I'll try to get access to a MacBook in a few hours to test this.
NB: This is not how to do it with the GNU toolchain. If you're on Linux, you're probably going to be using something like mount.cifs(8). The correct solution in that case is the credentials=filename option (used after -o, of course), where filename is a file of credentials in key=value form, separated by newlines. See http://linux.die.net/man/8/mount.cifs
The answer in this apple support discussion thread worked for me:
osascript -e 'mount volume "smb://user:password#server/share"'
I'll give you 2 options. First, include the password on the command line:
mount -t smbfs //$SAMBAUSER:$PASSWORD#$ADRESS/$NAMEOFSHARE $MACOSXPATH
This is not a great option because the command line (including password) is visible to anyone who happens to be logged in at the moment. Not great, but it is a possibility.
Second, use expect. The Mac OS X Hints article you linked dates from 2002, when OS X v10.2 would've been current. While 10.2 apparently didn't include expect as a standard component, 10.6 does, and I'm pretty sure it's been included for several versions now.
#!/usr/bin/expect -f
spawn mount -t smbfs //fred#12.34.56.78/myfiles /tmp/mountpoint
expect "Password:"
send "wibble\r"
wait
You not only can use a hashed value, you're expected to, at least in older releases. The crypt option for smbutil is not DOD-level security but as with most security, you're trying to keep the honest people honest: the bent ones will find a way. It seems to be broken in Mountain Lion but the nsmb.conf file in ~/Library/Preferences should be secure at the OS level. The /etc/nsmb.conf would override it if it exists. I'm sure there's a reason why plain text files are obsolete but didn't we go this with NetInfo? How long did it take for Apple to allow the old standbys (/etc/hosts, /etc/passwd) to be used?
I would like to compare all GNU Unix manuals and and Mac's Unix manuals by sdiff.
I do not know how you go through, for instance, all Mac's Unix manuals and then save them to a file.
The comparison can be done by the following code when the manuals are in two files
sdiff <(file1) <(file2)
Perhaps, there is some index of Unix command names such that we can do the following
sdiff <(man *[in the index]) <(man *[in the index])
How can you compare all GNU Unix manuals with all Unix manuals in Mac?
[edit]
Mac's manuals are at /usr/share/man/man[1-9]/*.
I have an encoding problem with them when I try to cat them.
Another problem is to find the location of Coreutils' manuals.
Your goal, to identify the differing parameters for the different BSD vs GNU/Linux versions of the various programs, is going to be somewhat tedious. It's useful to note that there are other variants of all commands as well. There are system V versions and BSD versions and GNU versions, and the Mac uses a mish-mash of all 3. In any event, as a starting point, the files themselves are filled with formatting macros that you have no interest in. Pipe the output of man through 'col -b' to get data you can diff. In terms of generating the list of commands, you could just ls -1 /bin /usr/bin' Then something like this would get you most of the way:
while read command ; do
man $command | col -b > output1
man ./path/to/GNU/$command | col -b > output2
diff output1 output2 | grep '^[ ]*-' > $command.diffs
done<<EOF
diff
grep
sort
...
...
EOF
GNU means (G)NU is (N)ot (U)nix. GNU is not based, in any way on UNIX, it could not be due to copyright and licensing issues.
Most GNU documentation was written in texinfo format (which Debian later converted to roff (man) format as users wanted man pages). The documentation is in no way based upon the BSD documentation, everything in GNU was written from scratch.
Trying to diff between the two is like diffing a dictionary against a thesaurus. You will find that they both contain many of the same words, but are entirely different books written by entirely different people.
The documentation in no way adequately explains the differences between GNU and BSD (and by extension MacOS).
All man pages exist within the /usr/share/man/*; I'm not sure what you are attempting to accomplish here. Mac runs on BSD, so most applications are going to be the same as the ones you would find on the BSD machine. If you still wanted to do it, you would need to grab the manual pages of the same applications in *nix as in Mac as well as the same version (since the man page can change). And yea, I would say that doing a diff /usr/share/man/man[0-9]/* and the expanded tar of all the man pages from the linux box.
I am writing a console application which makes use of the F1 key (for help). Unfortunately, while Konsole (of KDE) doesn't use this key, Gnome Terminal does, so the F1 key becomes inaccessible to my application. I don't think there's a way to detect whether the F1 key is already mapped in the GUI side of things (Gnome Terminal), but if there is, the answer to that will obviate this question. :)
Ergo, my next best bet is to try to detect whether I am running inside Gnome Terminal. Is there some way to do that? I'm primarily interested in gleaning this from within Ruby, but if it can be done via shell or environment variables, or virtual filesystem (/proc, /dev, etc.) then that will suffice.
I'm hoping for a reliable way to do this, but I can settle for "best guess" approaches like grepping the environment variables for clues that can let me reasonably assume that Gnome Terminal is the wrapping terminal.
Extra info: other keys are also "stolen" by Gnome Terminal. I intend to display some sort of informative message about alternative keys for Gnome users.
Googleage has revealed that I might be able to rely on Gnome Terminal setting the COLORTERM environment variable to 'gnome-terminal'.
For zsh:
[[ "$COLORTERM" == "gnome-terminal" ]] || [[ ${$(ps -p $(ps -p $$ -o ppid=) -o cmd=):t} == gnome-terminal* ]]
gnome-terminal used to set $COLORTERM, but this has been dropped (in 3.12.0-67-g1d5c1b6).
Normally you use termcap info aka terminfo. This tells you what kind of terminal you're working with and also what the keys are.
It is the user's choice, and since Gnome Terminal reports itself as probably a kind of x-term, as Konsole likely does, there is likely a way for the user to create an F1 keypress. Therefore, I suspect that the terminal capabilities of the two will be reported as equivalent.
This investigation of Function Key Escape Codes might be interesting to you without actually explaining how, if it is even possible, that the gnome terminal could be made to produce an F1 press. Thinking of the Mac OS X terminal I used a long time back, it caught PageUp and PageDown for the scroll bar, while Command-PageUp and Command-PageDown passed them through to the terminal.
A rather crude method, if you feel like delegating this to the shell -- otherwise, in C or C++, you will have to wade through your /proc, if you have one:
ps x | grep `ps o ppid,fname | grep bash | grep -v grep | head -1 | awk '{print $1}'` | grep 'gnome-terminal' | wc -l
If running from your own program, through system() for instance, you may with to 'grep' your program's name rather than 'bash'
I know, it's definitely "hack like a pirate" ;)
fwiw, this is a setting in gnome-terminal; users can go to Edit -> Keyboard Shortcuts in the gnome-terminal menus and change or delete the F1 keybinding.
I simply check the $TERM for the terminal emulator of my choice and then add an alias for spawning a new terminal in the current directory.
if [[ $TERM == 'xterm' ]] ; then
alias nw='gnome-terminal --working-directory=$PWD'
fi