Linux Adm Lab Commands
Linux Adm Lab Commands
Noida (U.P.)
Session 2024-25
As an example, enter
touch /home/username/Documents/Web.html to create an
HTML file entitled Web under the Documents directory.
11. locate command: You can use this command
to locate a file, just like the search command in Windows.
What’s more, using the -i argument along with this command
will make it case-insensitive, so you can search for a file even if
you don’t remember its exact name.
13. grep command: It lets you search through all the text in
a given file.
After knowing what signal you want to use and the PID of the
program, enter the following syntax:
kill [signal option] PID.
# useradd IILM
In the following example we are going to set the password for the
new user IILM.
# passwd IILM
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
⮚ /etc/passwd - User info file.
When a new user is added an entry is made in the /etc/passwd. In
the following example we are listing all the entries in the passwd
file.
# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
...
...
...
IILM:x:1001:1001::/home/IILM:/bin/sh
We can see that we have the new entry for user name IILM.
IILM:x:1001:1001::/home/IILM:/bin/sh
The line is colon : separated and consists of 7 parts which are the
following.
● Username
● Password
● User ID or UID
● Group ID or GID
● User Info
● Home Directory
● Shell
⮚ useradd -u - Assigning User ID
If we want to assign specific User ID to a user then we can use
the -u option. In the following example we are creating a new user
IILM with userid 500.
So, if we create a new user let’s say, alice then we will get a new
home directory /home/alice. If we want to assign specific home
directory to a user then we can use the -d option.
In the following example we are creating a new user IILM with
home directory /workspace/IILM.
# useradd -M IILM
⮚ useradd -g - Assigning Group ID
If we want to assign specific Group ID to a user then we can use
the -g option. In the following example we are creating a new user
bob with groupid 500.
This is an optional step. If you think you are not going to need
the data of the user then you can jump to the next step.
Pipes are unidirectional i.e. data flows from left to right through
the pipeline.
Syntax:
command_1 | command_2 | command_3 | .... | command_N
For example, listing all files and directories and give it as input to
more command.
$ ls -l | more
archive, compress, unpack and
uncompressed files using tar,
star, gzip and bzip2
⮚ tar
Syntax to create an archive file:
tar [options] [archive-file] [file or directory to be archived]
Create an archive.
# cd /tmp
# tar -cvf archive1.tar test-dir
Check the contents.
# tar -tvf /tmp/archive1.tar
Extract it.
# cd /tmp/extract-dir
# tar -xvf /tmp/archive1.tar
⮚ gzip
The gzip command compresses the specified files, giving them a
".gz" extension. In this case we will use it to compress a ".tar" file.
# cd /tmp
# tar -cvf archive3.tar test-dir
# gzip archive3.tar
The "-z" option of the tar command allows you to do this directly.
# cd /tmp
# tar -cvzf archive3.tar.gz test-dir
The files are uncompressed using the gunzip command.
# gunzip archive3.tar.gz
The "-z" option of the tar command allows you to directly ungzip
and extract a ".tar.gz" file.
# cd /tmp/extract-dir
# tar -xvzf /tmp/archive3.tar.gz
⮚ bzip2
The bzip2 command is similar to the gzip command. It
compresses the specified files, giving them a ".bz2" extension. In
this case we will use it to compress a ".tar" file.
# cd /tmp
# tar -cvf archive4.tar test-dir
# bzip2 archive4.tar
The "-j" option of the tar command allows you to do this directly.
# cd /tmp
# tar -cvjf archive4.tar.bz2 test-dir
The files are uncompressed using the bunzip2 command.
# bunzip2 archive4.tar.bz2
The "-j" option of the tar command allows you to directly bunzip2
and extract a ".tar.bz2" file.
# cd /tmp/extract-dir
# tar -xvjf /tmp/archive4.tar.bz2
⮚ zip
Create an archive.
# cd /tmp
# zip -r archive5.zip test-dir
Check the contents.
# unzip -l archive5.zip
Extract it.
# cd /tmp/extract-dir
# unzip /tmp/archive5.zip
⮚ cpio
Create an archive.
# cd /tmp
# find test-dir | cpio -ov > archive6.cpio
Check the contents.
# cpio -t < /tmp/archive6.cpio
Extract it.
# cd /tmp/extract-dir
# cpio -idmv < /tmp/archive6.cpio
⮚ star
The star command may not be installed by default, but you can
install it with the following command.
# yum install star
Create an archive.
# cd /tmp
# star -cv f=archive2.star test-dir
Extract it.
# cd /tmp/extract-dir
# star -xv f=/tmp/archive2.star
Soft and Hard links in Unix/Linux
A link in UNIX is a pointer to a file. Like pointers in any
programming languages, links in UNIX are pointers pointing to a
file or a directory. Creating links is a kind of shortcuts to access a
file. Links allow more than one file name to refer to the same file,
elsewhere.
setfacl and getfacl are used for setting up ACL and showing ACL
respectively.
For example:
getfacl test/declarations.h
Output:
# file: test/declarations.h
# owner: vikas
# group: vikas
user::rw-
group::rw-
other::r—
List of commands for setting up ACL:
1) To add permission for user
setfacl -m "u:user:permissions" /path/to/file
2) To add permissions for a group
setfacl -m "g:group:permissions" /path/to/file
3) To allow all files or directories to inherit ACL entries from the
directory it is within
setfacl -dm "entry" /path/to/dir
4) To remove a specific entry
setfacl -x "entry" /path/to/file
5) To remove all entries
setfacl -b path/to/file