Teacher:
Mohamed A. Goumaa
[Link]. Of Computer Architecture and
Networking, University of Khartoum
Linux Basic Commands:
(A) Administration
cd change directory
[root@redhat ~]#cd ..
[root@redhat ~]#cd /root/Desktop
ls show files/folders in current directory
[root@redhat Desktop]#ls ٌستعرض المحتوى
[root@redhat Desktop]#ls -l إلستعراض المحتوى بالتفصٌل
[root@redhat Desktop]#ls -ld ٌستعرض تفاصٌل المجلد
cp copy file or directory
[root@redhat Desktop]#cp file1 /root/Desktop/
mv move and rename file or directory
[root@redhat Desktop]#mv file1 /root/Desktop/
rm remove file or directory
[root@redhat Desktop]#rm -ir file1
pwd show current path
[root@redhat Desktop]#pwd
mkdir create directory
[root@redhat Desktop]#mkdir lab4
[root@redhat Desktop]#mkdir -p lab4/lab5 إنشاء مجلدان معا
rmdir remove directory
[root@redhat Desktop]#rmdir lab4
touch create an empty file ًإنشاء ملف فاض
[root@redhat Desktop]#touch file1
cat display file contents, write to file إنشاء واضافة اسطر لملف
[root@redhat Desktop]#cat file1
[root@redhat Desktop]#cat >> file1 (CTRL+d) save
[root@redhat Desktop]#file1 >> file2
man display command manual لتوضٌح استخدام أمر معٌن
[root@redhat Desktop]#man cat
groupadd create new group إنشاء مجموعة
[root@redhat Desktop]#groupadd tech3
useradd create new user account إنشاء مستخدم
[root@redhat Desktop]#useradd -g tech3 mohamed
Linux Commands:
passwd change user password
[root@redhat Desktop]#passwd mohamed
userdel delete user account
[root@redhat Desktop]#userdel mohamed
usermod change user group
[root@redhat Desktop]#usermod -g tech4 mohamed
تغٌٌر مجموعة المستخدم الى مجموعة جدٌدة
groupmod change group name
[root@redhat Desktop]#groupmod -n tech3 tech4
groupmod change group ID
[root@redhat Desktop]#groupmod -g 123 tech4
gpasswd manage group options
[root@redhat Desktop]#gpasswd …..
[root@redhat Desktop]#gpasswd -a husain tech3
Options: -a add user to group
-d delete user from group
-A assign a user to be group admin
-M add members to groups
id/groups show user id & groups
[root@redhat Desktop]#id mohamed
[root@redhat Desktop]#groups mohamed
su switch user تغٌٌر المستخدم
[root@redhat Desktop]#su – mohamed
Users details:
[root@redhat Desktop]#vi /etc/passwd UID & GID ٌحتوي
[root@redhat Desktop]#vi /etc/shadow ٌحتوي األرقام السرٌة للمستخدمٌن
Group details:
[root@redhat Desktop]#vi /etc/group تفاصٌل المجموعة
[root@redhat Desktop]#vi /etc/gshadow الرقم السري ومدٌر المجموعة
reboot restart the system
[root@redhat Desktop]#reboot
Linux Commands:
chown change file owner المجلد/تغٌٌر مالك الملف
[root@redhat Desktop]#chown owner:group file/dir
chgrp change group for file تغٌٌر مجموعة الملف
[root@redhat Desktop]#chgrp group file
chmod change file permissions
Read r=4
[root@redhat Desktop]#chmod ug=rwx,o=rx file1 Write w=2
Execute x=1
[root@redhat Desktop]#chmod 761 file1
vi edit file
[root@redhat Desktop]#vi file1
There is two modes ( I + esc)
I = Insert mode
esc = Command mode
yy copy, p paste
(SHIFT+q)
q quite, wq quite with save, q! quite without save
Make shell script file
- Create file containing commands
[root@redhat Desktop]#cat > script
ls -l
touch file4
(CTRL+d) save
- Make file executable
[root@redhat Desktop]#chmod 777 script
- Run the file using full path
[root@redhat Desktop]#/root/Desktop/script
or [root@redhat Desktop]#./script
CUI: f1, f2, …, f6 (CTRL+ALT+f…)
GUI: f7 (CTRL+ALT+f7)
Linux Commands:
(B) Package Management
في الوندوز عملية تثبيت البرامج تتم تلقائيا أما في اللنكس البرنامج عبارة عن مجموعة من البرامج والملفات
حيث البد ان يتم تثبيت هذه الملفات بالترتيب حتى يكتمل تثبيت البرنامج،المعتمدة على بعضها
Programs in Linux are in rpm format [Redhat Package Management].
These files RPM`s are called dependencies or packages.
Yum is interface between user and RPM, if there is more than one package or
dependency, then yum resolves these dependencies (pk1, pk2, pk3, …).
Yum commands: (local or central or internet)
[root@redhat Desktop]#yum -y check-update لتحدٌث البرامج
[root@redhat Desktop]#yum install ntp لتحمٌل وتثبٌت
- الرابط موجود في ملف تهيئة،يتم تحميل وتثبيت البرامج اما من نفس الجهاز أو من جهاز في الشبكة
[root@redhat Desktop]#/etc/[Link].d/…
- Configuration file: baseurl=[Link]
RPM commands:
[root@redhat Desktop]#rpm -aq لمعرفة البرامج المثبتة فً الجهاز
[root@redhat Desktop]#rpm -aq | grep vsftpd
[root@redhat Desktop]#rpm -e [Link] إلزالة برنامج
[root@redhat Desktop]#rpm -ivh [Link] لتثبٌت برنامج
Linux Commands:
(C) Network Configuration
IP address could be assigned using configuration file (local) or DNS (central).
- Configuration files:
[root@redhat Desktop]#vi /etc/sysconfig/network-script/ifcfg-eth0
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=[Link]
NETMASK=[Link]
[root@redhat Desktop]#vi /etc/sysconfig/network
HOSTNAME=redhat
GATEWAY=[Link]
[root@redhat Desktop]#vi /etc/hosts
[Link] redhat
[Link] PC5
[Link] PC6
[root@redhat Desktop]#ping [Link]
[root@redhat Desktop]#service network start لتشغٌل الخدمة
[root@redhat Desktop]#service network stop إلٌقاف الخدمة
Linux Commands:
(d) Disk Management
Partition types:
1. Primary: contains operating system (booting)
2. Extended
File system types:
1. ext2
2. ext3
Mount point
In Windows, any partition has label, but in Linux you should make “Mounting” for each
created partition.
[root@redhat Desktop]#fdisk -L ٌستعرض حالة الدٌسك
[root@redhat Desktop]#df -h ٌستعرض المساحة الفاضٌة
Hardisks /dev/hda هاردٌسك من النوع القدٌم
/dev/sda هاردٌسك من نوع ساتا
/dev/fda ًهاردٌسك من نوع فلوب
Swap in Linux is like “Paging File” in Windows
Swap بمعنى أي برنامج ماشغال لفترة زمنٌة ٌخرج من الرام وٌحفظ فً الـ
Swap= 1.5 of RAM size
* To create partition: “steps”
(1) [root@redhat Desktop]#fdisk /dev/sda مثال بارتشن جدٌد،لعرض خٌارات هذا الهاردٌسك
(2) [root@redhat Desktop]#partprobe لتحدٌث التعدٌالت االخٌرة
(3) [root@redhat Desktop]#mkfs.ext3 /dev/sda2 لعمل فورمات للبارتشن
(4) [root@redhat Desktop]#mkswap /dev/sda3 لجعل البارتشن ٌكون سواب
(5) [root@redhat Desktop]#mkdir /root/Desktop/part2 النشاء مجلد جدٌد
(6) [root@redhat Desktop]#mount /dev/sda2 /root/Desktop/part2 لربط المجلد الجدٌد
بالبارتشن الجدٌد
(7) [root@redhat Desktop]#umount /dev/sda2 /root/Desktop/part2 لفك ارتباط المجلد
الجدٌد بالبارتشن الجدٌد
Introduction to Linux
Listing the Content of a
Directory
ls is used to list the contents of a directory.
If the command ls is written with
parameter –l then the command lists
contents of the working directory with
details. Example:
#ls –l
Introduction to Linux
Moving in Directories
• cd try_it :Changes the directory to try_it
• pwd :Prints present working
directory (e.g. /home/smith/try_it)
• cd.. :Move to superior directory
• pwd :Prints /home/smith
• cd /home :The absolute path
• pwd : Prints /home
• cd :The system is returned to the
user home directory
• pwd : Print /home/smith
Introduction to Linux
Make Directory
The command mkdir my_dir
makes new directory my_dir (the path is
given relative) as a subdirectory of the
current directory.
Introduction to Linux
Remove Directory
The command rmdir your_dir
removes directory your_dir if it is empty.
Introduction to Linux
Copy File
The command cp file_1 file_2
copies file_1 to file_2. The both files must
be in the same working directory. If they
are in various directories, the path must be
given.
Introduction to Linux
Rename and/or Move the
File
The command mv file_1 file_2
moves file_1 to file_2
The both files must be in the same
working directory.
If they are in different directories, the path
must be given.
The file_1 is removed from the disk.
Introduction to Linux
Remove File
The command rm file_a
removes the file_a from the system
If you use wildcard. For example
rm h*c
you will remove all files beginning with h
and ending with c which are in working
directory.
If you write
rm *
you will erase all files from your working
directory.
Introduction to Linux
Access Permission of File/Directory
The ownership of the file or directory can
be changed using the command
chown <owner> <file/directory name>
The group of the file or directory can be
changed using the command
chgrp <group> <file/directory name>
The permissions of the file can be changed
using chmod command
chmod -R ### <filename or directory>
-R is optional and when used with
directories will traverse all the sub-
directories of the target directory changing
ALL the permissions to ###.