Basic Linux Command Line Interface Guide

Similar documents
Basic Linux Command Line Interface Guide

Linux Command Line Primer. By: Scott Marshall

Unix Introduction to UNIX

Embedded Linux Systems. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Linux Systems Administration Getting Started with Linux

Connecting to ICS Server, Shell, Vim CS238P Operating Systems fall 18

Introduction to the UNIX command line

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Unix System Architecture, File System, and Shell Commands

CHE3935. Lecture 1. Introduction to Linux

Introduction: What is Unix?

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Introduction to Linux Workshop 1

Perl and R Scripting for Biologists

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Chapter-3. Introduction to Unix: Fundamental Commands

Computer Systems and Architecture

Working with Basic Linux. Daniel Balagué

Outline. Structure of a UNIX command

Linux Tutorial. Ken-ichi Nomura. 3 rd Magics Materials Software Workshop. Gaithersburg Marriott Washingtonian Center November 11-13, 2018

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Linux Essentials Objectives Topics:

Lab Working with Linux Command Line

Mills HPC Tutorial Series. Linux Basics I

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Linux Shell Script. J. K. Mandal

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Computer Systems and Architecture

*nix Crash Course. Presented by: Virginia Tech Linux / Unix Users Group VTLUUG

IBM AIX Basic Operations V5.

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

Linux Kung Fu. Ross Ventresca UBNetDef, Fall 2017

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Computer Architecture Lab 1 (Starting with Linux)

UNIX Quick Reference

Lab 3a Using the vi editor

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

Linux Kung Fu. Stephen James UBNetDef, Spring 2017

Short Read Sequencing Analysis Workshop

Linux crash lecture by Andrey Lukyanenko

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Linux environment. Graphical interface X-window + window manager. Text interface terminal + shell

Introduction to Linux

Linux at the Command Line Don Johnson of BU IS&T

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Lab 2: Linux/Unix shell

Introduction to Unix: Fundamental Commands

CS4350 Unix Programming. Outline

A Brief Introduction to the Linux Shell for Data Science

Chapter 4. Unix Tutorial. Unix Shell

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

PROGRAMMAZIONE I A.A. 2015/2016

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Introduction to Supercomputing

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

Introduction to UNIX/Linux

Introduction. File System. Note. Achtung!

Introduction to Linux Environment. Yun-Wen Chen

Introduction to Linux for BlueBEAR. January

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Chapter 1 - Introduction. September 8, 2016

The Unix Shell & Shell Scripts

Introduction to UNIX Command Line

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Introduction. What is Linux? What is the difference between a client and a server?

Unix Handouts. Shantanu N Kulkarni

Introduction to Linux

System Administration

CSN08101 Digital Forensics. Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak

Std: XI CHAPTER-3 LINUX

2. UDP Client, UDP Server

Introduction to UNIX command-line II

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

UNIX Quick Reference

Introduction to Linux

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Chap2: Operating-System Structures

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

CENG393 Computer Networks Labwork 1

M.C.A. (Sem.-lll) (CBCS) Examination November CCA-3003 Operating System and LinuxlUnix programming

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

commands exercises Linux System Administration and IP Services AfNOG 2015 Linux Commands # Notes

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

List of Linux Commands in an IPm

Introduction to Linux

