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

108-Linux Shell Scripting

This document is a comprehensive guide to various Bash commands used in Linux, detailing their functions and examples. It covers file and directory management, user management, permission settings, process handling, and network configuration, among other topics. Additionally, it includes specific commands for editing files with VI, managing disk partitions, and using tools like tar for archiving.

Uploaded by

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

108-Linux Shell Scripting

This document is a comprehensive guide to various Bash commands used in Linux, detailing their functions and examples. It covers file and directory management, user management, permission settings, process handling, and network configuration, among other topics. Additionally, it includes specific commands for editing files with VI, managing disk partitions, and using tools like tar for archiving.

Uploaded by

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

Bash command line for Linux

Collected by : farid ahmadian & kianoosh rezaee

ls list
ls -al list of hidden & all detail
cd .. Go one level up
cd ../.. Go two level up
cd directoryname(path) Go to specified directory(path)
cal for calender by day
cal -y for calender completely
who Print all usernames currently logged in
whoami who is current user
ls -al | less use | for get output from prior command and give it to
input of next comman (paging)
mkdir directoryname make directory
example : mkdir kianoosh make kianoosh folder
mkdir kianoosh rezaee make two folder kianoosh & rezaee
mkdir kianoosh\ rezaee make one folder kianoosh rezaee
clear clear the screen shortcut ctrl+l
touch filename create file with specified name
example : touch zanjan create file with zanjan name
touch kia{1,2,3} create three file kia1 kia2 kia3
touch kia{1..3} create three file kia1 kia2 kia3
echo “hello” print the hello in the output
echo “hello” > zanjan write hello in zanjan file (overwrite)
echo “hello” >> zanjan append hello to zanjan
cat zanjan to read file content
ls -al | grep zanjan to find zanjan in list of current path
grep -rin “test” . To find a string (test) in the file in current path
-r recursive
in insensetive
. current path
man commandname manual of command
example : man grep to see how to use grep or manual of grep
history to see history of command used in this computer up to now
example : history | grep ls |wc -l count of the ls command in history
wc word count
-l line
cp test1 test2 (test1,2 is file) copy the content of test1 to test2
cp -r folder1 folder2 copy folder1 to folder2
remaining -r recursive
example : cp folder1/folder2 . Copy folder2 to current path
mv test2 test5 rename the test2 to test5
mv test3 folder move or cut the test3 to folder or directory
rm test1 remove the test1
notice : evry thing in linux is file.
Cat /proc/cpuinfo see cpu information and performance
cat /proc/meminfo see memory information and performance
head -n3 /prco/meminfo to see 3 first line of memory information and performance
tail -n5 /proc/meminfo to see 3 last line of memory information and performance
find /home -iname “*.pdf” search in /home to finde all file with .pdf extention
remaining -i insensetive

Question: 1-creat 2 folder tehran and zanjan


2-in zanjan folder creat test 1 to 9
3-in tehran folder creat new folder and named it milad
4-copy the test5 to milad folder
5-cut the test9 to milad folder
6-make new folder and name it iran and move all file that start with test to iran
soloution : mkdir iran
find . -iname “test*” -exec mv {} iran \;
syntax : find <path> <option> “object to find” <action>
ps -A list all process
example : ps -A | grep gedit show gedit PID
kill KILL PID to kill the specified process by ID
unam -a show the version of linux
notice : to install font make new folder in home directory and named it .font then copy
the font to that folder.
Ls;ls use ; to manage the command.at first ,first command is get start and after that
second one.
Wget <download link> use this command to download the downloadable link
notice : to install the program in debian side linux use this command :
apt -get install aria2
to uninstall the program :
apt -get remove aria2
to see address of source :
cat /etc/apt/source.list
to update all installed program :
apt -get update
to update (upgrade) version of linux
apt -get upgrade
notice : to install the program from file :
dpkg -i /home/kia/downloads/
adduser kianoosh create new user
useradd kianoosh create new user
passwd newpassword to change password
deluser kianoosh remove user
userdel kianoosh remove user
userdel -r kianoosh remove user and all user file and folder
d rwx
- --- --- ---
owner group other
r : read (4) w : write (2) x : execute (1) d : directory

chmod 777 test to change access permissions


remaining : 777 means all user can do every thing
755
724
The octal (0-7) value is calculated by adding up the values for each digit
User (rwx) = 4+2+1 = 7
Group(rx) = 4+1 = 5
World (rx) = 4+1 = 5
chmode mode = 0755
Examples

