0% found this document useful (0 votes)
18 views

Linux Commands

Uploaded by

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

Linux Commands

Uploaded by

Ritu priya singh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

man uname

uname
man ln ->> ln is the command the create a link b/w files
nano filename
ls -l filename ->> list the content of the current directory
ln (link) ->> hardlink(inode of linked file is same) and softlink(inode of the
linked file is different)
inode is the base number
ln filename file2 ->> hardlink
cat file2
ls -i filename ->> check the inode number of the file
nano link1
ln -s link1 link2
ls -l link1
ls -l link2
file link2
nano link2

HW: Suppose user LPU exists with default dir /home/LPU. Change its default dir
to /home/New. Also move data from /home/LPU to /home/New
hint: usermod -m and -d

ip --brief addr show

<-------------------------------Unit 6------------------------------------>

id
ps -au
cat /etc/passwd
cat /etc/group
su - user1
su -
sudo usermod -L user1
sudo tail -4 /var/log/secure
usermod ---> -a, --append
---> -c, --commented
---> -d, --home
---> -g, --gid
---> -G, --groups
---> -L, --lock (! mark in the shadow file)
---> -m, --move-
---> -s, --shell
---> -U, --unlock
useradd user1
userdel user1
ls -l /home
rm -rf user1
userdel -rf user1
passwd user1
tail -4 /etc/passwd
userdel -r user1
groupadd -g 10000 group1
groupadd -r group2
groupmod -n new_name existing_name
groupmod -g 2000 group1
groupdel group1
usermod -g group1 user1
usermod -aG group1 user3
newgrp group2
cat /etc/shadow
chage -m 0 -M 90 -W 6 -I 14 user1
date +%F
date -d "+30 days" +%F
chage -E $(date -d "+30 days" +%F) user3
chage -l user3 | grep "Account expires"
chage -d 0 user3
date -d -u
cd /etc/login.defs
cat /etc/shadow
tail -4 /etc/passwd

<-----------------------------Unit-7 ----------------------------------------------
>

ls -la ---> long listing of files in that directory


u -> user
g -> group
o -> other
a -> all
+ -> add
- -> remove
= -> set exactly
r -> read
w -> write
x -> execute
X -> special execute
chmod go-rw doc.pdf
chmod -R g+rwx /home/user/myfolder
chmod -R g+rwX demodir
chmod 777 file/directory
chmod 644 sample.txt
read -> 4, write -> 2, execute -> 1 (4+2+1)
chown student app.conf
chown -R student Pictures
chown :admins Pictures
chown visitor:guests Pictures
u+s -> suid (setuid)
g+s -> sgid (setgid)
o+t -> sticky
ls -l /usr/bin/passwd
ls -ld /run/log/journal
ls -ld /usr/bin/locate
ls -ld /tmp
setuid -> 4; setgid -> 2; sticky -> 1 (octal representation)
chmod g+s example (add setgid bit)
chmod u-s example (remove setuid bit)
chmod 2770 example (setgid bit and add, read, write and execute permissions for
user and group, with no access for others)
chmod 0770 example (remove setgid bit and add r,w,x for both users and group, with
no permissions to others)
umask -> 0022
inital file permissions -> rw-rw-rw- -> 0666
umask -> ----w--w- -> 0022
resulting file permissions -> rw-r--r-- -> 0644
umask 0 -> the file permissions for others change from read to read and write. The
dir permissions for other change from read and execute to read, write, and execute.
umask 007
umask 027 -> new files have read and write permissions for user and read permission
for group. new dir have read and execute permissions for group and no permissions
for other.

<----------------------------------Unit
8-------------------------------------------->

