Question

In: Computer Science

Command Example Usage Explanation whoami groups touch chmod

Command

Example Usage

Explanation

whoami

groups


touch



chmod



Solutions

Expert Solution

Command Example Usage Explanation
whoami

Example 1: Display the domain and user name of the current user: whoami

Example 2: Display the user groups to which the current user belongs:

whoami/groups

Example 3: Display all of the information in the current access taken:

whoami/all

whoami coomand is used iboth in Unix operating system and as well as windows operating system

  • It is basically the concatenation of the strings "who","I","am" as whoami.
  • It displays the username of the current user when this command is invoked.
It is similar as running the id command with the options -un.
groups

Example 1: Provided with a user name

Syntax:

groups [username]...

In this example, username akshay is passed with groups command and the output shows the groups in which the user demon is present, separated by a colon.

Example 2: No username is passed then this will display group membership for the current user

Syntax:$groups

Here the current user is akshay. So when we give “groups” command only we get groups in which akshay is a user.

Example 3: Passing root with groups command

In linux, there can be multiple users(those who use/operate the system), and groups are nothing but the collection of users. Groups make it easy to manage users with the same security and access privileges. A user can be part of different groups.The groups command works irrespective of whether you provide it a username or not. In case there's no username, the tool displays group memberships for the current process.

  • Groups command prints the names of the primary and any supplementary groups for each given username, or the current process if no names are given.
  • If more than one name is given, the name of each user is printed before the list of that user’s groups and the username is separated from the group list by a colon.
touch

Example:1 Create an empty file using touch

To create an empty file using touch command on Linux systems, type touch followed by the file name, example is shown below,

[root@linuxtechi ~]# touch devops.txt

[root@linuxtechi ~]# ls -l devops.txt

-rw-r--r--. 1 root root 0 Mar 29 22:39 devops.txt

[root@linuxtechi ~]#

Example:2 Create empty files in bulk using touch

There can be some scenario where we have to create lots of empty files for some testing, this can be easily achieved using touch command,

[root@linuxtechi ~]# touch sysadm-{1..20}.txt

Example:2 Create empty files in bulk using touch

There can be some scenario where we have to create lots of empty files for some testing, this can be easily achieved using touch command,

[root@linuxtechi ~]# touch sysadm-{1..20}.txt

In the above example we have created 20 empty files with name sysadm-1.txt to sysadm-20.txt, you can change the name and numbers based on your requirements.

Example:3 Change / Update access time of a file and directory

Let’s assume we want to change access time of a file called “devops.txt“, to do this use ‘-a‘ option in touch command followed by file name, example is shown below,

[root@linuxtechi ~]# touch -a devops.txt

[root@linuxtechi ~]#

Now verify whether access time of a file has been updated or not using ‘stat’ command

[root@linuxtechi ~]# stat devops.txt File: ‘devops.txt’ Size: 0               Blocks: 0          IO Block: 4096   regular empty file Device: fd00h/64768d    Inode: 67324178    Links: 1 Access: (0644/-rw-r--r--) Uid: (    0/    root)   Gid: (    0/    root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2018-03-29 23:03:10.902000000 -0400 Modify: 2018-03-29 22:39:29.365000000 -0400 Change: 2018-03-29 23:03:10.902000000 -0400 Birth: - [root@linuxtechi ~]#

Change access time of a directory,

Let’s assume we have a ‘nfsshare’ folder under /mnt, Let’s change the access time of this folder using the below command,

[root@linuxtechi ~]# touch -a /mnt/nfsshare/

[root@linuxtechi ~]#

[root@linuxtechi ~]# stat /mnt/nfsshare/

File: ‘/mnt/nfsshare/’

Size: 6               Blocks: 0          IO Block: 4096   directory

Device: fd00h/64768d    Inode: 2258        Links: 2

Access: (0755/drwxr-xr-x) Uid: (    0/    root)   Gid: (    0/    root)

Context: unconfined_u:object_r:mnt_t:s0

Access: 2018-03-29 23:34:38.095000000 -0400

Modify: 2018-03-03 10:42:45.194000000 -0500

Change: 2018-03-29 23:34:38.095000000 -0400

Birth: -

[root@linuxtechi ~]#

Example:4 Change Access time without creating new file

There can be some situations where we want to change access time of a file if it exists and avoid creating the file. Using ‘-c‘ option in touch command, we can change access time of a file if it exists and will not a create a file, if it doesn’t exist.

[root@linuxtechi ~]# touch -c sysadm-20.txt

[root@linuxtechi ~]# touch -c winadm-20.txt

[root@linuxtechi ~]# ls -l winadm-20.txt

ls: cannot access winadm-20.txt: No such file or directory

