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.
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.
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.
ls(1)
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.
-l
ls
tail(1) - Output the last part of files.
tail(1)
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 .
The -n switch is handled by specifying a number. Otherwise, the default is about 10 lines (like tail ).
-n
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 .
-f
monitor start <file>
tail -f <file> &
monitor stop
w(1) - See who is logged in and what they are doing.
w(1)
lab@cli> show system users
ps(1) - Show current processes.
ps(1)
lab@cli> show system processes
kill(1) - Send a signal to a process.
kill(1)
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.
kill
init
uptime(1) - Tell how long the system has been running.
uptime(1)
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
df(1)
lab@cli> show system storage
ifconfig(1) - Interface settings
ifconfig(1)
lab@cli> show interfaces
Changing the way the interface is configured is primarily in [edit interfaces] of the configuration hierarchy.
[edit interfaces]
route(8) - Show and manipulate the routing table.
route(8)
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.
cp(1)
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.
rm(1)
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.
lab@cli> file delete october*.conf
.conf
shred(1) - Overwrite file contents.
shred(1)
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.
mv(1)
lab@cli> file rename <source> <destination>
cat(1) - Concat files.
cat(1)
lab@cli> file show <path>
netstat(8) - Show network connections.
netstat(8)
lab@cli> show system connections
history - Shell internal command to display recently used commands
history
lab@cli> show cli history
Setting $TERM , $COLUMNS , $LINES - termcap(5) and screen dimensions
$TERM
$COLUMNS
$LINES
termcap(5)
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.
show cli
apropos(1) - Search man page names and contents.
apropos(1)
lab@cli> help apropos <something>
diff(1) - Compare files.
diff(1)
lab@cli> file compare <onefile> <nextfile>
Similar to diff -u
diff -u
grep(1) - Match lines by regular expression.
grep(1)
Not case sensitive, and less features than grep (more like grep -i and grep -F )
grep -i
grep -F
lab@cli> show interfaces extensive | match alarm
less(1) - Pager with more features than more(1)
less(1)
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
2020-03-03: Article checked for accuracy; article found to be valid and relevant; no changes made