top
ps aux
ps lax
ps -ef
ps is for listing detailed information for current processes
Running -> R (TASK_RUNNING)
Sleeping -> S (TASK_INTERRUPTIBLE)
-> D (TASK_UNINTERRUPTIBLE)
-> K (TASK_KILLABLE)
-> I (TASK_REPORT_IDLE)
Stopped -> T (TASK_STOPPED)
-> T (TASK_TRACED)
Zombie -> Z (EXIT_ZOMBIE)
-> X (EXIT_DEAD)
sleep 10000 & -> the task will run in the background
jobs
example_command | sort | mail -s "Sort output" &
fg %1 -> bring background job to foreground. %jobnumber format to specify the
process to foreground
ps j -> find process and session information
bg %1 -> to start running the suspended process
HUP -> 1 -> Hangup
INT -> 2 -> Keyboard interrupt (ctrl+c)
QUIT -> 3 -> Keyboard quit (ctrl+\)
KILL -> 9 -> Kill, unblockable
TERM -> 15 -> Terminate
CONT -> 18 -> Continue
STOP -> 19 -> Stop, unblockable
TSTP -> 20 -> Keyboard Stop
kill -l
ps aux | grep job
kill -9 jobnumber
pgrep -l -u bob
pstree
w -> user controll activity
uptime -> display the current load average
lscpu -> determine the number of CPU on a system
? or h -> help
l -> load; t -> threads; m -> memory
1 -> Toggle for individual CPU or a summary for all CPU in the header
s -> change the refresh (screen) rate
b -> Toggle reverse highlighting for Running processes; the default is bold only
shift+b -> enable bold use in display, in the header and for Running processes
shift+h -> Toggle threads; show process summary or individual threads
u, shift+u -> filter for any username (effective, real)
shift+m -> sort process listing by memory usage, in descending order
shift+p -> sort process listing by processor usage, in descending order
k -> kill a process
r -> renice a process
shift+w -> write save the current display configuration for use at the next top
restart
q -> quit
f -> manage columns by enabling or disabling fields

<---------------------------------Unit 9---------------------------------->

systemctl list-units --type=service -> paginates all currently loaded service units
systemctl list-units --type=service --all
systemctl
systemctl list-unit-files --type=service
systemctl status sshd.service
systemctl is-active sshd.service
systemctl is-enabled sshd.service
systemctl is-failed sshd.service
systemctl start sshd
systemctl stop sshd.service
systemctl restart sshd.service
systemctl reload sshd.service
systemctl reload-or-restart sshd.service
systemctl list-dependencies sshd.service
systemctl mask sendmail.service
systemctl list-unit-files --type=service
systemctl start sendmail.service
systemctl unmask sendmail
systemctl enable sshd.service
systemctl enable --now sshd.service
systemctl disable --now sshd.service
systemctl is-enabled sshd.service

<-----------------------------------Unit 10------------------------------->

ssh-keygen
ssh-keygen -f .ssh/key-with-pass
ssh-copy-id -i .ssh/key-with-pass.pub user@remotehost
ssh -i .ssh/key-with-pass user@remotehost
eval $(ssh-agent)
ssh-add
ssh user@remotehost
ssh -v user@remotehost

cd /etc/ssh/sshd_config -> PermitRootLogin yes; PasswordAuthentication yes


systemctl reload sshd
<-----------------------------------unit
11-------------------------------------------->

ip --brief addr show


ip link show
ip addr show ens3
ip -s link show ens3
ping ipOfanotherHost
ip route
ip -6 route
ss -ta
nmcli dev status
nmcli con show
nmcli con show --active
nmcli con-add type ethernet con-name cse493 ifname enp0s3 ipv4.addresses
10.0.2.16/24 ipv4.gateway 255.255.255.1 ipv4.dns 8.8.8.8 ipv4.method auto
nmcli con UP cse493
nmcli con modify cse493 +ipv4.addresses 10.0.2.17/24
ip link show -> to check the ip address
nmcli con modify cse493 ipv4.dns _______ ipv4.gateway ________ ipv4.address
________
cat cse493.nmconnections
nmcli con delete cse493
nmcli con down cse493
nmcli reload cse493

You might also like