Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Basic Linux Commands

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Basic Linux Commands

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

BASIC LINUX

COMMANDS
Understanding the Basics of the Linux administration 1

Teaching Assist Shams Urahman Rashidy


Lecturer, Kandahar University | Cybersecurity Specialist

Shamsrashidy@kdru.edu.af
LINUX DIRECTORY
STRUCTURE
 Now that you are able to connect to the server and have been introduced
to the interface you will be using, it's time to learn about the directory
layout. Understanding the directory structure will help you in the future
when you are searching for components on the system. It can help you
answer questions like:
 Where are programs located?
 Where do configuration files live?
 Where might I find the log files for this application?

Shamsrashidy@kdru.edu.af 2
COMMON DIRECTORIES
 Here are the most common top level directories that you need to be aware
of and may interact with as a normal user.

Shamsrashidy@kdru.edu.af 3
COMMON DIRECTORIES
 Here are the most common top level directories that you need to be aware
of and may interact with as a normal user.

Shamsrashidy@kdru.edu.af 4
SHELL
 When you log into a server over the network the shell program is started
and acts as your default interface to the system. The shell is nothing more
than a program that accepts your commands and executes those
commands. Said another way, the shell is a command line interpreter.
 Let's look at the shell prompt you'll be working with. The prompt just sits
and stares at you waiting for you do something interesting like give it a
command to execute. Here is Bob's shell prompt.
 bob@linuxsvr $

 Bob's prompt is in a common format of username@servername $ . In this


