TOPIC: UNIX
File comparison using PowerShell
16th August 2025In the past, I have compared files on the Linux/UNIX command line as well as the legacy Windows command line. Recently, I decided to try it using PowerShell. Here is the command structure:
Compare-Object (Get-Content ".\[name of one text file]") (Get-Content ".\[name of another text file]") > [path and name of output file]
Admittedly, this is more verbose than the others that I have mentioned above. Nevertheless, it does the job and sends everything to a text file for review. The Compare-Object
piece does the comparison once the Get-Content
portions have read in the content.
Unzipping more than one file at a time in Linux and macOS
10th September 2024To me, it sounded like a task for shell scripting, but I wanted to extract three zip archives in one go. They had come from Google Drive and contained different splits of the files that I needed, raw images from a camera. However, I found a more succinct method than the line of code that you see below (it is intended for the BASH shell):
for z in *.zip; do; unzip "$z"; done
That loops through each file that matches a glob string. All I needed was something like this:
unzip '*.zip'
Without embarking on a search, I got close but have not quoted the search string. Without the quoting, it was not working for me. To be sure that I was extracting more than I needed, I made the wildcard string more specific for my case.
Once the extraction was complete, I moved the files into a Lightroom Classic repository for working on them later. All this happened on an iMac, but the extraction itself should work on any UNIX-based operating system, so long as the shell supports it.
Another way to supply the terminal output of one BASH command to another
26th April 2023My usual way for sending the output of one command to another is to be place one command after another, separated by the pipe (|
) operator, adjusting the second command as needed. However, I recently found that this approach does not work well for docker pull
commands until I uncovered another option.
The solution is to enclose the input command in $( )
within the output command. Within the parentheses, any kind of command can be declared and includes anything with piping as part of it. As long as text is being printed to the terminal, it can be fed to the second command and used as required. Thus, you can have something like the following:
docker pull $([command outputting name of image to download])
This approach has helped with other kinds of automation of docker image and container use and deployment because it is so general. There may be other uses found for the approach yet.
Killing Windows processes from the command line
26th September 2015During my days at work, I often hear about the need to restart a server because something has gone awry with it. This makes me wonder if you can kill processes from the command line, like you do in Linux and UNIX. A recent need to reset Windows Update on a Windows 10 machine gave me enough reason to answer the question.
Because I already knew the names of the services, I had no need to look at the Services tab in the Task Manager like you otherwise would. Then, it was a matter of opening up a command line session with Administrator privileges and issuing a command like the following (replacing [service name] with the name of the service):
sc queryex [service name]
From the output of the above command, you can find the process identifier, or PID. With that information, you can execute a command like the following in the same command line session (replacing [PID] with the actual numeric value of the PID):
taskkill /f /pid [PID]
After the above, the process no longer exists and the service can be restarted. With any system, you need to find the service that is stuck to kill it, but that would be the subject of another posting. What I have not got to testing is whether these work in PowerShell, since I used them with the legacy command line instead. Along with processes belonging to software applications (think Word, Excel, Firefox, etc.), that may be something else to try should the occasion arise.
Copying only updated and new files
20th October 2008With Linux/UNIX, the command line remains ever useful and allows you to do all manner of things, including file copying that only adds new files to a destination. Here's a command that accomplishes this on Linux:
cp -urv [source] [destination]
The u
switch does the update while r
ensures recursion (by default, cp
only copies files from a source directory and not anything sitting in subfolders) and v
tells the command to tell the user what is happening.
Though buried and hardly promoted, Windows also has its command line and here's what accomplishes a similar result:
xcopy /d /u [source] [destination]
Anything's better than having to approve or reject every instance where source and destination files are the same or, even worse, to overwrite a file when it is not wanted.
How much space is that folder taking up on your disk?
23rd July 2008On Windows, it's a matter of right-clicking on the folder and looking in its properties. I am sure that there is a better way of doing it in that ever pervasive operating system but, in the worlds of Linux and UNIX, the command line comes to the rescue as it is wont to do. What follows is the command that I use:
du -sh foldername
The s
option makes it present the total space taken up; leaving it out gets you a breakdown of how much space the subfolders are taking up as well. The h
makes the sizes output more friendly to human eyes with things like 10K, 79M and 51G littering what you get. The command itself is a much shorter way of saying "print disk usage". It's all quick and easy when you know it, and very useful in this age of ever-increasing data volumes.
A quick way to create a blank text file
27th June 2008The primary job done by the touch command in UNIX or Linux is to update the time stamps on files. However, it also has another function: creating an empty text file where you are "touching" a file that doesn't exist. This has its uses, particularly when you want to reduce the amount of pointing and clicking that you need to do, or you want to generate a series of empty files in a shell script. Whatever you do with it is up to you.
Putting it all on one line
9th March 2008One of the nice things about the Linux/UNIX command line is that you get the options of stringing together a number of commands on one line for submission of all for processing at one go. Separating them with && does the trick, but I noticed that semicolon delimitation worked as well. Here's a line that will install VMware for you in one fell swoop:
sudo apt-get install linux-headers-$(uname -r) build-essential gcc-3.4 && tar xzf VMware-workstation-6.0.2-59824.i386.tar.gz && export CC=/usr/bin/gcc-3.4 && cd vmware-distrib && sudo ./vmware-install.pl
Another trick is to direct the output of one command into another, like the following, which subsets a process listing:
ps -aux | grep "wine"
It's all good stuff and is the sort of thing that shows why so many Linux/UNIX types love their command line so much.
A year in the making…
17th January 2008It was a year ago that I set this blog on the go. Then, I was exploring the possibilities offered by WordPress.com. After some months, I decided that I wanted to make my own decisions rather than have them, so I went independent in June. Between those dates, some big launches took my attention: Windows Vista, Office 2007 & CS3 come to mind. All the while, my experience of UNIX, Oracle and other such matters kept growing more and more. In the latter half of the year, I finally made the leap from Windows to Linux on the home computing front, a decision that taught me a lot and one that I don't regret. Other subjects featured from time to time as well; my musings on web development and blogging made their appearance too. 2007 was a packed year on the technology front, and 2008 is only just getting under way. There's a Vista laptop, and I am already picking up ideas for posts, though I am not going to force them out like I might have tried to do last year. 2008 may be a spot more leisurely, but I hope that it's just as interesting.
A UNIX shell running on Windows
15th November 2007Here's an idea that I got for a post before I spent that torrid weekend with Windows that caused me to jump ship to Linux. The idea of having a UNIX command line while still remaining on Windows did appeal to me at the time, and Cygwin seems to provide an intriguing way to do this. At its most basic, it is a set of DLL's that allow you to run standard UNIX commands in a shell like what you see below. However, it is extensible with a good number of packages that you can choose to install. NEdit is just one that gets included, and I think that I spied Apache too. The standard installation is a web-based affair, with your downloading only the components that you need; it's worth trawling through the possibilities while you're at it.
Now that I am firmly ensconced in the world of Linux, this may be one possibility that I will park, for a while anyway. After all, I now do have the full power of the UNIX command line...