Transcription:

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 Notice the different outputs between running ls and 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 ( /dev/sda# shows the mounted devices.) 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. 1 / 12

Change to the /home/remote directory. # cd /home/product Print the current working directory to verify that you are now in the /home/product directory. # pwd You should see the following output: /home/product 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. Change to the /mail/tmp directory. #cd /mail/tmp Create a file named myfile. # touch myfile 3. List the directory contents to verify that myfile has been created. # ls In the output, myfile should be listed. 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: Owner Read, Write, and Execute Group Read and Execute Other Read and Execute For example, to change the permissions of a file named myfile: vi Allow read, write, and execute permissions for the file. # chmod 777 myfile List the directory contents in long list format to view the file permissions. # ls -l You should see output that is similar to the following: -rwxrwxrwx 1 root root 0 2013-03-06 12:17 myfile 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 2 / 12

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: 3. Open the file in the vi editor. # vi myfile Press the I key to enter the insert mode. When you are in insert mode, --INSERT -- is displayed at the lower left hand corner of the shell. Type the following: #!/bin/bash echo "hello, $USER. I will list the files in the current directory" echo "The current directory is, $PWD" ls # list files 4. Press the Esc key to return to command mode. 5. 6. Save and exit the file. Enter: :wq To run this file, enter: #./myfile. To later remove a line from myfile without saving your changes: wc Open the file in the vi editor: # vi myfile Put the cursor in the line that you want to delete and then press d+d. 3. Exit the file without saving. Enter: :q! 4. Run the file. #./myfile. The output should not have changed. You can use the wc command with various options to view information about a file: Command wc c wc m wc w wc l Output Prints the number of bytes in the specified file. Prints the number of characters in the specified file. Prints the number of words in the specified file. Prints the number of lines in the specified file. 3 / 12

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. To exit out of the tail, press Ctrl+C. 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. Using cat to create a file: You can also use the cat command to create a file and write text to that file. For example, to create a file named usernamecatfile: Create the usernamecatfile file. # cat > usernamecatfile The > will redirect the output to a file. You can now write to the file. Type the following information: This is my example of an output redirect 3. Press the Enter key to create a new line, and then press Ctrl+D to quit the cat. 4. Cat the file you created to verify the file was written to. Using cat to output to a 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. less Redirect the output of usernamecatfile to usernamecatredir. # cat usernamecatfile > usernamecatredir Cat the new file and review the output. To view a file incrementally, use the less command. This command is especially useful on larger files and is 4 / 12

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. 3. View myfile. # less myfile Review the output. Notice how different it is from the output from using the cat command. 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. Run: # grep TIMING /mail/log/info 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: tail f /mail/log/info grep domain.com less /mail/log/info grep domain.com grep domain.com /mail/log/info I pipe To send the output of one command to the input of another, use the pipe ( ) operator. 3. 4. Use the less command to view the info file. # less /mail/log/info Press the Q key to exit. Press the up arrow key to display the previous command (# less /mail/log/info) and then add: /info grep TIMING Review the output. Notice the difference between the output for the less command and the grep command. mv To move a file to another directory, use the mv command. Move myfile from the /mail/tmp directory to the /home/remote directory. # mv /mail/tmp/myfile /home/remote/myfile. List the contents of the /mail/tmp directory to verify that myfile is no longer in it. # ls /mail/tmp 3. Change to the /home/remote directory and then list its contents. # cd /home/remote/ # ls 5 / 12

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. Create a copy of myfile that is named myfile # cp myfile myfile2 List the files in the directory to verify that myfile2 was created. For example, to create a copy of a file in another location: Create a copy of myfile2 in another directory. # cp /home/remote/myfile2 /tmp/myfile2 List the files in the /home/remote and /tmp/ directories. Both directories should list myfile 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. 3. 4. Type the following command without pressing Enter: # /tmp/myfile2 Use the left arrow key to go to the beginning of the line and add rm. # rm /tmp/myfile2 Press Enter. List the files in the tmp directory to verify that the file has been removed. ln To make links between files, use the ln command. Many files and file system locations are already symbolically linked on Barracuda products. 3. Symbolically link /home/remote/myfile to /mail/tmp/seemyfile. # ln s /home/remote/myfile /mail/tmp/seemyfile Run a long list for /mail/tmp to see the symbolic link between seemyfile and /home/remote/seemyfile. Cat both files to see how the content is similar. 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: # find /home iname *yfile* The output prints all files in the /home directory that have the simple pattern of yfile in their name. 6 / 12

which To display the full path of shell commands (executables or scripts), use the which command. # which qm.pl alias To create shortcuts by defining aliases, use the alias command. Create an alias named homepers for listing the contents of the /home directory in long list format. # alias homepers= ls l /home 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. # ps fax If you are looking for a specific process, you can pipe the ps command to a grep for a pattern. # ps fax grep mysql Compare the outputs from both ps commands. 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. # kill -9 7 / 12

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. Ping your company website. # ping You should receive responses. Press Ctrl+C to kill the ping to the website. 3. Ping www.aol.com. # ping www.aol.com This request should not return any responses. 4. Press Ctrl+C to kill the ping to AOL. 5. Review the output. ldapsearch To query an LDAP library, use the ldapsearch command. This command is only available on a Barracuda NG Control Center. Example 1 Search for a specific LDAP user, running the following command: # ldapsearch -h ldap.barracuda.com -p 389 -D 'username@cudanet.local' -b 'dc=cudanet,dc=local' -W "mail=bghodd*" When prompted, the administrator must provide the password. Example 2 Create an LDAP Data Interchange Format (LDIF) file, running the following command: # ldapsearch -h ldap.barracuda.com -p 389 -D 'username@cudanet.local ' -b dc=cudanet,dc=local' -W -LLL > /tmp/thisboxldif.ldif 8 / 12

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 # dig barracuda.com (general DNS query for the barracuda.com a record) # dig @4.2 barracuda.com (DNS query for the barracuda.com a record but at a specific server (4.2)) # dig mx barracuda.com (DNS query for a Mail exchange (MX) record) # dig x 64.235.145.81 (DNS query for a reverse lookup of an IP address) 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. For example, to query the MX record for barracuda.com in interactive mode: 3. 4. 5. Start the nslookup. # nslookup Specify that you are looking up the MX record. > set type=mx Specify the domain. > barracuda.com Review the output. To exit nslookup, enter: exit For example, to query bsf0yourwebsite.com in non-interactive mode: host Enter: # nslookup bsf0yourwebsite.com Review the output. 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. Look up 64.235.145.8 # host 64.235.145.81 This is the IP address of the network host. Review the output. 3. Look up bsh0yourwebsite.com. # host bsh0yourwebsite.com 9 / 12

4. Review the output. telnet To communicate with another host on a given port, use the telnet command. ifconfig To view or configure a kernel-resident network interface, use the ifconfig command. 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. From your shell, enter: # 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. For example, enter: # 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. From your shell, enter: hwtool -b fsck To check the filesystem for errors use the fsck command depending on what filesystem you are using (ext2 or ext3). If your appliance uses IDE harddisks replace sdax with hdax. /bin/umount /dev/sda1 /bin/umount /dev/sda2 /bin/umount /dev/sda3 /bin/umount /dev/sda4 /bin/umount /dev/sda5 /bin/umount /dev/sda6 ext2 file system: /sbin/fsck.ext2 -y /dev/sda1 /sbin/fsck.ext2 -y /dev/sda2 /sbin/fsck.ext2 -y /dev/sda3 /sbin/fsck.ext2 -y /dev/sda4 /sbin/fsck.ext2 -y /dev/sda5 /sbin/fsck.ext2 -y /dev/sda6 ext3 file system: 10 / 12

/sbin/fsck.ext3 -y /dev/sda1 /sbin/fsck.ext3 -y /dev/sda2 /sbin/fsck.ext3 -y /dev/sda3 /sbin/fsck.ext3 -y /dev/sda4 /sbin/fsck.ext3 -y /dev/sda5 /sbin/fsck.ext3 -y /dev/sda6 Keyboard Shortcuts To save time while you are typing at the command line, use the following keyboard shortcuts: Ctrl+A Ctrl+E Alt+B Alt+F Ctrl+W Ctrl+D Ctrl+K Ctrl+U Tab Keys Action Go to the beginning of the command line. Go to the end of the command line. Move the cursor backwards by one word. Move the cursor forward by one word. Remove the previous word, from the cursor to the previous word boundary. Delete the character under the line. Remove the remainder of the line, from the cursor to the end of the line. Clear the line from the cursor to the beginning of the line. Autocomplete a line of text. up/down arrows Move through previously used commands. 11 / 12

12 / 12