[root@linuxtechi ~]#

Example:5 Change Modification time of a file and directory

Using ‘-m‘ option in touch command, we can change the modification time of a file and directory,

Let’s change the modification time of a file called “devops.txt”,

Example:6 Changing access and modification time in one go

Use “-am” option in touch command to change the access and modification together or in one go, example is shown below,

[root@linuxtechi ~]# touch -am devops.txt

[root@linuxtechi ~]#

Example:7 Set the Access & modification time to a specific date and time

Whenever we do change access and modification time of a file & directory using touch command, then it set the current time as access & modification time of that file or directory,

Let’s assume we want to set specific date and time as access & modification time of a file, this is can be achieved using ‘-c’ & ‘-t’ option in touch command,

Date and Time can be specified in the format: {CCYY}MMDDhhmm.ss

Where:

  • CC – First two digits of a year
  • YY – Second two digits of a year
  • MM – Month of the Year (01-12)
  • DD – Day of the Month (01-31)
  • hh – Hour of the day (00-23)
  • mm – Minutes of the hour (00-59)

Let’s set the access & modification time of devops.txt file for future date and time( 2025 year, 10th Month, 19th day of month, 18th hours and 20th minute)

[root@linuxtechi ~]# touch -c -t 202510191820 devops.txt

Use stat command to view the update access & modification time,

Set the Access and Modification time based on date string, Use ‘-d’ option in touch command and then specify the date string followed by the file name, example is shown below,

[root@linuxtechi ~]# touch -c -d "2010-02-07 20:15:12.000000000 +0530" sysadm-29.txt

[root@linuxtechi ~]#

Verify the status using stat command,

[root@linuxtechi ~]# stat sysadm-20.txt

File: ‘sysadm-20.txt’

Size: 0               Blocks: 0          IO Block: 4096   regular empty file

Device: fd00h/64768d    Inode: 67324189    Links: 1

Access: (0644/-rw-r--r--) Uid: (    0/    root)   Gid: (    0/    root)

Context: unconfined_u:object_r:admin_home_t:s0

Access: 2010-02-07 20:15:12.000000000 +0530

Modify: 2010-02-07 20:15:12.000000000 +0530

Change: 2018-03-30 10:23:31.584000000 +0530

Birth: -

[root@linuxtechi ~]#

Cross verify the access and modification time using stat,

[root@linuxtechi ~]# stat devops.txt File: ‘devops.txt’ Size: 0               Blocks: 0          IO Block: 4096   regular empty file Device: fd00h/64768d    Inode: 67324178    Links: 1 Access: (0644/-rw-r--r--) Uid: (    0/    root)   Gid: (    0/    root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2018-03-30 00:06:20.145000000 -0400 Modify: 2018-03-30 00:06:20.145000000 -0400 Change: 2018-03-30 00:06:20.145000000 -0400 Birth: - [root@linuxtechi ~]#

[root@linuxtechi ~]# touch -m devops.txt

[root@linuxtechi ~]#

Now verify whether modification time has been changed or not using stat command,

[root@linuxtechi ~]# stat devops.txt

File: ‘devops.txt’

Size: 0               Blocks: 0          IO Block: 4096   regular empty file

Device: fd00h/64768d    Inode: 67324178    Links: 1

Access: (0644/-rw-r--r--) Uid: (    0/    root)   Gid: (    0/    root)

Context: unconfined_u:object_r:admin_home_t:s0

Access: 2018-03-29 23:03:10.902000000 -0400

Modify: 2018-03-29 23:59:49.106000000 -0400

Change: 2018-03-29 23:59:49.106000000 -0400

Birth: -

[root@linuxtechi ~]#

Similarly, we can change modification time of a directory,

[root@linuxtechi ~]# touch -m /mnt/nfsshare/

[root@linuxtechi ~]#

Example:8 Set the timestamps to a file using a reference file (-r)

In touch command we can use a reference file for setting the timestamps of file or directory. Let’s assume I want to set the same timestamps of file “sysadm-20.txt” on “devops.txt” file. This can be easily achieved using ‘-r’ option in touch.

Syntax: # touch -r {reference-file} actual-file

[root@linuxtechi ~]# touch -r sysadm-20.txt devops.txt

[root@linuxtechi ~]#

Example:9 Change Access & Modification time on symbolic link file

By default, whenever we try to change timestamps of a symbolic link file using touch command then it will change the timestamps of original file only, In case you want to change timestamps of a symbolic link file then this can be achieved using ‘-h’ option in touch command,

Syntax: # touch -h {symbolic link file}

[root@linuxtechi opt]# ls -l /root/linuxgeeks.txt

