Akram-BSMRSTU / Linux_command

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

                                                                       Linux Command

cat /etc/passwd

• To show userlist .

sudo useradd user1 –g 1001

• create new user with group id 1001

1st image

sudo groupadd –g 1002 group1

• Add new group “group1” with group id 1002

2nd

sudo usermod user1 -g 1002

• Assign user1 in new group which id is 1002

3

mkdir {os-concepts,ubuntu-is-the-best}

• Create multiple file in one command in home Directory.

4

cd os-concepts

• To change Directory home to newly Created os-concepts

touch file1,file2

• To create 2 file

5

ls –l

• To show the permission of the file where w indicates write, r indicates Read and x indicate Execute.

6

To update file permissions so that the owner can read and write, the group can only read, and others have no permissions, you can use the chmod command in Linux with the following syntax • chmod 640 file1.txt,file2.txt In this command: 6 represents read (4) + write (2) permissions for the owner. 4 represents read permission for the group. 0 represents no permissions for others.

7

sudo groupadd –g 1010 newsgroup

• Create new group with id 1010 which name is newsgroup.

8

To update ownership of a file to the newly created group you can use chown command.

• sudo chown :newgroup file.txt,file2.txt

9

To assign user1 to newly created group which gid is 1010

• sudo usermod –a –G newgroup user1 10

To create a file named "crash.in" containing the word "crash" in different directories and then find those files using the find command, you can follow these steps:

• echo "crash" > ~/os-concept/crash.in

• echo "crash" > ~/ubuntu-is-the-best/crash.in • echo "crash" > ~/Desktop/crash.in

find ~/ -name "crash.in"

• Use the find command to locate all instances of the file. • This command will search for files named "crash.in" starting from the root directory (/) and display the paths to all matching files.

11

find ~/ -name "crash.in" -print0 | xargs -0 sed -i 's/crash/broken/g'

• find / -name "crash.in" -print0: This finds all files named "crash.in" starting from the home directory () and prints the file paths with null terminators (to handle filenames with spaces or special characters).

• xargs -0 sed -i 's/crash/broken/g': This takes the output of the find command and uses xargs to execute sed on each file. The sed command (sed -i 's/crash/broken/g') replaces all occurrences of "crash" with "broken" in each file in-place. After running this command, all instances of "crash" in the "crash.in" files within the specified directories will be replaced with "broken".

12

About


Languages

Language:Shell 100.0%