chmod 400 file - Read by owner


chmod 040 file - Read by group
chmod 004 file - Read by world

chmod 200 file - Write by owner


chmod 020 file - Write by group
chmod 002 file - Write by world

chmod 100 file - execute by owner


chmod 010 file - execute by group
chmod 001 file - execute by world
To combine these, just add the numbers together :
chmod 444 file - Allow read permission to owner and group and world
chmod 777 file - Allow everyone to read, write, and execute file

Permissions: 751 -rwxr-x--x

owner group other


read * *
write *
execute * * *

Chown Change owner, change the user and/or group ownership of


each given File to a new Owner.
Chown can also change the ownership of a file to match
the user/group of an existing reference file.
Chown username filename
chgrp Change group ownership
chgrp username filename

cat /proc/partition to see all hards and partitions


df -H Disk Free - display free disk space
With no arguments, `df' reports the space used and
available on all currently mounted filesystems (of all
types).
Mount mount a file system and partitions.
Example :
mkdir mnt
mount /dev/sda6 mnt/
umount mnt/ to unmount the partitions

VI Editor Commands
Vi has two modes insert mode and command mode.
The editor begins in command mode, where cursor movement and copy/paste editing occur.
Most commands execute as soon as typed except for "colon" commands which execute when
you press the return key.
Switch to Insert mode:

O Open line above cursor

I Insert text at beginning of line

i Insert text at cursor

a Insert text after cursor

A Append text at line end

o Open line below cursor


Switch to Command mode:
Switch to command mode <ESC>

Cursor Movement (command mode):

Scroll Backward 1 screen <ctrl>b


Scroll Up 1/2 screen <ctrl>u
Go to beginning of line 0
Go to line n nG
Go to end of line $
Scroll Down 1/2 screen <ctrl>d
Go to line number ## :##
Scroll Forward 1 screen <ctrl>f
Go to last line G
Scroll by sentence f/b ( )
Scroll by word f/b w b
Move left, down, up, right h j k l
Left 6 chars 6h
Scroll by paragraph f/b { }
Directional Movement Arrow Keys
Go to line #6 6G

Delete text (command mode):

Change word cw
Replace one character r
Delete word dw
Delete text at cursor x
Delete entire line (to buffer) dd
Delete (backspace) text at cursor X
Delete 5 lines (to buffer) 5dd
Delete current to end of line D
Delete lines 5-10 :5,10d

Editing (command mode):

Copy n
Copy line yy nyy Copy lines 1-2/paste after 3 :1,2t 3
lines
Paste above current line P
Paste below current line p Move lines 4-5/paste after 6 :4,5m 6
Join previous line J
Search
Search backward for string ?string forward for /string Find next string occurrence n
string
% (entire file) s (search and
replace) /old text with new/ c :%s/oldstring/newstring/cg Ignore case during search :set ic
(confirm) g (global - all)
Undo
Repeat last command . previous u Undo all changes to line U
command

Save and Quit (command mode):

Save changes to buffer :w


Save changes and quit vi :wq
Save file to new file :w file
Quit without saving :q!
Save lines to new file :10,15w file
ifconfig Configure a network interface.Interface configurator -
display your ip address, network interfaces, transferred and
received data information, configure a network interface.
Example :
ifconfig eth0 192.168.1.82 assign ip to eth0 interface
ifconfig etht0 192.168.1.82/16 assign ip and subnet mask to eth0 interface
route -n display the defult gateway
route add defult gw 192.168.1.1 eth0 change the defult gateway manually
dig www.zanjanhost.com DNS lookup (domain information groper)
fdisk Partition table manipulator for Linux
Hard disks can be divided into one or more logical disks
called partitions. This division is described in the partition
table found in sector 0 of the disk.
Example :
fdisk /dev/sda1
mkfs.ntfs /dev/sda1 to format ntfs partitions
tar Tape ARchiver, store, list or extract files in an archive
Example :
tar -cf testarchive.tar /home/kia/rezaee to archive the rezaee folder
tar -xf testarchive.tar /home/kia/rezaee to extract
tar -cjf testarchive.tar /home/kia/rezaee to compress and archive the rezaee folder
tar -xjf testarchive.tar /home/kia/rezaee to extract

You might also like