CLI Commands

Jump to navigationJump to search
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

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