example, the prompt is displaying the username, the server name, and if
that user is using the system as a normal user ( $ ) or a superuser ( # ).

Shamsrashidy@kdru.edu.af 5
SHELL
 When you log into a server over the network the shell program is started
and acts as your default interface to the system. The shell is nothing more
than a program that accepts your commands and executes those
commands. Said another way, the shell is a command line interpreter.
 Let's look at the shell prompt you'll be working with. The prompt just sits
and stares at you waiting for you do something interesting like give it a
command to execute. Here is Bob's shell prompt.
 bob@linuxsvr $

 Bob's prompt is in a common format of username@servername $ . In this


example, the prompt is displaying the username, the server name, and if
that user is using the system as a normal user ( $ ) or a superuser ( # ).

Shamsrashidy@kdru.edu.af 6
BASIC LINUX
COMMANDS
7

Shamsrashidy@kdru.edu.af
WORKING DIRECTORY AND
NAVIGATION
 Here is a short list of basic, but essential commands. In Linux, commands
are case-sensitive and more often than not they are entirely in lowercase.
Items that are surrounded by brackets ( [] ) are optional.
 You will more than likely use at least some of these commands every time
you log into a Linux system. Become familiar with these commands
because they can get you pretty far in a short amount of time.

Shamsrashidy@kdru.edu.af 8
LS
 ls - Lists directory contents. You will use ls to display information about files
and directories.

Shamsrashidy@kdru.edu.af 9
CD [DIR]
 cd [dir] - Changes the current directory to dir . If you execute cd without
specifying a directory, cd changes the current directory to your home
directory. This is how you navigate around the system.

Shamsrashidy@kdru.edu.af 10
PWD
 pwd - Displays the present working directory name. If you don't know what
directory you are in, pwd will tell you.

Shamsrashidy@kdru.edu.af 11
CAT
 cat [file] - Concatenates and displays files. This is the command you run to
view the contents of a file.

Shamsrashidy@kdru.edu.af 12
ECHO
 echo [argument] - Displays arguments to the screen.

Shamsrashidy@kdru.edu.af 13
MAN COMMAND
 man command - Displays the online manual for command . Type q to quit
viewing the manual page. The documentation provided by the man
command is commonly called "man pages."

Shamsrashidy@kdru.edu.af 14
EXIT , LOGOUT , OR CTRL-D
 exit , logout , or Ctrl-d - Exits the shell or your current session.
 clear - Clears the screen.

Shamsrashidy@kdru.edu.af 15
EXAMPLE

Shamsrashidy@kdru.edu.af 16
WORKING WITH
DIRECTORIES
 Directories are simply containers for files and other directories. They
provide a tree like structure for organizing the system. Directories can be
accessed by their name and they can also be accessed using a couple of
shortcuts. Linux uses the symbols . and .. to represent directories.
 Think of . as "this directory" and .. and "the parent directory."

Shamsrashidy@kdru.edu.af 17
WORKING WITH
DIRECTORIES
 Directories are simply containers for files and other directories. They
provide a tree like structure for organizing the system. Directories can be
accessed by their name and they can also be accessed using a couple of
shortcuts. Linux uses the symbols . and .. to represent directories.
 Think of . as "this directory" and .. and "the parent directory."

Shamsrashidy@kdru.edu.af 18
WORKING WITH
DIRECTORIES
 Using the shortcuts can make navigating easier. For example, type cd.. to
go to the directory just above your current directory.

Shamsrashidy@kdru.edu.af 19
WORKING WITH
DIRECTORIES
 The cd . command did not take you anywhere. Remember that . is "this
directory" and .. Is "the parent directory." Another shortcut for navigating
directories is cd - . This command takes you to the previous directory. The
environment variable that represents your previous working directory is
OLDPWD . So, cd - and cd $OLDPWD are equivalent.

Shamsrashidy@kdru.edu.af 20
CREATING AND REMOVING
DIRECTORIES
 Command: touch filename
 - Create a new file (e.g., touch text.txt).
 - Create multiple files: touch ab ac ad ae.
 - Use brace expansion: touch node{1..10}.

Shamsrashidy@kdru.edu.af 21
CREATING AND REMOVING
DIRECTORIES
 The mkdir command is used to create directories and the rmdir command
removes them.
 mkdir [-p] directory - Create a directory. Use the -p (parents) option to
create intermediate directories.
 rmdir [-p] directory - Remove a directory. Use the -p (parents) option to
remove all the specified directories. rmdir only removes empty directories.
To remove directories and their contents, use rm .
 rm -rf directory - Recursively removes the directory and all files and
directories in that directory structure. Use with caution. There is no "trash"
container to quickly restore your file from when using the command line.
When you delete something, it is gone.

Shamsrashidy@kdru.edu.af 22
CREATING AND REMOVING
DIRECTORIES
 The mkdir command is used to create directories and the rmdir command
removes them.
 mkdir [-p] directory - Create a directory. Use the -p (parents) option to
create intermediate directories.
 rmdir [-p] directory - Remove a directory. Use the -p (parents) option to
remove all the specified directories. rmdir only removes empty directories.
To remove directories and their contents, use rm .
 rm -rf directory - Recursively removes the directory and all files and
directories in that directory structure. Use with caution. There is no "trash"
container to quickly restore your file from when using the command line.
When you delete something, it is gone.

Shamsrashidy@kdru.edu.af 23
CREATING AND REMOVING
DIRECTORIES

Shamsrashidy@kdru.edu.af 24
LISTING FILES AND
UNDERSTANDING LS
OUTPUT
 Here is the output from an ls command using the -l option. The -l flag tells
ls to display output in a long format. If you need to see what files or
directories exist, use ls . However, if you need detailed information use ls -l.
 $ ls -l

 -rw-rw-r-- 1 bob users 10400 Sep 27 08:52 sales.data

Shamsrashidy@kdru.edu.af 25
LISTING ALL FILES,
INCLUDING HIDDEN FILES
 Files or directories that begin with a period ( . ) are considered hidden and
are not displayed by default. To show these hidden files and directories, use
the -a option.

Shamsrashidy@kdru.edu.af 26
LISTING FILES BY TYPE
 When you use the -F option for ls a character is appended to the file name
that reveals what type it is.

Shamsrashidy@kdru.edu.af 27
LISTING FILES BY TIME AND
IN REVERSE ORDER
 If you would like to sort the ls listing by time, use the -t option.

Shamsrashidy@kdru.edu.af 28
LISTING FILES RECURSIVELY
 Using the -R option with ls causes files and directories to be displayed
recursively.

Shamsrashidy@kdru.edu.af 29

 You can also use the tree command for more visually appealing output. If
you only want to see the directory structure, use tree -d .
 tree - List contents of directories in a tree-like format.
 tree -d - List directories only.
 tree -C - Colorize output.

Shamsrashidy@kdru.edu.af 30
LIST DIRECTORIES, NOT
CONTENTS
 Normally when you run ls against a directory the contents of that directory
are displayed. If you want to ensure you only get the directory name, use
the -d option.

Shamsrashidy@kdru.edu.af 31
COMMONLY USED LS
OPTIONS
 Here is a recap of the ls options you have learned.

Shamsrashidy@kdru.edu.af 32
COMMONLY USED LS
OPTIONS
 Here is a recap of the ls options you have learned.

Shamsrashidy@kdru.edu.af 33
Q&A

Any questions?

Shamsrashidy@kdru.edu.af 34

You might also like