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!
Related
I have a lot of files with names in one language and I need to rename them all to another one.
Is there any script for this? (preferably on Mac)
Figured it out. We can do it with translate-shell CLI utility.
Install it with brew install translate-shell
Then run next script in your folder:
for i in *.txt
do
sleep 5
mv -i "$i" "$(echo ${i%.txt} | trans -b nl:en).txt";
done
translate-shell makes a call to Google Translate server to do translation
sleep 5 is needed to avoid being blocked by Google's server for too many requests in a second
trans is actual translate command
-b stands for "brief", as we don't need verbose output
nl:en are the source and destination languages
I've used jq on Mac/Unix successfully for several years and have now been asked to port a project from Mac to Windows.
My problem is that I am unable to run any command in jq under Windows with the .json files that work perfectly on the Mac.
This includes the simplest command:
jq -r . /path/to/json.json
All commands cause a crash of jq. I'm running Windows 10 Pro.
What I've tried:
-Installing jq using chocolatey as well as downloading the precompiled 32-bit and 64-bit binaries directly.
-Using a standard command prompt, an elevated command prompt and PowerShell.
The .json files all have UTF-8 encoding without BOM and I've tried them with both Windows and Unix line endings. jq crashes regardless.
Can anyone please provide any guidance as to why a simple port to Windows would be so problematic, or maybe some simple issue I am overlooking?
Thanks
This includes the simplest command:
jq -r . /path/to/json.json
To ascertain the nature of the problem, it would probably be better to start with an even simpler command, such as:
jq -n .
If that fails, maybe there is a 32-bit/64-bit mismatch.
Also, when specifying pathnames, you will have to use Windows conventions.
Please note that jq 1.5 cannot handle long Windows pathnames. You can obtain a more recent version of jq pre-compiled for Windows from Appveyor, as explained at
https://github.com/stedolan/jq/wiki/Installation#windows-using-appveyor
I am running Windows 10 on this laptop and recently was recommend to install grep. Well I did that by installing it with a program called GNUWin32.
For some reason I can't get grep to work. Maybe I'm stupid? I don't know but when I type the grep command in CMD it doesn't recognize it.
Any ideas?
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.
I would like to redirect the output from a command to a file and to stdout. I am using Windows XP command line.
I realize that there is a command in linux called tee which will do this, but I want this in windows.
The first hit when googling windows tee gives UNIX-style tee utility for Windows
Use tee for windows.
The simple DOS shell doesn't have the ability to do this simultaneously.
Try using:
Windows PowerShell
or
Cygwin
If using tee (one of the various Windows variants) isn't an option and the command isn't long-running or you don't need to do further processing of the output in real time, then
command > file && type file
would do that for you. But only under the mentioned circumstances. You're probably be better off using tee.
PowerShell has tee-object (standard alias tee) if you are using a decent shell.