This Guide contains all the Linux commands that you may have to use for ThingWorx Analytics Installation or day to day use.

 

Command/Category

Description

Network/port

 

ip a

List the ips of all of the network interfaces

ssh

How to jump from one machine to another

ping

Send packets to a remote machine.  useful for testing connectivity

netstat –anp

Check active port

cat < /dev/tcp/localhost/8080

Test connection to a port

Replace localhost with desired hostname or ip, replace 8080 with desired port number

(/dev/tcp/host/port)

exit

Exit my current sign in.  this lets one disconnect from remove ssh sessions or if one has changed one's user e.g. switched to root

scp

Retrieve something via ssh

Resource Usage

 

free -m

Check memory

-m is for output in Mb

Mpstat -P ALL

CPU usage

top

Process usage

jvmtop

Collect cpu usage of jvm and its thread

https://github.com/patric-r/jvmtop

(requires jdk to be installed)

File Interaction

 

cp / mv

Copy and move respectively. mv just deletes the source file.  Usage: cp /source/location/file /output/location/file

cat

  1. Mostly used to just print the contents of a file to the command line.  can also print multiple files at once:  cat /var/log/gridworker/warning.log /var/log/gridworker/error.log

vim / vi

A command line text editor. Not the most user friendly (none of them are) but really useful. Here's a cheat sheet for the commands https://www.fprintf.net/vimCheatSheet.html

rm

Remove files

chmod

Change the access permissions of files

chown

Change the user or group ownership of files

grep

A text based filtering.  Useful for making a larger list smaller and more targeted.  Almost always used after a pipe (see pipe below)

less

Generally used to view the contents of a file with more friendly scrolling

locate

Find a file by name

Directory

 

ls

What’s in the directory.  Will do the current directory but you can also pass the directory e.g. ls /var/log/tomcat.

  • Black writing is files
  • Blue writing is directories
  • Red writing is compressed file

pwd

Tell me which directory I'm currently in

cd

Change directory.  provide the directory to change to or just use cd to return to the user's home directory

clear

Clears the screen Terminal clears all provided commands

mkdir

Creates Directories

Running Processes

 

ps

Query what services are running. usually use ps -aux to get a full, sorted list.  using grep with this is helpful

systemctl

The correct way to interact with services that are running

Package installation

 

yum install <packageName>

Install a package. More useful commands: https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-yum-useful-commands.html

yum list installed

List installed packages

yum list <package>

List available packages

yum --showduplicates list java-1.7.0-openjdk-devel

Use --showduplicates to see all versions

Can use * for package name: *openjdk*

rpm -ql <packagename>

Find where package are installed

Note: works if package installed with yum

Yumdownloader --urls <packageName>

Find URL where a package is downloaded from.

Note: need to install yum-utils package

Repoquery --requires <packageName>

Find dependencies of a package

Note: need to install yum-utils package

repoquery --qf=%{name} -g --list --grouppkgs=all [groups] | xargs repotrack -a x86_64 -p /repos/Packages

Download a package with all its dependencies. Need to install yum-utils package From  <http://unix.stackexchange.com/questions/50642/download-all-dependencies-with-yumdownloader-even-if-already-installed>

Other Commands

 

curl http://localhost:8080/1.0/about/versioninfo

Send REST call via command line

Use -X POST (default GET) for a POST (see man

page - https://curl.haxx.se/docs/manual.html for example)

See also http://www.codingpedia.org/ama/how-to-test-a-rest-api-from-command-line-with-curl/

Find / -type f -exec grep -I mystring {} \;

Search string in files

Sudo -u user command

Execute a command as different user

 

 

 

The below helpers are not commands themselves, but can be used in conjunction with the above commands.

Helper

Description

'pipe'

The | character.  lets one chain commands.  e.g. ps -aux | grep java

./

The shorthand way to refer to this directory explicitly

../

The shorthand way to refer to the parent directory

'tab completion'

Pressing tab will let linux guess what command/option best fits what's currently written.  very useful for navigating directories and long-named files (NOTE: not necessarily tab based upon one's keyboard layout/language)

'ctrl-r'

Look up the mostly likely command that matches what one typing.  so if one earlier used ps -aux | grep java | less and the hit ctrl-r and typed -aux it would likely pull that command or at least the most recent one that matches