0% found this document useful (0 votes)
13 views15 pages

Commands of Rhel

Uploaded by

abdu772727
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views15 pages

Commands of Rhel

Uploaded by

abdu772727
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Commands of RHEL 2024

Command Description Example

pwd Prints the full pathname of the pwd


current working directory.

echo $SHELL Displays the shell currently in echo $SHELL


use.

ls Lists all fi ls
les and directories in the current
directory.

ls -l Detailed list with permissions, ls -l


ownership, and size.

ls -a Includes hidden files. ls -a

ls -ld Displays detailed information ls -ld /Desktop


<directory> about directories without listing
contents.

cd Change Directory; returns to cd


home directory if used alone.
cd <directory> Changes into the specified cd Documents
directory.

cd .. Moves up one directory. cd ..

touch Creates a new file or updates touch file.txt


<filename> the timestamp of an existing
file.

cat <filename> Displays the contents of a file. cat file.txt

echo "New Writes "New content" to a file, echo "Hello" >


content" > removing existing text. greetings.txt
<file_name>

echo "New Appends "New content" to a file echo "World" >>


content" >> without removing existing text. greetings.txt
<file>

file <filename> Determines the type of a file. file document.pdf

less <file.txt> Allows scrolling through a file; less notes.txt


press q to exit.
more <file.txt> Similar to less but with simpler more notes.txt
interface.

tail -n 10 Shows the last 10 lines of a file. tail -n 10 log.txt


<file.txt> if you want to appear 5 line type
5 instead of 10

head -n 10 Shows the first 10 lines of a file. head -n 10 log.txt


<file.txt>

mkdir Creates a directory in the mkdir new_folder


<dir_name> current directory.

mkdir Creates multiple directories at mkdir dir1 dir2 dir3


<dir1_name> once.
<dir2_name>

mkdir -p Creates nested directories. mkdir -p fruits/apples


fruits/apples

touch Creates a file named test20 touch testdir/test20


testdir/test20 inside the testdir directory.

cd Changes the current working cd Desktop/testdir


Desktop/testdir directory to Desktop/testdir.
find -name Searches for a specific file by find -name "test.txt"
"file_name" name.

find ~/Desktop/ Searches for a specific file in find ~/Desktop/ -name


-name the Desktop directory. "report.doc"
"file_name"

locate Quickly finds files using a locate report.doc


<filename> pre-built database.

mv <oldname> Renames a file from oldname to mv oldfile.txt


<newname> newname. newfile.txt

mv filename Moves a file to the specified mv file.txt Documents/


<destination_di directory.
rectory>

rm <file_name> Deletes the specified file. rm unwanted_file.txt

cp Copies a file to the specified cp file.txt backup.txt


<source_file> destination.
<destination_fi
le>

nano Opens the file in the Nano text nano test.txt


<file_name> editor for editing.

mv Renames a directory. mv old_folder


<old_dir_name> new_folder
<new_dir_name>
mv Moves a directory to the mv myfolder Documents/
<directory_name specified destination.
>
<destination_di
rectory>

rmdir Removes an empty directory. rmdir empty_folder


<directory_name
>

rm -r Removes a directory and its rm -r myfolder


<directory_name contents.
>

cp -r Copies a directory and its cp -r dir1 Desktop


<source_directo contents.
ry>
<destination_di
rectory>

chmod u+x Adds execute permission for chmod u+x test.txt


<filename.txt> the owner.

chmod g=x Sets group execute permission. chmod g=x test.txt


<filename>

chmod a=r Sets read permission for all chmod a=r test.txt
<filename> users.

chmod a+rw Adds read and write permission chmod a+rw test.txt
<filename> for all users.
chmod Modifies specific permissions chmod u+rx,g+x,o-r
u+rx,g+x,o-r for owner, group, and others. test.txt
<filename>

cat /etc/passwd Displays all users. cat /etc/passwd

sudo cat Displays users with password sudo cat /etc/shadow


/etc/shadow information.

sudo chown Changes the owner of a file. sudo chown user2


<newowner> file.txt
<filename.txt>

sudo chgrp Changes the group of a file. sudo chgrp admin


<newgroup> file.txt
<filename.txt>

sudo chown Changes the owner and group sudo chown user2:admin
<newowner>:<new of a file. file.txt
group>
filename.txt

useradd Adds a new user to the system. sudo useradd Khadija


<Khadija>

passwd Changes the password for a sudo passwd Khadija


<Khadija> user.
usermod -l Modifies an existing user usermod -l newKhadija
<newname> account. Khadija
<oldname>

usermod -aG Adds the user to a specific usermod -aG admins


<groupname> group without removing other Khadija
<username> groups.

userdel Deletes a user account. sudo userdel Khadija


<Khadija>

groupadd Adds a new group to the groupadd IT_group


<IT_group> system.

cat /etc/group Allows you to view the groups. cat /etc/group

gpasswd -a Adds a user to a specific group. gpasswd -a Khadija


<username> IT_group
<groupname>

groupmod -n Modifies an existing group to groupmod -n


<newgroupname> rename. new_IT_group IT_group
<oldgroupname>

groupdel Deletes a group. groupdel IT_group


<IT_group>

groups Shows the groups to which a groups Khadija


<Khadija> user belongs.
id <Khadija> Displays user ID (UID) id Khadija

su - <Khadija> Switches to another user su - Khadija


account.

who Displays currently logged-in who


users.

last Shows the last logins of users. last

chage -l Changes user password chage -l Khadija


<username> expiration information.

<command> > Redirects the output of a ls > output.txt


<file_name> command to a file.

<command> 2> Redirects the error output to a ls non_existing_file 2>


<file_name> file. error.txt

ls > file_name Redirects output and error to ls > output.txt 2>


2> file_name2 different files. error.txt
ls > file_name Redirects both output and error ls > output.txt 2>&1
2>&1 to the same file.

wc file_name Counts lines, words, and wc file.txt


characters in a file.

wc -l file_name Counts the number of lines in a wc -l file.txt


file.

wc -w file_name Counts the number of words in wc -w file.txt


a file.

<command1> ; Runs commands sequentially, echo "Hello"; echo


<command2> regardless of success or failure. "World"

<command1> && Runs the second command mkdir new_folder && cd


<command2> only if the first succeeds. new_folder

<command1> || Runs the second command rm non_existing_file ||


<command2> only if the first command fails echo 'File does not
exist'
date Displays the current date and date
time.

cal Displays the calendar for the cal


current month.

sort Sorts lines of text in files or sort unsorted.txt


<file_name> input.

uniq Filters out or reports repeated uniq file.txt


<file_name> lines in a sorted file.

export Sets an environment variable. export VAR20=12345


<VAR_name>=<val
ue>

echo <$USER> Displays a specific environment echo $USER


variable.

env Displays all environment env


variables.

printenv <USER> Prints the value of a specific printenv HOME


environment variable.
unset Removes a specific unset MY_VAR
<Variable_name> environment variable.

alias Creates an alias for a alias ll='ls -la'


<shortcut_name> command.
='<command>'

alias Lists all aliases. alias

unalias Removes a specific alias. unalias ll


<shortcut_name>

grep Searches for patterns within grep "error"


"<pattern>" files. logfile.txt
<file>

<command_1> | Passes output of command_1 sort file.txt | uniq


<command_2> as input to command_2.

set -o Prevents accidental overwriting set -o noclobber


noclobber of files.

<command> & Runs a command in the sleep 10 &


background.
jobs Displays status of all stopped jobs
and background jobs.

jobs -l Displays jobs with Process ID. jobs -l

fg Brings a specific job to the fg %1


%<job_number> foreground using job number.

fg <Process_id> Brings a specific job to the fg 1234


foreground using Process ID.

bg <Process_id> Sends a specific job to the bg 1234


background using Process ID.

bg Sends a specific job to the bg %1


%<job_number> background using job number.

kill Kills a job using the job number. kill %1


%<job_number>
kill -9 Forcefully kills a job if it does kill -9 %1
%<job_number> not terminate with kill
command.

kill -9 Forcefully kills a process using kill -9 1234


<process_id> Process ID.

kill Kills a job using the Process ID. kill 1234


<process_id>

getfacl Displays the Access Control getfacl file.txt


<file_name> List (ACL) for a file.

getfacl Displays the Access Control getfacl file.txt


<directory_name List (ACL) for a directory.
>

setfacl Sets or modifies the Access setfacl -m u:user1:rw


Control List (ACL) for a file or file.txt
directory.

setfacl -m Allows cs group to read and setfacl -m g:cs:rw


g:cs:rw write to test.txt. test.txt
test.txt

setfacl -x Removes user1's access to setfacl -x u:user1


u:user1 test.txt. test.txt
test.txt
vi <file_name> Opens the file in the vi text vi file.txt
editor for editing.

ps Provides a snapshot of current ps


processes and their status.

ps aux Displays detailed information ps aux


about all running processes.

top Provides a dynamic real-time top


view of the running system.

top -u Displays processes for a top -u Khadija


<username> specific user.

sudo <command> Executes a command with sudo useradd ahmed


superuser privileges.

su Switches to the root user. su


init Changes the run level of the init 5
<RunLevel_num> system.

Option Function
:wq+ENTER Saves all changes and quit

i Inserts text

:W+ENTER Saves the file

:q!+ENTER Quits without saving changes

:w Writes to a different file


<filename>+
Enter

You might also like