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

linux commands

Uploaded by

robinskroy0
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

linux commands

Uploaded by

robinskroy0
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Linux commands

User manangement commands


Add an new user :
Syntax : sudo useradd user_name
Example : sudo useradd jose
Create a user with a userid and default home directory :
Syntax : sudo useradd -u UID -d /path/to/home_directory username
Example : sudo useradd -u 2001 -d /jose jose
To create a new directory if it doesn’t exist:
Syntax : sudo useradd -u uid -d /path/to/home_directory -m username
Example : sudo useradd -u 2001 -d /home/jose -m jose
Delete a user :
Syntax : sudo deluser username
Example : sudo deluser jose
Change users password :
Syntax : sudo passwd username
Example : sudo passwd jose
Switch to another user :
Syntax : sudo su – username
Example : sudo su - jose
Locate all files owned by a user :
Syntax : find /path -user username
Example : find / -user jose
Directory Commands :
To create a directory :
Syntax : mkdir directory_name
Example : mkdir jose
Change directory :
Syntax : cd directory_name
Example : cd my_project
List all files in a directory :
Syntax : ls -l (example – same)
Remove a directory :
Syntax : rm -r directory_name
Example : rm -r my_directory
To create a subdirectory :
Syntax : mkdir parent_directory/subdirectory
Example : mkdir my_directory/jose

File management commands :


Create a file :
Syntax :touch file_name
Example : touch my_file
Copy a file :
Syntax : cp source_file destination_path
Example cp my_file /jose/renamed_file
Move a file :
Syntax : mv source_file destination_path
Example : mv old_name.txt /home/new_name.txt
Rename a file :
Syntax : mv old_name new_name
Example : mv new_name.txt old_name.txt
Remove a file :
syntax : rm file_name
example : rm my_folder.txt
view content of a file :
syntax : cat file_name
example : cat my_file

Changing file permissions :


Syntax : chmod mode file_name
Mode can be of integer containing three values
Example : chmod 757 my_file
Each file/directory has three types of permissions:
 Read (r): Allows viewing file content or listing a directory.
 Write (w): Allows modifying the file or creating/deleting files in a directory.
 Execute (x): Allows executing a file/script or accessing a directory.
Permissions are divided into three groups:
 Owner: The user who owns the file.
 Group: Users who are in the file's group.
 Others: All other users.
 Permissions can also be represented numerically:
o Read = 4, Write = 2, Execute = 1
o Add values to set permissions:
 7 (rwx) = Read + Write + Execute
 6 (rw-) = Read + Write
 5 (r-x) = Read + Execute
 0 (---) = No permission

For example in the above example chmod 757 my_file the first 7 represents that owners
have full permissions. The second integer in the mode represenst the permissions for groups
in the above example the group has permissons only for read and execute and third integer
represents permission for other users . in the above example other users have all
permissions.
7 5 7
Permission for owners permission for other
users

Permission for
groups
Change file ownership :
Syntax : sudo chown username:group file_name
Example : sudo chown john:developers file.txt

Group management commands :


Create a group :
Syntax : sudo groupadd group_name
Example : sudo groupadd my_group
Add user to a group :
Syntax : sudo usermod -aG group_name username
Example : sudo usermod -aG developers jose
Remove from a group :
Syntax : sudo gpasswd -d username group_name
Example : sudo gpasswd -d jose my_group
To remove all groups except their primary group :
Syntax : sudo usermod -G primarygroup username
Example : sudo usermod -G primarygroup jose
Delete a group :
Syntax : sudo groupdel group_name
Example : sudo groupdel my_group

You might also like