Linux Commands
Linux Commands
wd
head -n 5 /etc/pass To show first 5 lines
-5
wd
tail /etc/pass To show lastest 10 lines
wd
tail -f /etc/pass To show every in same terminal after changing in
otherone
wd
tail -n 5 /etc/pass To show lastest 5 lines
-5
wd
Which passwd To know where it’s locate (result /etc/passwd)
whereis To know where it’s locate (result /etc/passwd)
passwd
su root To swish users
cd .. To go to previous directory
touch “File 1”
mkdir /home/a Creating a directory and it start to create from right of
pass (dir first -→ Desktop)
hmed
/Desktop
/dir
mkdir -p /Desktop (Positive) Creating a directory and it start to create from
left of pass (dir1 first → dir2 → dir 3)
/dir1
/dir2/”dir 3”
File1 To copy File1 from current directory to Desktop
cp /home/ahmed
/Desktop
~/Downloads
/home/ahme
d
/Desktop
cp -r dir1/* To copy dir1 from current directory to Desktop
/home/ahme should make -r to copy directory
d * for making the content of directory coped to Desktop
/Desktop
rmdir dir1
rmdir -rf Dir1 (Recursive Force) To remove directory and every thing
inside
nautilus To open file explorer
(Globbing)
ls a* Show each file or directory starts with a
echo $Z=1 or $ Z is variable now and here you print it’s value
z=Ahmed
echo “Today is Here you showing string + date
$(date)”
echo “1+2= Here you showing an arithmetic operation
$[1+2]”
(Help)
ls --help For showing what ls can do and information about it
man ls
-k | grap 1 “print” For showing ever command have a print word in it’s
man describtion
man -K “print” For showing ever command have a print word in it’s
describtion and describe all of them
apropos “print” For showing ever command have a print word in it’s
describtion
passwd For showing what ls can do and information about it
Info
passwd For showing what ls can do and information about it with color
binfo
cd /usr/share/do ls command for showing all files that related to system
c
https://docs.redhat. For help
com
(Redirect)
> /home/ahmed The result go to text.txt file
ls /home /Desktop/text.txt
2> The error go to text.txt file
ls mm /home/ahmed
/Desktop/text.txt
> /home/ahmed The result and the error go to text.txt file
ls /home /Desktop/text.txt
mm 2>
/home/ahmed
/Desktop/text.txt
>> The result is expanded in text.txt
ls /home/ahmed
/Desktop/text.txt
ls /home &> /home/ahmed The result of two go to text.txt
/Desktop/text.txt
/Music
less text.txt To view the content of the file (should press q to close)
more text.txt To view the content of the file (show percentage and
close by itself)
(Pip) |
ls |head -n Show list of content in current directory and filter | to get
first 4 lines
4
ls | tee text.txt | Content of current directory is stored in text.txt and the
wc -l terminal will show no.of lines
Cat text.txt | less Showing content of file but in less way (you can do this
with more too)
Vim To edit files
gedit
nano
Users
useradd -p 123 To create an user and give him a password
ahmed
adduser
-G Ahmed To make this user in a group called Ahmed
ahmed -c IT To but Gecos to this user
-s Departm To change shell
-u ent To give the new user an id
/etc/sbin
/nologin
1001
usermod -p 123 To change password
ahmed
-G Ahmed To make this user in a group called Ahmed
-c IT To but new Gecos to this user
-s Departm To change shell
-u ent To give to an existing user an id
2000
ahmed
ahmed
Permossions (Simpolic)
chmod u+r , dir1 To give the file or directory permission to read
To prevent the file or directory from reading
u-r (Note : the ,to do more than 1 in one command)
u+w To give the file or directory permission to write
To prevent the file or directory from writing
u-w
u+x To give the file or directory permission to be executable
To prevent the file or directory from being executable
u-x
(Note : you can do this with g or o instead of u)
chmod a+rwx dir1 To make theme all have all permissions
chmod -R a=rwx (Recursive) To make the directory and it’s content have this
dir1 Permissions
Numeric
chmod 4 dir1 To give r
Processes:
echo $$ To know the process id of the processes in the current
Shell
ps To show processes that running in current shell
ps -l To show parent id
ps -ef
ps aux | grep 22 To get the process by it’s number is 22
ps fax
Real Time process : (Task Manager for Linux)
top To show all information about the time consuming
through running processes
1 To show all cores
Press P
To show processes acourding to CPU
Press M
To show processes acourding to Memory
Press W
To save
Press q
To quit
Sleep 2000 & The same command but the process will run in bg or
ctrl + z and bg %1 to make the process in bg
Press
not fg
kill 22743 To kill process by pid
Priority between(-20 : 19)(if it low is good because the cpu will look at this process more than the others)
nice firefox Give the process 10 priority
Services
systemctl To view all services and running users in the machine
systemctl status ssh To view information about this service like (Enabled or
disabled) …etc
systemctl status ssh.service
systemctl status -l ssh To view more information
systemctl start ssh To start service if it is inactive
systemctl reload ssh Here the service will reload configuration files without
restart
list- To know what sevicea is depend on ssd
systemctl dependencies ssh
list-units To view all services in list
systemctl --type service
IP:(Network)
ifconfig To view all network slots that exist on your machine
ip add Show To view all network slots that exist on your machine
Powerful more than ifconfig
ip add Show Lo To get information about :o
ip link Show To get more informations about the network slot
ip -s link Show To get more info more than the previous command
addr add dev To change ip address
ip Lo
172.16.0.1/24 make it secondary ip
Ifconfig Lo To change ip address
172.16.0.1/24 make it overwrite on last ip it will be deleted when
restarting the machine
nmcli To view and control networks in this machine
ip route
ip route Show
Installing Pachages
RPM:
rpm -ivh package Installing package
Logs:
systemd-journald To ensure that service of journald is active
systemctl status
journalctl To view all actions that have been done from first day you
installed the os until now
journalctl -n To view last 10 lines in logs
journalctl -n 5 To view last 5 lines in logs
journalctl --since Yesterday – To view all actions from yesterday until now
until now
journalctl --since “2024-2-1” To view all actions between this dates
--until
“2024-2-7”
journalctl _PID=1 To view the actions of Process ID=1
journalctl _UID=0 To view all actions that had done by root (uid=0)
journalctl _SYSTEMD_ To view all actions that beloge to this service
UNIT=shd
last Print the users that login
lastlog Print the content of the last login log
timedatectl Showing every thing about time zone
List-timezones Showing all time zones
timedatectl
set-timezone To change time zone to cairo
timedatectl Africa/Cairo
timedatectl Set-ntp true To synchro the time according to ntp
du -hs (Disk Usage) to know the current directory usage
-s for get the total usage not usage for each file and
directory
df -h
Archiving:
tar -cvf Archive.tar To meke archive file and its content is file1, 2, 3
file1
file 2
file 3
tat -tvf Archive,tar To list the content of the archive file
tar -xvf Archive.tar To extract the archive file
tar -xvf Archive.tar To extract the archive file in another working directory
-c /Desktop
tar Archive.tar.gz Stronger than tar (gzip)
-cvzf
tar Archive.tar.bz2 Stronger than gzip (bzip2)
-cvjf
tar Archive.tar.xz Stronger than bzip2 (xzip)
-cvJf
gzip Text.txt.tar Another way to archive by gzip
bzip2 Text.txt.tat Another way to archive by bzip2
xz Text.txt.tar Another way to archive by xzip
gunzip Text.txt.tar. To unzip/extract the file but the zip file will be deleted
gzip
bunzip2 Text.txt,tar.
bzip2
unxz Text.txt,tar
.zx
unzx -c Text.txt,tar This way the zip file will not deleted while extracting it
.zx > dir1.zx
scp Copy files between many machine
Accessing:
mount /dev/media /media To can access this directory from another way
umount /dev/media To can access current directory from another way
blkid To get uuid of the directory
umount uuid To make mount by uuid
lsof /media Tp know the opened file in /media
ln /dev/media (Hard Link) samr id
To make a new way to access and if the source is deleted
the chiled directory will not be deleted
/media
ln -s /dev/media (Symbolic Link) diffient id
Same but thechiled will be deleted if the source is
deleted
/media
Searching in File System:
whatis passwd To fined a file
whereis Passwd
which passwd
locate passwd You should updatedb before locate
find / -name passwd To search in whole system
find / -name “*.txt” To search in whole system
find / -user ahmed To search in whole system
lsmod View all modules