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

RedHat Linux Commands

The document provides information about various Linux commands related to directories, files, users and permissions. It describes commands for navigating directories, creating/deleting files and folders, viewing file contents, managing users and groups, changing file permissions and owners. SELinux modes and configuring network interfaces are also covered.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

RedHat Linux Commands

The document provides information about various Linux commands related to directories, files, users and permissions. It describes commands for navigating directories, creating/deleting files and folders, viewing file contents, managing users and groups, changing file permissions and owners. SELinux modes and configuring network interfaces are also covered.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

RedHat Linux Commands

Linux Directory Commands

Cmd Description Syntax

pwd The pwd command is used to display the location of pwd


the current working directory.

mkdir The mkdir command is used to create a new directory mkdir <dir name>
under any directory.

rmdir The rmdir command is used to delete a directory. rmdir <dir name>

ls The ls command is used to display a list of content of a ls


directory.
cd The cd command is used to change the current cd <dir name>
directory.

Linux File commands

Cmd Description Syntax

touch The touch command is used to create empty files. We touch <file name>
can create multiple empty files by executing it once. touch <file1> <file2>
cat The cat command is a multi-purpose utility in the cat <file name>
Linux system. It can be used to create a file, display
content of the file, copy the content of one file to
another file, and more.

rm The rm command is used to remove a file. rm <file name>

cp The cp command is used to copy a file or directory. cp <existing file name>


<new file name>

mv The mv command is used to move a file or a directory mv <file name>


form one location to another location. <directory path>

rename The rename command is used to rename files. It is rename 's/old-name/new-


useful for renaming a large group of files. name/' files
Linux File Content commands
Cmd Description Syntax
head It displays the beginning of a file. head <file name>
tail It displays the last last part of a file. tail <file name>
cat This command is versatile and multi worker. cat <file name>
tac Opposite of cat. tac <file name>
more Command line displays contents in pager form that is more <file name>
either in more format.
less Command line displays contents in pager form that is less <file name>
either in less format.
vim Vim is an editor to create or edit a text file. vim <file name>
vi The vi editor tool is an interactive tool as it displays vi <file name>
changes made in the file on the screen while you edit
the file.

Linux User Content commands

Cmd Description Syntax

su The su command provides administrative access to su <user name>


another user. In other words, it allows access of the
Linux shell to another user.

id The id command is used to display the user id (uid) id


and group id(gid).

useradd The useradd command is used to add or remove a useradd <user name>
user on a Linux server.

passwd The passwd command is used to create and change passwd <user name>
the password for a user.

groupadd The groupadd command is used to create a user1. groupadd <group name>
group.

Show User : cd /home > ls

Group create : cd /root /Desktop


Show Group : cat /etc /group
Run Levels in Linux

Run-level Description

0 System halt i.e., the system can be safely powered off with no activity.

1 Single user mode.

2 Multiple user mode with no NFS (network file system).

Multiple user modes under the command line interface and not under the

3 graphical user interface.

4 User-definable.

Multiple user mode under GUI (graphical user interface) and this is the

5 standard runlevel for most of the LINUX-based systems.

6 Reboot which is used to restart the system.

Syntax:
init <runlevel_value>
telinit <runlevel_value>

Show UID GID Group : id <username>


Delete User: userdel <username>
Delete Group: groupdel <groupname>
Linux Usermod Commands
The syntax of the usermod command is:
# usermod [options] {user name}

Option Description Example


-c Sets Comment Field # usermod -c “user one” user
-u Changing a User UID # usermod -u 1050 user
-l Change User’s Login Name # usermod –l u1 user
-L Lock a User # usermod -L user
-U Unlock the user # usermod -U user
-p Set Password for a User # usermod -p [newname] [oldname]
-g Change User Primary Group # usermod -g [group] [username]
-G Add a User to a Group # usermod –a –G user
-s Changing a User Default Shell # usermod -s SHELL user
-l Change User’s Login Name # usermod -l [newname] [oldname]
-d Set User’s Home Directory # usermod -d HOME_DIR user
File Permission / Access Modes:

 Owner permissions − The owner's permissions determine what actions the owner of the
file can perform on the file.
 Group permissions − The group's permissions determine what actions a user, who is a
member of the group that a file belongs to, can perform on the file.
 Other (world) permissions − The permissions for others indicate what action all other
users can perform on the file.

While using ls -l command, it displays various information related to file permission

$ls -l /home/amrood

-rwxr-xr-- 1 amrood users 1024 Nov 2 00:10 myfile

drwxr-xr--- 1 amrood users 1024 Nov 2 00:10 mydir

Changing Permissions

To change the file or the directory permissions, you use the chmod (change mode) command.
There are two ways to use chmod — the symbolic mode and the absolute mode.

Using chmod in Symbolic Mode


Sr.No. Chmod operator & Description
1 [+] Adds the designated permission(s) to a file or directory.

2 [-] Removes the designated permission(s) from a file or directory.

3 [=] Sets the designated permission(s).

$chmod o+wx testfile

$ls -l testfile

-rwxrwxrwx 1 amrood users 1024 Nov 2 00:10 testfile

$chmod u-x testfile

$ls -l testfile

-rw-rwxrwx 1 amrood users 1024 Nov 2 00:10 testfile


$chmod g = rx testfile

$ls -l testfile

-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile

Using chmod with Absolute Permissions

The second way to modify permissions with the chmod command is to use a number to specify each set of
permissions for the file.

l = link User owner Permission Group Owner Permission

c = Char

b = block drwx-rx-rw
d = dir Other user Permission
Changing Owners and Groups
Two commands are available to change the owner and the group of files −
 chown − The chown command stands for "change owner" and is used to change the
owner of a file.
 chgrp − The chgrp command stands for "change group" and is used to change the
group of a file.

# chown <username> <filename>


# chown <groupname> <filename>

SELinux Modes

There are three main SELinux modes:

1. Enforcing mode. The default and most secure SELinux mode. In this mode, SELinux
enforces the access control policies set by the sysadmin and does not allow users to
override them. If a user or process attempts to access a resource not authorized by the
policies, SELinux denies the request and logs the decision in AVC.
2. Permissive mode. Less secure than enforcing mode but still provides protection. In this
mode, SELinux does not enforce the policies but logs events when a user or process
attempts to access a resource blocked off by the policies. This enables sysadmins to
monitor the system for potential security issues and make any necessary policy changes
before authorizing the enforcing mode.
3. Disabled mode. The least secure mode as it does not protect system resources. In this

mode, SELinux does not enforce access control policies. This mode is useful for testing
or debugging.

Open the SELinux config file in a text editor of your choice.

# vim /etc/selinux/config
Set the SELINUX variable to permissive with:

*you have been provided a virtual box named as serverX.example.com (hint:where X is your
domain number) * password for both virtual machine should be "Postroll"
*serverX.example.com provided with ip=172.25.X.11/255.255.255.0 *serverX.example.com
are provided with gateway 172.25.254.254 & example.com dns domain with the IP:
172.25.254.254
*NOTE: I have Foundation Machine # 9, so I am using 172.25.9.11
# nmcli connection add con-name eth0 ifname eth0 type ethernet ip4 172.25.9.11/24 gw4
172.25.254.254
# nmcli connection modify eth0 ipv4.dns 172.25.254.254
# nmcli connection modify eth0 ipv4.dns-search example.com
# nmcli connection modify eth0 ipv4.method manual
# nmcli connection modify eth0 connection.autoconnect yes
# nmcli connection down eth0 # nmcli connection up eth0

You might also like