lrwxrwxrwx. 1 root root 15 Mar 30 10:56 /root/linuxgeeks.txt -> linuxadmins.txt

[root@linuxtechi ~]# touch -t 203010191820 -h linuxgeeks.txt

[root@linuxtechi ~]# ls -l linuxgeeks.txt

lrwxrwxrwx. 1 root root 15 Oct 19 2030 linuxgeeks.txt -> linuxadmins.txt

[root@linuxtechi ~]#
Touch command is used to create empty files and also changes the timestamps of existing files on Unix & Linux System. Changing timestamps here means updating the access and modification time of files and directories.The touch command is primarily used to change file timestamps, but if the file (whose name is passed as an argument) doesn't exist, then the tool creates it.The touch command is a command line utility to update timestamps on files. UNIX and UNIX like operating systems store timestamp information for each file or folder including access time, modify time and change time. It is possible to modify timestamps using the touch command either to update a timestamp to the current time or to modify it to a date in the past.
chmod

Examples

    chmod 644 file.htm

Set the permissions of file.htm to "owner can read and write; group can read only; others can read only".

   chmod -R 755 myfiles

Recursively (-R) Change the permissions of the directory myfiles, and all folders and files it contains, to mode 755: User can read, write, and execute; group members and other users can read and execute, but cannot write.

chmod u=rw example.jpg

Change the permissions for the owner of example.jpg so that the owner may read and write the file. Do not change the permissions for the group, or for others.

chmod u+s comphope.txt

Set the "Set-User-ID" bit of comphope.txt, so that anyone who attempts to access that file does so as if they are the owner of the file.

chmod u-s comphope.txt

The opposite of the above command; un-sets the SUID bit.

chmod 755 file.cgi

Set the permissions of file.cgi to "read, write, and execute by owner" and "read and execute by the group and everyone else".

chmod 666 file.txt

Set the permission of file.txt to "read and write by everyone.".

chmod a=rw file.txt

Example 1 :
Let’s change the assgn1_client.c permission so that the owner cannot write(w) in the file but can only read it.

BEFORE: -rw-rw-r-- mik mik assgn1_client.c

COMMAND: chmod u=r assgn1_client.c

AFTER: -r--rw-r-- mik   mik   assgn1_client.c

Before :

After :

Example 2 :
Let’s restrict the permission such that the user cannot search the directory EXA.

BEFORE: drwxrwxr-x mik   mik   EXA

COMMAND: chmod u=rw EXA

AFTER: drw-rwxr-x   mik mik    EXA

After applying the chmod u=rw EXA command, the user (owner) cannot change the directory. If the user tries to change the directory, then it shows the message “Permission denied” as shown in the figure below :

chmod - To change access permissions, change mode.

chmod changes the permissions of each given file according to mode, where mode describes the permissions to modify. Mode can be specified with octal numbers or with letters.chmod changes the file mode of each specified FILE according to MODE, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bits.

Related Solutions

Command Example Usage Explanation yum search packagename yum install packagename yum update packagename yum remove packagename...
Command Example Usage Explanation yum search packagename yum install packagename yum update packagename yum remove packagename yum update
full details explanation of any touch screen device
full details explanation of any touch screen device
AutoCAD command prompts are grouped under Tabs according to their command functions. Such groups are labelled...
AutoCAD command prompts are grouped under Tabs according to their command functions. Such groups are labelled as PANELS. Explore into details FIVE panels.   
What is Information System? Provide an example of usage.
What is Information System? Provide an example of usage.
Example of a sales forecast with explanation.
Example of a sales forecast with explanation.
Select one explanation for democratization. Provide an example of a case that proves that this explanation...
Select one explanation for democratization. Provide an example of a case that proves that this explanation is either incorrect or insufficient.
How are focus groups used in marketing? Find and explain an example of focus groups as...
How are focus groups used in marketing? Find and explain an example of focus groups as they relate to marketing. Cite and reference your source.
• Develop an "Echo" command that returns the parameters on different lines. Example: For input "$...
• Develop an "Echo" command that returns the parameters on different lines. Example: For input "$ Java Echo Hello world!" The answer will be: "Hello world ! ” using java programming language
​define what is beween-groups , within-groups and mixed group study and an example of each?
​define what is beween-groups , within-groups and mixed group study and an example of each?
Explain the difference between central command planning and indicative planning. An example of a country that...
Explain the difference between central command planning and indicative planning. An example of a country that uses indicative planning is France; explain how indicative planning has been applied in France and its relative success. Given the complexity of the interdependencies in modern industrial technology, explain how indicative planning might complement a more successful industrial development for a country. What is the weakness of indicative planning in this regard? Carefully explain.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT