Support Support Downloads Knowledge Base Case Manager My Juniper Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

[Junos] Common CLI commands which replace shell commands

0

0

Article ID: KB14066 KB Last Updated: 03 Mar 2020Version: 3.0
Summary:

The CLI has many operations that replace the need to use the shell on a device running Junos OS. This article lists some common CLI commands that replace the shell commands.

 

Symptoms:

Operation in the shell is not supported by Juniper. However, there are many equivalent ways to operate the CLI that a FreeBSD savvy user may be familiar with. Shell commands should be used only under the guidance of a JTAC engineer in very limited circumstances. Many deterministic features of shell operations on Junos OS are not documented, and are not supported to provide consistent results. The primary line of troubleshooting resides with the CLI and Juniper approved methods, including other knowledge articles and online documentation. Stability of the platform can be adversely affected by improper use of the shell.

 

Solution:

The following FreeBSD commands (or any UNIX friendly platform) can be run in a different way in Junos OS with equivalent, or near equivalent results. More extensive use of operators and their differences are left up to the user. It is assumed that the user has some background with FreeBSD or other UNIX friendly platforms, and is already familiar with common shell commands. This article provides an alternative to using the shell.

  • ls(1) - List directory contents.

lab@cli> file list <detail> <path>

The -l switch for ls is the detail knob for file list. Path supports command-line globbing, but accepts only one parameter.

  • tail(1) - Output the last part of files.

lab@cli> show log messages | last 10

The -n switch is handled by specifying a number. Otherwise, the default is about 10 lines (like tail).

To emulate the -f switch of tail (follow), use the monitor start <file> command. This is similar to tail -f <file> &. Only new lines will be displayed. Stop all output with monitor stop.

  • w(1) - See who is logged in and what they are doing.

lab@cli> show system users
  • ps(1) - Show current processes.

lab@cli> show system processes
  • kill(1) - Send a signal to a process.

lab@cli> restart <service|feature>

This is less like kill, but more like issuing a restart of an init script. This controls how aggressively the service or feature is restarted.

  • uptime(1) - Tell how long the system has been running.

lab@cli> show system uptime

Some Juniper products have distributed processing, so other components may have their own individual uptime that is separate from the system uptime shown by the CLI.

  • df(1) - File system disk space usage

lab@cli> show system storage
  • ifconfig(1) - Interface settings

lab@cli> show interfaces

Changing the way the interface is configured is primarily in [edit interfaces] of the configuration hierarchy.

  • route(8) - Show and manipulate the routing table.

lab@cli> show route

Again, operational commands display only the current state of available information. Modification to routing should be done in configuration mode. This is beyond the scope of this article.

  • cp(1) - Copy files.

lab@cli> file copy <source> <destination>

The source and destination support different styles of URLs. Files can be copied to and from reachable FTP, HTTP, HTTPS and SCP servers to name a few.

  • rm(1) - Remove files.

lab@cli> file delete <path>

File globbing and multi level file globbing are permitted. However, only one path may be provided. Globbing here should be used with care.

lab@cli> file delete october*.conf  will delete files with october at the beginning of the name and with .conf at the end.

  • shred(1) - Overwrite file contents.

For the truly paranoid, you can blank out the file before it is erased. This prevents recovery of the file contents with third-party recovery methods or tools.

lab@cli> file delete <path> purge

Eg:

lab@cli> file delete super-top-secret.conf purge
  • mv(1) - Move a file.

lab@cli> file rename <source> <destination>
  • cat(1) - Concat files.

lab@cli> file show <path>
  • netstat(8) - Show network connections.

lab@cli> show system connections
  • history - Shell internal command to display recently used commands

lab@cli> show cli history
  • Setting $TERM, $COLUMNS, $LINES - termcap(5) and screen dimensions

Some shells use only $TERM to control the termcap(5). This allows better handling of the terminal when using the CLI from a serial console. Use show cli to review current settings.

  • apropos(1) - Search man page names and contents.

lab@cli> help apropos <something>
  • diff(1) - Compare files.

lab@cli> file compare <onefile> <nextfile>

Similar to diff -u

  • grep(1) - Match lines by regular expression.

Not case sensitive, and less features than grep (more like grep -i and grep -F)

lab@cli> show interfaces extensive | match alarm
  • less(1) - Pager with more features than more(1)

Some keystrokes, / G n N and so on, are the same. Not case sensitive. The first match will be alarm in the output, with the ability to scroll back or to the next entry.

lab@cli> show interfaces extensive | find alarm

 

Modification History:

2020-03-03: Article checked for accuracy; article found to be valid and relevant; no changes made

 

Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Getting Up and Running with Junos

Getting Up and Running with Junos Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search