# RP/JDA WMS Essential OS commands every MOCA Developer should know

In this blog, I’ll list out some basics OS commands that every developer should know. I am hoping you will find this guide essential for your day to day activities.

Finding environment variables:

Windows: setRHEL: printenv or env

To sort environment variables (/R in Windows or -r in RHEL will reverse sort the result set):

Find specific environment variables:

Windows: set | findstr “DIR”RHEL: printenv | grep DIR

Find a file:

Windows: dir /s filename or foldernameLinux: locate filename or foldername----OR----find /directorytosearch -type d -name “log” — for folderfind /directorytosearch -type f -name “rollout.pl” — for file

However, do note that the locate command in Linux may not work on recent files (created less than 24 hours ago) as the “updatedb” command runs once a day. Locate command also requires the mlocate package to be installed.

Search through multiple files containing a specific text:

There are times when you want to easily be able to search multiple files or even thousands of files in a folder and its subfolders, you can use the following command to accomplish this.

Windows: find /i "search text" path\to\search\*.*RHEL: grep -rnw '/path/to/search' -e 'search text'

Windows:

RHEL 7:

Print/display a file on cmd/terminal:

Windows: type filenameWindows: more filenameRHEL: cat filenameRHEL: cat –n filename (with line number)

Print specific lines matching the criteria:

Windows: type build.xml | findstr “LES”RHEL: cat [-n] build.xml | grep LES

Print start or end of the file:

Windows (cmd):more +n filename   --where +n prints after the nth line----OR----Windows (powershell):get-content filename -head 30  --prints first 30 linesget-content filename -wait –tail 30  --print last 30 lines-wait flag is the equivalent to -f in linux, which is to wait and print more output as lines are appeneded to a file.RHEL:head -n 30 mocaserver.log   --prints the first 30 linestail -n 30 mocaserver.log   --prints the last 30 linestail -f mocaserver.log      --prints output as file is writtentail -10f mocaserver.log    --prints last 10 lines and waits for output

Understanding File Permissions in Linux:

Here is a sample directory of LES.

d | Owner | Group | Others |directory  rwx     rwx     rwxWhere Read = 4, Write = 2 and Execute = 1So, chmod 7 5 5 — Full permission for the owner, read and execute access for the group and others not in group (thus denying permission to write).chmod u+x filename — Makes the file called filename executable to owner exclusively.Similary chmod +x filename — Makes the file called filename executable to all users

# Redirecting output; understanding pipes and ampersand:

command > filename    -- redirectsoutput to a file (overwrite)command >> filename   -- appends output into a filecommand1  |  command2 -- passses output from command1 into command1command1 ; command2   -- runs command2 even if command1’s failscommand1 & command2   -- run command1 and then run command2command2 && command2  -- run command1 and only run command2 if first    one is successfulcommand1 || command2  -- run command1, if it fails only then run command2

I will first cover the pipes and ampersand and then talk about redirecting output below this. To explain the screenshot below, I have highlighted the commands in red and I will explain what each operator does:

1. ; — command 2 will execute regardless if command1 fails or not.
2. & — command2 will execute regardless if command1 fails or not.
3. && — command2 will only execute if command1 is successful. If you look at the 4th underlined command, I intentionally made a syntax error in the 4th command and proved that command2 will not run if command1 fails.
4. || — command2 will only execute if command1 fails. The 2nd last highlighted command has a syntax error, so we can see that only command2 was successful. In the last example when command1 is successful, command2 doesn’t run.

I have intentionally left out the pipe | operator as we’ve covered in some of the examples above.

# Redirecting output to a file:

Appending output into an existing file:

Simple enough, let’s see if we run mbuild and redirect its output into a file. So below is what a sample mbuild output looks like on my JDA WMS instance. We’re hoping to have the same output in a file using redirection.

Please note that I have intentionally inserted an error into a command to make things interesting. If we run mbuild > mbuild.log it doesn’t show me all the warnings or errors and only inserts the portion after that into the mbuild.log file. Why is that?

Let’s see if we can change that. When we run the following command, the errors and warning are redirecting into the mbuild.log but not the statistics below is:

mbuild 2> mbuild.log

Now, what if we want to redirect all the output into the file. I will use the script below:

mbuild 2>&1 mbuild.log

To suppress output and only insert into the file, we can modify our script as below:

mbuild > mbuild.log 2>&1

and there we have it! My goal here is to give you some examples to gain your interest to explore these commands, practice, and understand through experimentation what works and what doesn’t so you can master it according to your needs.

--

--

--

## More from Ali Ahmed

I am an experienced IT Consultant who has a knack to solve complex problems. Want to connect? Reach out to me on: http://www.linkedin.com/in/ali-ahmed-jdawms

Love podcasts or audiobooks? Learn on the go with our new app.

## Ali Ahmed

I am an experienced IT Consultant who has a knack to solve complex problems. Want to connect? Reach out to me on: http://www.linkedin.com/in/ali-ahmed-jdawms