Linux Commands
Linux Commands
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
<-------------------------------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 ----------------------------------------------
>
<----------------------------------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