User Tools

Site Tools


Site Information

Interactive Maps



Linux Commands

This is a page I had previously created elsewhere, but now that I've installed Ubuntu in Windows 10 [2019.03.03] and started a new Linux section in the Wiki, I've moved this here until each command has it's very own page.

"We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris."
– Larry Wall, from the book Programming in Perl, Preface.

"Ninety percent of the battle is knowing you can or cannot do something.
Five percent is finding someone else's code that comes close to what you need.
Three percent is modifying their code to do what you need.
Two percent is taking credit for having done it."
– Terrill Bennett

A few of our rarely-used but awesome when you find 'em commands. Since we no longer do this stuff on a daily basis, and my brain is full, we occasionally need a reminder of what we once did!

Windows 10 Subsystem

We can now install various Linux distributions as subsystems to Windows 10 (includes Windows 10 Home edition!). You can install as many distributions as you'd like!

Ubuntu Updates/ Upgrades

  • Update updates the list of packages.
  • Upgrade does the actual updating.
sudo apt-get update
sudo apt-get upgrade

Additionally you can run:

sudo apt-get dist-upgrade

Things I did…

sudo add-apt-repository universe
sudo apt-get install p7zip-full
sudo apt-get install unzip
sudo apt install speedtest-cli


This looks like it hangs … right up until it completes doing the test. So grab a cup of coffee, chat with coworkers at the water cooler, sit back, relax, and wait patiently while it executes!

$ speedtest-cli --simple --no-pre-allocate
Ping: 67.229 ms
Download: 9.82 Mbit/s
Upload: 1.70 Mbit/s


When you don't have the ability to NOT enter your password for things like sftp, and you absolutely MUST supply your password on the command line, you'll want to install sshpass. On a real Linux server, this could be dangerous since it's possible for others to see your password using ps, not to mention by simply reading your code! That said:

  • Try: sudo apt-get install sshpass
  • If that fails, then:
    • sudo apt-get update
    • apt-cache search sshpass
    • (If it's found, then)
    • sudo apt-get install sshpass

Once sshpass is available, then:


csh / tcsh

Programming Chapter 8. csh and tcsh

To install tcsh and csh, and make csh your default shell:

$ sudo apt-get install tcsh
$ sudo apt-get install csh
$ which csh
$ chsh -s /bin/csh

mv / rename

Changing Multiple Files
Most modern Linux comes with a rename command.

Show what would happen if you executed (i.e. "test 1st, do 2nd""):

rename -n 's/\.gz$/\.tgz/' *.gz

Sample Output:

[myserver]$ rename -n 's/\.gz$/\.tgz/' *.gz
file1.gz renamed as file1.tgz
file2.gz renamed as file2.tgz

To actually rename, remove the "-n" option. Like most Linux commands, "no news is good news!"

[myserver]$ rename -n 's/\.gz$/\.tgz/' *.gz


for f in *.png; do mv "$f" "${f/_h.png/_half.png}"; done

The above could also be written in a shell script as:

for file in *_h.png
  mv "$file" "${file/_h.png/_half.png}"

Sample output:

$ rename 's/_h.png/_half.png/' *.png
$ ls
one_half.png  three_half.png  two_half.png


* Remove MS-DOS 'CRLF' from file:
perl -pi -e 's/\r\n/\n/g' test.txt


Create tar archive:
tar cvzf My.tar.gz /path/to/directory-or-file
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

* List contents of tar.gz:
tar -ztf My.tar.gz

* List verbose contents of tar.gz:
tar -ztvf My.tar.gz

* Extract tar.gz archive:
tar -zxvf My.tar.gz

* Show log file while command is running:
tail -f tar.log


Need the properties of a video file? If you do a which command and find one of these tools available, then life is good!


avcon does video and audio.

$ avconv -i myvideo.mp4
avconv version 0.8.17-4:0.8.17-0ubuntu0.12.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Mar 16 2015 13:26:50 with gcc 4.6.3
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'myvideo.mp4':
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2014-10-29 21:15:37
  Duration: 00:01:55.96, start: 0.000000, bitrate: 357 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 640x296 [PAR 1:1 DAR 80:37], 259 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc
    Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 95 kb/s
      creation_time   : 2014-10-29 21:15:38
At least one output file must be specified


exiftool does " EXIF, GPS, IPTC, XMP, JFIF, GeoTIFF, ICC Profile, Photoshop IRB, FlashPix, AFCP and ID3, as well as the maker notes of many digital cameras by Canon, Casio, DJI, FLIR, FujiFilm, GE, HP, JVC/Victor, Kodak, Leaf, Minolta/Konica-Minolta, Motorola, Nikon, Nintendo, Olympus/Epson, Panasonic/Leica, Pentax/Asahi, Phase One, Reconyx, Ricoh, Samsung, Sanyo, Sigma/Foveon and Sony."

$ exiftool hbd0x44Mitzi.mp4
ExifTool Version Number         : 8.60
File Name                       : myvideo.mp4
Directory                       : .
File Size                       : 4.9 MB
File Modification Date/Time     : 2016:10:11 13:06:18-07:00
File Permissions                : rw-r--r--
File Type                       : MP4
MIME Type                       : video/mp4
Major Brand                     : MP4 v2 [ISO 14496-14]
Minor Version                   : 0.0.0
Compatible Brands               : isom, mp42
Movie Header Version            : 0
Create Date                     : 2014:10:29 21:15:37
Modify Date                     : 2014:10:29 21:15:37
Time Scale                      : 600
Duration                        : 0:01:55
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Track Header Version            : 0
Track Create Date               : 1904:01:01 00:00:00
Track Modify Date               : 2014:10:29 21:15:38
Track ID                        : 1
Track Duration                  : 0:01:55
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 640
Image Height                    : 296
Graphics Mode                   : srcCopy
Op Color                        : 0 0 0
Compressor ID                   : avc1
Source Image Width              : 640
Source Image Height             : 296
X Resolution                    : 72
Y Resolution                    : 72
Bit Depth                       : 24
Video Frame Rate                : 29.97
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2014:10:29 21:15:38
Media Modify Date               : 2014:10:29 21:15:38
Media Time Scale                : 44100
Media Duration                  : 0:01:55
Media Language Code             : und
Handler Description             : IsoMedia File Produced by Google, 5-11-2011
Balance                         : 0
Audio Format                    : mp4a
Audio Channels                  : 2
Audio Bits Per Sample           : 16
Audio Sample Rate               : 44100
Handler Type                    : Metadata
Handler Vendor ID               : Apple
Movie Data Size                 : 5147511
Avg Bitrate                     : 355 kbps
Image Size                      : 640x296
Rotation                        : 0

Call bash in DOS

In cmd, DOS Batch file or Powershell:

bash -c linux_comand

For example, in DOS cmd:

C:\tmp> bash -c ./

sftp using batch commands:

wiki/lnx/cmds.txt · Last modified: 2019/07/22 09:20 by terrill