Kuk Linux 2023
Q2 :- Write the command and its syntax for following action and also explain the command :
(i) View name of files in desending order by time wise.
(ii) Create new user with shell specified.
(iii) View test.test files with permission and change
permission from rw-r-rw- to rwxrw-r--
(i) View name of files in descending order by time-wise
Command:ls -lt
Syntax:
ls -lt [directory]
Explanation:
ls
is the command to list directory contents.-l
option provides a detailed listing (long format) which includes file permissions, number of links, owner, group, size, and time of last modification.-t
option sorts the files by modification time, with the newest files first.- When combined (
-lt
), it lists files in long format sorted by time in descending order.
ls -lt /path/to/directory
(ii) Create a new user with a specified shell
Command:useradd -s
Syntax:
sudo useradd -s /path/to/shell username
Explanation:
useradd
is the command to create a new user.-s
option allows specifying the user’s login shell.sudo
is used to execute the command with superuser privileges, which is typically required for user management.
sudo useradd -s /bin/bash newuser
(iii) View test.test
file with permissions and change permissions from rw-r--rw-
to rwxrw-r--
To view the file permissions:
Command:
ls -l
Syntax:
ls -l test.test
Explanation:
ls -l
lists files in long format, showing detailed information including file permissions.
ls -l test.test
To change the file permissions:
Command:
Syntax:
Command:
chmod
Syntax:
chmod 764 test.test
Explanation:
chmod
is the command to change file permissions.- The numerical representation
764
translates to:7
(rwx) for the owner6
(rw-) for the group4
(r–) for others
chmod 764 test.test