Basic -> Advanced
This page gives you indepth commands which will help to write linux scripts
man man
The table below shows the section numbers of the manual followed by the types of pages they contain.
1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions, e.g. /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7), man-pages(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
apropos
apropos - search the manual page names and description
$apropos directo
ls (1) - list directory contents
mkdir (2) - create a directory
mkdirat (2) - create a directory
mkdtemp (3) - create a unique temporary directory
mkfontdir (1) - create an index of X font files in a directory
mklost+found (8) - create a lost+found directory on a mounted Linux second extended file system
mktemp (1) - create a temporary file or directory
modprobe.d (5) - Configuration directory for modprobe
mountpoint (1) - see if a directory or file is a mountpoint
ntfsls (8) - list directory contents on an NTFS filesystem
opendir (3) - open a directory
pam_mkhomedir (8) - PAM module to create users home directory
pwd (1) - print name of current/working directory
pwdx (1) - report current working directory of a process
readdir (2) - read directory entry
readdir (3) - read a directory
readdir (3am) - directory input parser for gawk
command <tab> <tab>
Gives you options for command
for example
systemctl <tab> <tab>
add-requires daemon-reload halt is-system-running list-unit-files reboot set-default suspend-then-hibernate
add-wants default help kexec list-units reenable set-environment switch-root
bind disable hibernate kill log-level reload set-property try-reload-or-restart
cancel edit hybrid-sleep link log-target reload-or-restart show try-restart
cat emergency import-environment list-dependencies mask rescue show-environment unmask
condreload enable is-active list-jobs mount-image reset-failed start unset-environment
condrestart exit is-enabled list-machines poweroff restart status
condstop force-reload is-failed list-sockets preset revert stop
daemon-reexec get-default isolate list-timers preset-all service-watchdogs suspend
stat <filename>
stat - display file or file system status
$stat help.txt
File: help.txt
Size: 52 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 4482838 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/gopikrishna) Gid: ( 1002/gopikrishna)
Access: 2023-08-02 16:55:41.169924633 +0530
Modify: 2023-08-02 18:53:00.422372139 +0530
Change: 2023-08-02 18:53:00.422372139 +0530
Birth: 2023-08-02 18:53:00.422372139 +0530
ln - make links between files
$cat help.txt
Sample Test In File help.txt
$ mkdir s_links
$ ln help.txt s_links/help2.txt
$ stat help.txt
File: help.txt
Size: 52 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 4482838 Links: 2
Access: (0664/-rw-rw-r--) Uid: ( 1001/gopikrishna) Gid: ( 1002/gopikrishna)
Access: 2023-08-02 21:28:54.559360758 +0530
Modify: 2023-08-02 18:53:00.422372139 +0530
Change: 2023-08-02 21:28:54.227365691 +0530
Birth: 2023-08-02 18:53:00.422372139 +0530
$ cat s_links/help2.txt
Sample Test In File help.txt
ln -s , --symbolic make symbolic links instead of hard links
$ ls
help.txt s_links
$ ln -s help.txt help_shortcut.txt
$ ls -l
total 8
lrwxrwxrwx 1 gopikrishna gopikrishna 8 Aug 2 22:22 help_shortcut.txt -> help.txt
-rw-rw-r-- 2 gopikrishna gopikrishna 52 Aug 2 18:53 help.txt
drwxrwxr-x 2 gopikrishna gopikrishna 4096 Aug 2 21:28 s_links
$ stat help_shortcut.txt
File: help_shortcut.txt -> help.txt
Size: 8 Blocks: 0 IO Block: 4096 symbolic link
Device: fc01h/64513d Inode: 4486493 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 1001/gopikrishna) Gid: ( 1002/gopikrishna)
Access: 2023-08-02 22:22:19.064124562 +0530
Modify: 2023-08-02 22:22:18.738124113 +0530
Change: 2023-08-02 22:22:18.738124113 +0530
Birth: 2023-08-02 22:22:18.738124113 +0530
SUID,SGID,STICKY BIT
SUID (4): Execute as file owner
ls -l /usr/bin/passwd # -rwsr-xr-x (s in user position)
chmod u+s file # Set SUID
chmod 4755 file # Set SUID numerically
find / -perm -4000 # Find SUID files
SGID (2): Execute as group owner/inherit group
ls -l /usr/bin/write # -rwxr-sr-x (s in group position)
chmod g+s directory # Set SGID
chmod 2755 directory # Set SGID numerically
find / -perm -2000 # Find SGID files
Sticky (1): Only owner can delete files
ls -ld /tmp # drwxrwxrwt (t at the end)
chmod +t directory # Set Sticky Bit
chmod 1777 directory # Set Sticky Bit numerically
find / -perm -1000 # Find Sticky Bit directories
Combined Examples of SUID.SGID.STICKY BIT
chmod 7755 file # Set SUID(4) + SGID(2) + Sticky(1) = 7
chmod 3777 directory # Set SGID(2) + Sticky(1) = 3
Last updated