Linux Command Line
Linux Command Line
This basic Linux Command-Line Interface (CLI) Guide provides a general explanation of commonly
used Bash shell commands for the Barracuda NG Firewall. You can access the command-line interface
by connecting to the hostname with a terminal utility (such as PuTTY). It is strongly recommended
that the administrator reads the manual (man) page for bash (# man bash) after connecting to the
system, and any man pages for commands listed in this article where a further explanation is needed.
It is also important to remember that more options are available for commands than what are
outlined in the following list.
In this article:
pwd
To verify the directory path that you are currently working in, use the pwd command. It stands for
"Print name of current Working Directory." From your shell, enter:
# pwd
ls
To display the contents of the current or specified directory, use the ls command. It stands for "list
directory contents" and can be thought of as "List to Screen." To display the contents of the current
directory, enter:
# ls
To print the contents of the directory in long list format, add the -l option:
# ls -l
mount
To attach a file system to a device or several devices, use the mount command. You can also run the
command by itself to view the mounted partitions:
# mount
df
To view the total and available disk space for the file system, use the df command. It stands for “report file
system disk space usage” but is commonly referred to as “disk free.” To print the output in a “human
readable” format, add the –h option:
# df -h
cd
To “change directories” or switch from one directory to another, use the cd command.
For example:
touch
The touch command is “officially” used to change a file’s time stamp, but you can use it to create
files.
For example, you can create a file named myfile in the /mail/tmp directory.
The /mail/tmp directory is the largest partition and can be used to write files to.
chmod
To change a file’s permissions, use the chmod command. When changing the file permissions
with chmod, the permissions are binary counted. Before using the chmod command, identify what
permissions should be given to which group. For example, you may choose to grant the following
permissions:
vi
To create or edit plain text documents or programs, use the vi or vim (Vi Improved) command. The vi
editor has two modes:
Insert mode — Lets you use input text into the document or program.
Command mode — Lets you use commands. It is recommended that you read the man page
for a comprehensive list of all commands.
You can also learn more about using vi by reading the Vimtutor and following the steps outlined in the
files. To access the Vimtutor, run:
# vimtutor
The following table lists common commands that you can use with vi:
Command Action
:wq Exit the vi editor and save changes.
:q! Exit the vi editor without saving changes.
i Insert before cursor.
Esc Enter command mode.
x Delete character under cursor.
d+d Delete a line in the file.
? Find a word going backwards.
/ Find a word going forwards.
For example, to edit a file named myfile and save your changes:
wc
You can use the wc command with various options to view information about a file:
Command Output
wc –c Prints the number of bytes in the specified file.
wc –m Prints the number of characters in the specified file.
wc –w Prints the number of words in the specified file.
wc –l Prints the number of lines in the specified file.
head
Use the head command to print the first 10 lines of a file. For example, to print the first ten lines of a
file named myfile:
# head myfile
To print lines based on other criteria, you can add options to the head command.
tail
Use the tail command to print the last 10 lines of a file. Usually, the command is used with the –f
option to view a log file as it is being written. For example, enter:
# tail –f /mail/log/debug
To separate the last 10 lines that have been written from the appended output, press the Enter key.
cat
To “concatenate” a file and print the standard output, use the cat command. It is one of
many commands that you can use to view the contents of a file. For example, to view myfile:
# cat myfile
It is not recommended that you use the cat command to view large files.
You can also use the cat command to create a file and write text to that file.
You can also use the cat command to redirect the output to a new file. This is essentially a method of
copying a file.
For example:
less
To view a file incrementally, use the less command. This command is especially useful on larger files
and is more useful than the more command because it allows for forward and backward
movement. When viewing the file, using /pattern will search forward within the file for the specified
regex pattern. When viewing the file, using ?pattern will search backwards within the file for the
specified regex pattern.
For example:
1. View myfile.
# less myfile
2. Review the output. Notice how different it is from the output from using the cat command.
3. To exit, press the Q key.
grep
To search a file for a given pattern, use the grep command. If a line has the requested pattern, the
entire line is printed.
For example:
1. Run:
# grep TIMING /mail/log/info
2. Review the output.
The grep command is an excellent tool with tailing for a specific pattern, sending an output to the
grep with a pipe, or just greping a file for the pattern. Examples of this include:
I pipe
To send the output of one command to the input of another, use the pipe ( | ) operator.
For example:
mv
For example:
cp
To make a copy of a file or create a copy of a file in another location, use the cp command. It is
recommended that you create a copy of any file before modifying it in any way.
For example:
rm
To “remove” a file or directory, use the rm command. It is good practice to add the file or directory to
be deleted before putting the rm command into the string.
For example:
ln
To “make links between files,” use the ln command. Many files and file system locations are already
symbolically linked on Barracuda Networks products.
For example:
find
To search for files in a directory hierarchy, use the find command. This command is especially useful
when you do not know the name or location of a file.
For example, to search for files in the /home directory that have yfile in their name:
The output prints all files in the /home directory that have the simple pattern of yfile in their name.
which
To display the full path of shell commands (executables or scripts), use the which command.
For example:
# which qm.pl
alias
For example:
1. Create an alias named homepers for listing the contents of the /home directory in long list
format.
# alias homepers=”ls –l /home”
2. Enter the alias to verify that it works.
# homepers
The contents of the /home directory should be listed in long list format.
The alias is removed when you log out of the shell. To permanently keep the alias, add it to the
~remote/.bashrc file.
uptime
To view how long the system has been running, use the uptime command.
ps
To report a snapshot of the current running processes, use the ps command. It is useful for getting
the process ID to send kill signals. If you are looking for a specific process, add a pipe and the
requested process.
For example:
# ps fax
If you are looking for a specific process, you can pipe the ps command to a grep for a pattern.
For example:
top
To display the top processes and memory used, use the top command. To sort by memory (%MEM),
press Shift+M.
kill
To send a kill signal to a process ID, use the kill command. The -9 is a common option and is used to
“kill all”. For example:
# kill -9
strace
To trace system calls and signals, use the strace command. This command essentially intercepts and
records the system calls of a process and the signals received by a process. Before using the strace
command, use the top command to get the required process ID. After getting the process ID, use the
following syntax to trace the process:
# strace –p
Reading a strace can be difficult due to the “noise” that is reported. When a program is run,
there are many standard system files that all write to the strace. The strace command is
especially useful for identifying what a process is doing when a process is “hogging” up CPU
resources.
ping
To send an ICMP ECHO_REQUEST to a host and listen for a response, use the ping command. This is
a good tool for verifying that the host is responding to requests. However, make sure that ICMP has
not been disabled on a network or the host; otherwise, no response is provided and the request will
time out.
For example:
ldapsearch
Example 1
Example 2
Create an LDAP Data Interchange Format (LDIF) file, running the following command:
When prompted, the administrator must provide the password. The LDIF file is written to the tmp
directory and can be copied and sent to a customer.
dig
To query a DNS server for a record, use the dig command. It is a DNS lookup utility. However, the dig
command relies on DNS and will not reference the /etc/hosts file to resolve a name to an IP address.
Example:
nslookup
To query Internet domain name servers, use the nslookup command. It has two modes
Interactive mode — Allows the user to query a name server for information about various hosts
and domains.
Non-interactive mode — Prints just the name and request information for a host or domain.
1. Enter:
# nslookup bsf01.yourwebsite.com
2. Review the output.
host
To perform DNS lookups, use the host command. It is normally used to convert names to
IP addresses, and/or IP addresses to names. This command will look in the /etc/host file.
For example:
1. Look up 64.235.145.81.
# host 64.235.145.81
This is the IP address of the network host.
2. Review the output.
3. Look up bsh01.yourwebsite.com.
# host bsh01.yourwebsite.com
4. Review the output.
telnet
To communicate with another host on a given port, use the telnet command.
ifconfig
traceroute
To print the route that the packets take to get to a network host, use the traceroute command.
It should be noted that traceroute may be unreliable because it is a connectionless (UDP in Unix
and ICMP in Windows) connection.
# traceroute
GET
To send requests to www and local file system servers, use the GET command. This tool may be
helpful if a customer states that they are not filtering outbound requests “at all”. The response will
indicate whether or not web traffic is being filtered/blocked; it may be best practice to try the
GET command with a website that would normally be blocked on a corporate or government network.
# GET www.disney.com
hwtool
To read out the currently installed BIOS version number for a running Barracuda NG Firewall without a
reboot, use the hwtool command.
hwtool -b
fsck
To check the filesystem for errors use the fsck command depending on what filesystem you are using
(ext2 or ext3).
/sbin/fsck.ext2 -y /dev/sda6
Keyboard Shortcuts
To save time while you are typing at the command line, use the following keyboard shortcuts:
Keys Action
Ctrl+A Go to the beginning of the command line.
Ctrl+E Go to the end of the command line.
Alt+B Move the cursor backwards by one word.
Alt+F Move the cursor forward by one word.
Ctrl+W Remove the previous word, from the cursor to the previous word boundary.
Ctrl+D Delete the character under the line.
Ctrl+K Remove the remainder of the line, from the cursor to the end of the line.
Ctrl+U Clear the line from the cursor to the beginning of the line.
Tab Autocomplete a line of text.
up/down arrows Move through previously used commands.
© Barracuda Networks Inc., 2023 The information contained within this document is confidential and proprietary to Barracuda Networks Inc. No
portion of this document may be copied, distributed, publicized or used for other than internal documentary purposes without the written consent of
an official representative of Barracuda Networks Inc. All specifications are subject to change without notice. Barracuda Networks Inc. assumes no
responsibility for any inaccuracies in this document. Barracuda Networks Inc. reserves the right to change, modify, transfer, or otherwise revise this
publication without notice.