Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

BASIC LINUX COMMAND

ANGGRAHITO, S.ST., S.T., M.B.A


HISTORY of LINUX

Ken Thompson and Dennis Ritchie was developed the


Unix Operating Systemat AT&T Laboratories in 1969 and
first released in 1970.

In 1977 the University of California, Berkeley released a


free UNIX system that called BSD (Berkeley Software
Distribution).

Ken Thompson (left) and Dennis Ritchie (right),


creators of the Unix operating system

Copyright ©TAALENTA 2023


HISTORY of LINUX
in 1991, while studying computer science at University of Helsinki,
Linus Torvalds began a project that later became the Linux kernel. He
wrote the program specifically for the hardware he was using and
independent of an operating system because he wanted to use the
functions of his new PC with an 80386 processor. Development was
done on MINIX using the GNU C Compiler.

Trovalds made the code of Linux freely for everyone.


People can freely created modifications their own versions Linux

Linux is therefore an example of Open-source Software, the


copyright holder provides the rights to study, change, and
distribute the software to anyone and for any purpose.
Linus Torvalds
Source: https://en.wikipedia.org/wiki/History_of_Linux
Copyright ©TAALENTA 2023
LINUX File System

/bin/ Essential user command binary


/boot/ Static files of the boot loader
/dev/ Device files
/etc/ Host specific system configuration
/home/ User home Directories
/lib/ Shared Libraries
/ /media/ Removable Media
/mnt/ Mounted Filesystem
/opt/ Add-on ApplicationSoftware package
/sbin/ System Binaries
/srv/ Data for service from system
/tmp/ Temporary Files
/usr/ User Utilities and Applications
/proc/ Process Information
Copyright ©TAALENTA 2023
BASIC COMMANDS
Command for
• Working in Directories
• Working in Files
• Working in File Content
• Working in System Information
• Networking
• Package Manager
• Text Editors
• Problems

Copyright ©TAALENTA 2023


COMMAND FOR
WORKING IN DIRECTORIES

Copyright ©TAALENTA 2023


LS
• list directories or files.
• By default “ls” Commands will show the list of files in current directory excluding any hidden files.
ls

• List the files in current directory and showing the hidden files
ls -a

• List the files in current directory with their size


ls –l

Copyright ©TAALENTA 2023


CD
Change Directory to the home Directory
Cd ~

Change current working Directory


cd [directory_name]

Back to up directory
cd ..

Copyright ©TAALENTA 2023


TREE
Tree is used to recursively list or display the
content of a directory in a “tree-like” format.
Command:
tree -a
tree -f

Copyright ©TAALENTA 2023


MKDIR
Create new Directory
Commnad:
mkdir new-folder

Copyright ©TAALENTA 2023


PWD
Current Directory
Command:
pwd

Copyright ©TAALENTA 2023


RMDIR
Current Directory
Command:
rmdir < directory >

Copyright ©TAALENTA 2023


COMAND FOR
WORKING IN FILES

Copyright ©TAALENTA 2023


Copyright ©TAALENTA 2023
CREATE FILE
Create a text file:
• Touch file creates an empty file.
sudo touch file1.txt

• Append the txt into file using command


ifconfig > file1.txt

• Open and view the file


nano file1.txt
Copyright ©TAALENTA 2023
RM
Removes file or folder
Command:
• rm -i : will ask first, before deleting file.
• Consider using rm -I instead, which will only ask once and
only if you are trying to delete three or more files.
• rm -r : recursively delete a directory and all its contents. By
default, “rm” will not delete directories,
• rmdir : only delete empty directories.
• rm -f : delete files without asking

Copyright ©TAALENTA 2023


CP
Copy file and folder
Command:

cp /dir/file1 /dir/file2

Will be asking first before copy the


files
cp -i

Copyright ©TAALENTA 2023


MV
Move file or folders, and change
name of file or folder
Command:
mv file1 file2
mv folder 1 folder2

Copyright ©TAALENTA 2023


COMMAND FOR WOKRING
IN FILE CONTENT

Copyright ©TAALENTA 2023


HEAD
Print the first 10 lines of each
FILE to standard output
Command:
head < file name >

Copyright ©TAALENTA 2023


TAIL
Print the last 10 lines of each
FILE to standard output
Command:
tail < file name >

Copyright ©TAALENTA 2023


Copyright ©TAALENTA 2023
CAT
Concatenate FILE(s) to standard output. Cat used to view the content of
the file without open the file using editor
Command:
cat ping.txt

Copyright ©TAALENTA 2023


ECHO
Echo the STRING(s) to standard output.
Command:
echo < text >

Copyright ©TAALENTA 2023


MORE
More is similar with cat
Command:
more ping.txt

Copyright ©TAALENTA 2023


LESS
Less is a program similar to more(1), but it has many more
features. Less does not have to read the entire input file before
starting, so with large input files it starts up faster than text editors
like vi(1).

Copyright ©TAALENTA 2023


VIEW FILE
• cat file Show entire contents of file.
• more file Show one page at a time. Space bar for next page
and (q) to exit.
• head file Show the first 10 lines.
• head -15 file Show the first 15 lines.
• tail file Show the last 10 lines.
• tail -15 file Show the last 15 lines.
• tail -f file Useful when viewing the output of a log file.

Copyright ©TAALENTA 2023


COMMAND FOR
SYSTEM INFORMATION

Copyright ©TAALENTA 2023


UPTIME
uptime gives a one line display of the following information. The current time, how long the
system has been running, how many users are currently logged on, and the system load averages
for the past 1, 5, and 15 minutes.

Copyright ©TAALENTA 2023


FREE
free displays the total amount of free and used physical and swap memory in the system, as well as
the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo.

Copyright ©TAALENTA 2023


PS

ps displays information about a selection of the


active processes. If you want a repetitive
update of the selection and the displayed
information, use top instead.

Copyright ©TAALENTA 2023


DF
df displays the amount of disk space available on the file system containing each file name argument. If no file
name is given, the space available on all currently mounted file systems is shown. Disk space is shown in 1K
blocks by default.

Copyright ©TAALENTA 2023


FDISK
fdisk is a dialog-driven program for creation and
manipulation of partition tables

Copyright ©TAALENTA 2023


HOSTNAMECTL
hostnamectl may be used to query and change the system
hostname and related settings

Copyright ©TAALENTA 2023


NETWORKING

Copyright ©TAALENTA 2023


IFCONFIG

Copyright ©TAALENTA 2023


IP

Copyright ©TAALENTA 2023


PACKAGE MANAGER

Copyright ©TAALENTA 2023


SUDO
sudo allows a permitted user to execute a command as the superuser or another user, as specified by the
security policy. The invoking user's real (not effective) user-ID is used to determine the user name with which to
query the security policy.

Copyright ©TAALENTA 2023


APT
apt provides a high-level commandline interface for the package management system. It is intended as an end
user interface and enables some options better suited for interactive usage by default compared to more
specialized APT tools like apt-get(8) and apt-cache(8).

Command :
apt –get update
apt-get install
apt-get upgrade
apt-get remove
apt search

Copyright ©TAALENTA 2023


TEXT EDITORS

Copyright ©TAALENTA 2023


EDITORS
• nano – CLI
• vi, vim - CLI
• gedit – GUI

Copyright ©TAALENTA 2023


NANO COMMAND
Nano
• ctrl v Next page.
• ctrl y Previous page.
• ctrl w Where is (find).
• ctrl k Cut that line of test.
• ctrl x Exit editor.

Copyright ©TAALENTA 2023


VIM Command
Editing Commands (double)
d à delete the characters from the cursor position up the position given by the next command (for example d$ deletes all character from the current
cursor position up to the last column of the line).
C à change the character from the cursor position up to the position indicated by the next command.
Y à copy the characters from the current cursor position up to the position indicated by the next command.
p à paste previous deleted or yanked (copied) text after the current cursor position.
Note: Doubling d, c or y operates on the whole line, for example yy copies the whole line.

Cursor Movement Commands


Cursor keys - to move the cursor anywhere in file.
Ctrl + e - 1 line up
Ctrl + d - 1/2 page up
Ctrl + f - 1 page up
Ctrl + y - 1 line down
Ctrl + u - 1/2 page down
Ctrl + b - 1 page down

% - use with '{','}','(',')' to jump with the matching one.


0 - first column of the line
$ - jump to the last character of the line

Undo and Redo


u - you can undo almost anything using u in the command mode.
Ctrl+r - undo is undoable using Ctrl-r.

Copyright ©TAALENTA 2023


VIM Command

External commands
In Vim it’s easy to include the output of external commands or to filter the whole line or just a part
through an external filter.
To issue an external command type ':'
Searching and Replacing
:s/old/new/gc
:s/old/new/g

Save the file

:wq

Exit file without saving the changes


:q!

Copyright ©TAALENTA 2023


OTHER BASIC COMMAND

Copyright ©TAALENTA 2023


Searching File, Permissions
Searching File
• find [dir] [options]
• locate < filename>
• which < binary location >

Permissions
• chmod <options> <filename>
• chown <user:group> <filename>

Copyright ©TAALENTA 2023


Enable Service, File Utilities
Enable Service
• Web server / http : systemctl start apache2
• SSH : systemctl start ssh
• MySQL: systemctl start mysql
• PostgreSQL: systemctl start porstgresql

File Utilities (extract file)


• unzip filename.zip
• tar xzvf filename.tar.gz
• tar xjvf filename.tar.bz2
• tar czvf file/dir

Copyright ©TAALENTA 2023


PROBLEMS

• Install “htop” packet application

• Install Penetration test tool “The Harvester”


• Source Github: https://github.com/laramies/theHarvester
• Install Github

• Running “theHarverster” tool, send the output into file. Choose your Domain
target. “Example: manchester.ac.uk”
• Monitoring the process using tail -f

Copyright ©TAALENTA 2023


THANK YOU

Copyright ©TAALENTA 2023

You might also like